id stringlengths 14 117 | description stringlengths 29 13k | code stringlengths 10 49.8k | test_samples dict | source class label 3
classes | prompt stringlengths 391 104k |
|---|---|---|---|---|---|
p01885 Escape from the Hell_14668 | Example
Input
3 9
6 3
5 2
3 1
2
2
2
Output
2 | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, L = map(int, readline().split())
P = [list(map(int, readline().split())) for i in range(N)]
C = [int(readline()) for i in range(N)]
P.sort(key = lambda x: (x[0] - x[1]), reverse=1)
INF = 10**18
S = [0]*(N+1)
... | {
"input": [
"3 9\n6 3\n5 2\n3 1\n2\n2\n2",
"3 9\n6 3\n5 1\n3 1\n2\n2\n2",
"3 9\n6 3\n9 1\n3 1\n2\n2\n2",
"3 9\n4 3\n5 1\n3 0\n2\n0\n2",
"3 14\n1 3\n9 1\n3 1\n2\n2\n2",
"6 17\n8 2\n5 2\n3 0\n2\n0\n2",
"3 9\n6 3\n5 1\n3 0\n2\n2\n2",
"3 9\n6 3\n5 1\n3 0\n2\n2\n4",
"3 9\n6 3\n5 2\n3 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
3 9
6 3
5 2
3 1
2
2
2
Output
2
### Input:
3 9
6 3
5 2
3 1
2
2
2
### Output:
2
### Input:
3 9
6 3
5 1
3 1
2
2
2
### Output:
2
### Code:
import sys
readline = sys... |
p02022 Mercy_14670 | H: Mercy
Santa Claus found a group doing programming even though it was Christmas.
Santa Claus felt sorry for them, so he decided to give them a cake.
There are $ N $ types of cream, and the taste is $ A_1, A_2, A_3, \ dots, A_N $.
There are $ M $ types of sponges, and the taste is $ B_1, B_2, B_3, \ dots, B_M $.
... | n, m = map(int, input().split())
a = sum(list(map(int, input().split())))
b = sum(list(map(int, input().split())))
print(a*b)
| {
"input": [
"3 2\n3 1 5\n2 4",
"3 2\n3 1 5\n2 5",
"3 2\n2 1 5\n2 5",
"3 2\n2 1 3\n2 5",
"3 2\n2 2 3\n2 5",
"3 1\n2 4 3\n2 5",
"3 2\n2 4 3\n2 4",
"3 2\n1 4 3\n2 4",
"3 2\n1 4 3\n4 5",
"3 2\n0 4 3\n4 1",
"3 1\n0 4 3\n4 1",
"3 1\n0 0 3\n4 2",
"3 1\n0 1 3\n4 2",
"2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
H: Mercy
Santa Claus found a group doing programming even though it was Christmas.
Santa Claus felt sorry for them, so he decided to give them a cake.
There are $ N $ types of crea... |
p02164 Satake likes straight_14673 | Problem
Satake doesn't like being bent.
For example, I don't like pencils, chopsticks, and bent-shaped houses, and I don't like taking actions such as turning right or left.
By the way, Satake who lives on the XY plane is $ N $ shops $ (X_ {1}, Y_ {1}), (X_ {2}, Y_ {2}), \ ldots, (X_ {N} , Y_ {N}) I was asked to shop... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]... | {
"input": [
"3\n1 0\n0 1\n-2 -1",
"2\n0 1\n0 -1",
"3\n1 0\n0 1\n-2 -2",
"2\n0 1\n-1 -2",
"2\n0 1\n-1 -3",
"2\n0 1\n-1 -4",
"3\n1 1\n0 1\n-2 -1",
"2\n0 2\n0 -1",
"2\n1 1\n-1 -3",
"3\n1 0\n0 1\n-2 0",
"2\n1 0\n-1 -3",
"2\n0 2\n1 0",
"2\n1 0\n-4 -1",
"2\n2 0\n-2 -... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Satake doesn't like being bent.
For example, I don't like pencils, chopsticks, and bent-shaped houses, and I don't like taking actions such as turning right or left.
By the ... |
p02305 Intersection_14676 | For given two circles $c1$ and $c2$, print
4
if they do not cross (there are 4 common tangent lines),
3
if they are circumscribed (there are 3 common tangent lines),
2
if they intersect (there are 2 common tangent lines),
1
if a circle is inscribed in another (there are 1 common tangent line),
0
if ... | import math
c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]
d = math.sqrt(pow(c1x-c2x, 2) + pow(c1y-c2y, 2))
s = c1r + c2r
if d > s:
print(4)
elif d == s:
print(3)
else:
if c1r > c2r:
if d + c2r > c1r:
print(2)
elif d + c2r == ... | {
"input": [
"0 0 1\n1 0 2",
"1 2 1\n3 2 2",
"0 0 1\n0 0 2",
"1 2 1\n4 2 2",
"1 1 1\n6 2 2",
"0 0 0\n1 0 2",
"1 2 1\n3 4 2",
"1 2 0\n4 2 2",
"0 0 1\n0 1 2",
"0 0 0\n0 0 2",
"1 1 1\n9 2 2",
"0 1 0\n0 0 2",
"1 2 1\n5 4 2",
"-1 0 0\n0 0 2",
"1 2 0\n0 2 2",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For given two circles $c1$ and $c2$, print
4
if they do not cross (there are 4 common tangent lines),
3
if they are circumscribed (there are 3 common tangent lines),
2
if ... |
p02452 Includes_14679 | For given two sequneces $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A$ and $B$ are sorted by ascending order respectively.
Constraints
* $1 \leq n, m \leq 200,000$
* $-1,000,000,000 \leq a_0 < a_1 < ... <... | n = int(input())
a = set(map(int, input().split()))
m = int(input())
print(+a.issuperset(set(map(int, input().split()))))
| {
"input": [
"4\n1 2 3 4\n2\n2 4",
"4\n1 2 3 4\n3\n1 2 5",
"4\n1 2 3 0\n2\n2 4",
"4\n1 2 4 1\n2\n1 4",
"4\n1 2 3 4\n3\n1 0 5",
"4\n1 2 3 0\n2\n1 4",
"4\n1 2 3 8\n3\n1 0 5",
"4\n1 2 3 1\n2\n1 4",
"4\n1 2 3 8\n3\n1 0 8",
"4\n1 2 3 8\n4\n1 0 8",
"4\n1 2 4 1\n2\n2 4",
"4\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For given two sequneces $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A... |
1032_C. Playing Piano_14691 | Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano keyboard.
Paul is very clever and knows that the essential thing is... | n = int(input())
u = list(map(int, input().split()))
d = []
for i in range(5):
d.append([0] * n)
for i in range(5):
d[i][0] = 1
for i in range(1, n):
if u[i] == u[i - 1]:
s1 = 0
for j in range(5):
if d[j][i - 1] == 1:
s1 += 1
if s1 > 1:
for j i... | {
"input": [
"7\n1 5 7 8 10 3 1\n",
"19\n3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8\n",
"5\n1 1 4 2 2\n",
"20\n5 3 3 2 5 5 3 3 5 1 2 5 1 3 3 4 2 5 5 5\n",
"1\n50\n",
"100\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: ... |
1055_A. Metro_14695 | Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.
In the city in which Alice and Bob live, the first metro line is being built. This metro line contains n stations numbered from 1 to n. Bob lives near the station with number 1, while Alice ... | n, s = input().split()
n = int(n)
s = int(s)
a = input().split()
b = input().split()
for j in range(n):
a[j] = int(a[j])
b[j] = int(b[j])
if a[0]==1:
if a[s-1]==1:
print("YES")
elif b[s-1]==1:
for i in range(s,n):
if a[i]==1 and b[i]==1:
print("YES")
break
else:
print("NO")
else:
prin... | {
"input": [
"5 4\n1 0 0 0 1\n0 1 1 1 1\n",
"5 3\n1 1 1 1 1\n1 1 1 1 1\n",
"5 2\n0 1 1 1 1\n1 1 1 1 1\n",
"4 2\n1 0 1 0\n0 1 1 0\n",
"4 2\n1 0 1 1\n0 1 0 1\n",
"5 3\n1 0 0 0 1\n1 0 1 0 0\n",
"10 2\n1 0 0 1 0 1 1 0 1 1\n1 1 1 0 1 0 0 1 0 1\n",
"7 4\n1 1 0 0 1 1 0\n1 1 1 1 1 1 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.
In the city in which Alice and Bob live, the first me... |
1077_B. Disturbed People_14699 | There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise.
Vova thinks that people in the i-th flats are distur... | n = int(input())
A = [int(i) for i in input().split()]
V = []
for i in range(n-2):
if (A[i]==1 and A[i+1]==0 and A[i+2]==1):
V.append(i+1)
V.append(1000)
k = 0
l = 0
n = len(V)
for i in range(n):
if (V[i]-V[l] != 2):
d = i-l
k += (d+1)//2
l = i
print(k)
| {
"input": [
"10\n1 1 0 1 1 0 1 0 1 0\n",
"4\n1 1 1 1\n",
"5\n1 1 0 0 0\n",
"5\n0 0 0 0 0\n",
"5\n1 0 1 0 1\n",
"62\n0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0\n",
"85\n0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2,... |
1098_A. Sum in the tree_14703 | Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vert... | # alpha = "abcdefghijklmnopqrstuvwxyz"
prime = 998244353
# INF = 100000000000
# from heapq import heappush
from collections import defaultdict, deque
t = 1#int(input())
from math import sqrt
for test in range(t):
n = int(input())
p = [0, 0]
p.extend(list(map(int, input().split())))
s = [0]
s.extend... | {
"input": [
"3\n1 2\n2 -1 1\n",
"5\n1 1 1 1\n1 -1 -1 -1 -1\n",
"5\n1 2 3 1\n1 -1 2 -1 -1\n",
"10\n1 1 2 4 4 5 6 3 3\n0 -1 -1 0 -1 -1 1 2 3 4\n",
"2\n1\n1 -1\n",
"2\n1\n0 -1\n",
"10\n1 1 1 1 2 3 4 5 1\n3 -1 -1 -1 -1 3 3 3 3 -1\n",
"5\n1 2 3 4\n5 -1 5 -1 7\n",
"25\n1 2 1 4 4 4 1 2 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya ... |
1119_B. Alyona and a Narrow Fridge_14707 | Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but ... | n,h=input().split()
n=int(n)
h=int(h)
l=list(map(int,input().split()))
k=[]
r=0
for i in range(n):
k.append(l[i])
k.sort(reverse=True)
ans=0
for j in range(0,len(k),2):
ans=ans+k[j]
if(ans<=h):
r=i+1
else:
break
print(r) | {
"input": [
"5 10\n3 1 4 2 4\n",
"10 10\n9 1 1 1 1 1 1 1 1 1\n",
"5 7\n2 3 5 4 1\n",
"1 2\n2\n",
"2 1\n1 1\n",
"1 1\n1\n",
"100 2000\n31 21 8 4 15 6 3 20 22 16 47 14 35 1 21 22 15 26 19 21 17 44 7 1 15 40 45 22 2 30 46 1 20 90 56 28 24 65 43 8 9 12 38 1 47 8 13 35 20 47 12 8 24 6 16 12 23... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona ... |
1145_F. Neat Words_14711 |
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
Input
NEAT
Output
YES
Input
WORD
Output
NO
Input
CODER
Output
NO
Input
APRILFOOL
Output
NO
Input
AI
O... | lin = set(list('WETYIAFHKLZXVNM'))
s = input()
print('YES' if len(set(list(s)).intersection(lin)) in [len(set(list(s))), 0] else 'NO')
| {
"input": [
"WORD\n",
"APRILFOOL\n",
"JUROR\n",
"NEAT\n",
"CODER\n",
"YES\n",
"AI\n",
"BRIGHT\n",
"SOURPUSS\n",
"SUSHI\n",
"WAYS\n",
"DODO\n",
"STATUSQUO\n",
"KHAKI\n",
"WEEVIL\n",
"WAXY\n",
"CROUP\n",
"BURG\n",
"PUZZLES\n",
"PHRASE\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
... |
1166_E. The LCMs Must be Large_14715 | Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?
There are n stores numbered from 1 to n in Nlogonia. The i-th of these stores offers a positive integer a_i.
Each day among the last m days Dora bought a single integer from s... | m, n = map(int, input().split())
s = [0] * m
for w in range(m):
for i in list(map(int, input().split()))[1:]:
s[w] |= 1 << i
for i in s:
for j in s:
if not (i & j):
print('impossible')
exit(0)
print('possible') | {
"input": [
"10 10\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n",
"2 5\n3 1 2 3\n3 3 4 5\n",
"4 4\n2 1 2\n2 2 3\n2 3 4\n2 4 1\n",
"3 10\n4 6 10 1 9\n9 6 1 8 10 4 9 5 7 2\n8 3 10 6 8 2 4 5 1\n",
"10 100\n4 51 22 73 78\n1 52\n5 49 74 100 14 80\n1 6\n2 98 65\n5 79 13 47 24 77\n6 47 57 35 24 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia?
There are n stores numbered from 1 to n... |
1185_C1. Exam in BerSU (easy version)_14719 | The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
*... | n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * 101
curr = 0
for i in range(n):
tm = m - a[i]
ans = 0
for j in range(1, 101):
tmp = int(tm / j)
if tmp >= cnt[j]:
tm -= cnt[j] * j
ans += cnt[j]
else:
tm -= tmp * j
... | {
"input": [
"7 15\n1 2 3 4 5 6 7\n",
"5 100\n80 40 40 40 60\n",
"14 70\n2 8 10 1 10 6 10 6 9 4 10 10 10 9\n",
"10 50\n9 9 9 9 9 9 9 9 9 9\n",
"3 299\n100 100 100\n",
"19 95\n1 9 5 5 9 8 9 6 3 7 1 1 6 7 4 4 4 2 10\n",
"17 85\n1 2 10 3 10 9 1 6 6 5 9 2 10 1 3 3 7\n",
"2 100\n1 99\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going t... |
1203_F2. Complete the Projects (hard version)_14723 | The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete ... | # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import math
import copy
#T = int(input())
#N = int(input())
#print(N)
N,r = [int(x) for x in stdin.readline().split()]
#arr = [int(x) for x in stdin.readline().split()]
... | {
"input": [
"3 4\n4 6\n10 -2\n8 -1\n",
"3 2\n300 -300\n1 299\n1 123\n",
"5 20\n45 -6\n34 -15\n10 34\n1 27\n40 -45\n",
"20 1000\n29531 141\n29892 277\n29544 141\n29825 -194\n29846 164\n29595 25\n28975 -249\n29926 -108\n29920 -99\n29232 -238\n29892 -284\n29757 270\n29828 122\n29925 256\n29656 -128\n290... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous f... |
1220_E. Tourism_14726 | Alex decided to go on a touristic trip over the country.
For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to A... | from collections import defaultdict
def get_neighbors(edges):
neighbors = defaultdict(set, {})
for v1, v2 in edges:
neighbors[v1].add(v2)
neighbors[v2].add(v1)
return dict(neighbors)
def get_component(neighbors_map, root):
if root not in neighbors_map:
return {root}
hori... | {
"input": [
"5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2\n",
"10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6\n",
"3 2\n1 1335 2\n2 1\n3 2\n2\n",
"28 31\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 1 0 1 0 0 1 1 1 0\n9 7\n24 10\n12 27\n3 20\n16 3\n27 8\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alex decided to go on a touristic trip over the country.
For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and... |
1246_A. p-binary_14729 | Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer.
For example,... | n,p=map(int,input().split())
#print("{0:b}".format(n).count('1'))
t=0
while (("{0:b}".format(n).count('1'))>t or n<t) and n>=0:
t+=1
n-=p
if n<0:
print(-1)
else:
print(t)
| {
"input": [
"4 -7\n",
"24 -1\n",
"24 1\n",
"24 0\n",
"1 1\n",
"536870812 1\n",
"1 0\n",
"1999 999\n",
"1 -1000\n",
"3 2\n",
"21 10\n",
"1000000000 1000\n",
"1 1000\n",
"1 -1\n",
"2001 1000\n",
"29 9\n",
"13 6\n",
"3 -179\n",
"2 1\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative... |
1265_E. Beautiful Mirrors_14733 | Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i)/(100) for all 1 ≤ i ≤ n.
Creatnx asks the mirrors one by one, starting from the 1-st mirror. Every day, if he asks i-th mirror, there ... | N = int(input())
P = list(map(int, input().split()))
mod = 998244353
p = 0
q = 1
for i in range(N):
p, q = (100 * (p+q)) % mod, (P[i] * q) % mod
print((p * pow(q, mod-2, mod))%mod)
| {
"input": [
"1\n50\n",
"3\n10 20 50\n",
"5\n30 48 49 17 25\n",
"4\n42 20 51 84\n",
"100\n60 79 48 35 18 24 87 1 44 65 60 78 11 43 71 79 90 6 94 49 22 91 58 93 55 21 22 31 7 15 17 65 76 9 100 89 50 96 14 38 27 87 29 93 54 12 99 35 27 51 36 44 6 26 91 1 53 8 49 63 18 4 31 55 95 15 77 1 16 98 75 26 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Creatnx has n mirrors, numbered from 1 to n. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The i-th mirror will tell Creatnx that he is beautiful with probability (p_i... |
1287_A. Angry Students_14737 | It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
* "A" corresponds to an angry... | n=int(input())
for i in range(n):
m=int(input())
l=list(input())
p=[]
c=0
r=len(l)
for i in range(r):
if l[i]=="P":
c+=1
if i==r-1:
p.append(c)
if l[i]=="A":
p.append(c)
c=0
if len(p)!=1:
if p[0]==0:
print(max(p))
else:
p.pop(0)
print(max(p))
else:
print(0) | {
"input": [
"1\n4\nPPAP\n",
"3\n12\nAPPAPPPAPPPP\n3\nAAP\n3\nPPA\n",
"10\n1\nA\n1\nP\n2\nAP\n2\nPA\n8\nPPPPAPPP\n8\nPPPPPPPA\n8\nAPPPPPPP\n8\nPPPPPPAP\n8\nPPPPPAPP\n8\nPPPAPPPP\n",
"16\n4\nPPPP\n4\nAPPP\n4\nPAPP\n4\nAAPP\n4\nPPAP\n4\nAPAP\n4\nPAAP\n4\nAAAP\n4\nPPPA\n4\nAPPA\n4\nPAPA\n4\nAAPA\n4\nPPAA... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, ... |
1307_A. Cow and Haybales_14741 | The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales.
However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an a... | t = int (input ())
ans = []
for i in range (t):
day = 0
p = list (map (int, input ().split ()))
n, d = p #
flag = False
num = list (map (int, input ().split ()))
for k in range (1, n) :
while (num[k] > 0 and day + k <= d) :
num[0] += 1
num[k] -= 1
... | {
"input": [
"3\n4 5\n1 0 3 2\n2 2\n100 1\n1 8\n0\n",
"3\n4 5\n1 0 1 2\n2 2\n100 1\n1 8\n0\n",
"3\n4 5\n1 0 1 2\n2 2\n100 2\n1 8\n0\n",
"3\n4 5\n0 0 1 2\n2 2\n100 2\n1 7\n0\n",
"3\n4 5\n0 0 1 2\n2 2\n000 2\n1 7\n0\n",
"3\n4 5\n1 0 3 2\n2 2\n100 0\n1 8\n0\n",
"3\n4 5\n2 0 1 2\n2 2\n100 2\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of n haybale piles on the farm. The i-th pile contains a_i haybales.
However, Farmer John has ju... |
1330_A. Dreamoon and Ranking Collection_14745 | Dreamoon is a big fan of the Codeforces contests.
One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing!
Based on this, you come up with the following problem:
There is a person who participated in n Codeforces rounds. His place in the first round is a_1, hi... | cycles = int(input())
def find_v(x, places):
places = set(places)
v = 0
i = 1
while True:
if i in places:
v = i
elif x > 0:
v = i
x -= 1
else:
break
i += 1
return v
results = []
for cycle in range(cycles):
n, x ... | {
"input": [
"5\n6 2\n3 1 1 5 7 10\n1 100\n100\n11 1\n1 1 1 1 1 1 1 1 1 1 1\n1 1\n1\n4 57\n80 60 40 20\n",
"1\n5 2\n3 4 5 6 7\n",
"1\n6 1\n1 3 4 5 6 7\n",
"1\n4 3\n4 5 6 7\n",
"1\n4 1\n1 3 4 5\n",
"1\n1 1\n2\n",
"1\n5 1\n1 3 4 6 6\n",
"1\n3 3\n4 5 6\n",
"1\n4 5\n6 6 7 7\n",
"1\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dreamoon is a big fan of the Codeforces contests.
One day, he claimed that he will collect all the places from 1 to 54 after two more rated contests. It's amazing!
Based on this, yo... |
1350_A. Orac and Factors_14749 | Orac is studying number theory, and he is interested in the properties of divisors.
For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, such that a⋅ c=b.
For n ≥ 2, we will denote as f(n) the smallest positive divisor of n, except 1.
For example, f(7)=7,f(10)=2,f(35)=5.
... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
ans = n
for i in range(2, n + 1):
if n % i == 0:
ans += i
break
ans += 2 * (k - 1)
print(ans) | {
"input": [
"3\n5 1\n8 2\n3 4\n",
"5\n497347 19283\n2568 1000000000\n499979 123987\n93 19\n13 5\n",
"1\n902059 999999997\n",
"1\n66605 9996\n",
"1\n100000 9997\n",
"1\n19 6\n",
"1\n1000000 100008\n",
"1\n5 17\n",
"1\n932531 999999995\n",
"1\n999983 99999999\n",
"1\n980051 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Orac is studying number theory, and he is interested in the properties of divisors.
For two positive integers a and b, a is a divisor of b if and only if there exists an integer c, s... |
1370_D. Odd-Even Subsequence_14753 | Ashish has an array a of size n.
A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the remaining elements.
Consider a subsequence s of a. He defines the cost of s as the minimum between:
* The maximum among all elements... | import sys
import math
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def MI():
return map(int, sys.stdin.readline().split())
def SI():
return sys.stdin.readline().strip()
n,k = MI()
a = LI()
def check(mid,isEven):
ans = 0
for i in range(n):
if isEven... | {
"input": [
"4 2\n1 2 3 4\n",
"4 3\n1 2 3 4\n",
"6 4\n5 3 50 2 4 5\n",
"5 3\n5 3 4 2 6\n",
"4 2\n93648 34841 31096 95128\n",
"10 4\n91239 51189 50977 96098 56330 55725 6448 7351 60071 93359\n",
"4 4\n99402 47701 84460 34277\n",
"7 7\n20569 28739 17283 56309 61086 8910 52918\n",
"3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ashish has an array a of size n.
A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the ... |
1417_E. XOR Inverse_14757 | You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)).
An inversion i... | import os
from sys import stdin, stdout
class Input:
def __init__(self):
self.lines = stdin.readlines()
self.idx = 0
def line(self):
try:
return self.lines[self.idx].strip()
finally:
self.idx += 1
def array(self, sep = ' ', cast = int):
... | {
"input": [
"9\n10 7 9 10 7 5 5 3 5\n",
"3\n8 10 3\n",
"4\n0 1 3 2\n",
"94\n89 100 92 24 4 85 63 87 88 94 68 14 61 59 5 77 82 6 13 13 25 43 80 67 29 42 89 35 72 81 35 0 12 35 53 54 63 37 52 33 11 84 64 33 65 58 89 37 59 32 23 92 14 12 30 61 5 78 39 73 21 37 64 50 10 97 12 94 20 65 63 41 86 60 47 72 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i... |
1434_C. Solo mid Oracle_14760 | Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the ... | import sys
input = sys.stdin.readline
def solve_case():
a, b, c, d = [int(x) for x in input().split()]
if a > b * c:
print(-1)
else:
k = a // (b * d)
print(a * (k + 1) - k * (k + 1) // 2 * b * d)
def main():
for _ in range(int(input())):
solve_case()
main() | {
"input": [
"7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n",
"1\n1000000 1000000 1 1000000\n",
"4\n568133 729913 934882 371491\n916127 997180 932938 203988\n112133 793452 857041 842130\n572010 190716 396183 683429\n",
"2\n395916 225366 921987 169483\n604656 66... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of e... |
145_A. Lucky Conversion_14764 | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety... | a,b=input(),input();c,d=0,0
for i in range(len(a)):
if a[i]!=b[i]:
if a[i]=='4': c+=1
else: d+=1
print(max(c,d)) | {
"input": [
"774\n744\n",
"47\n74\n",
"777\n444\n",
"74747474\n77777777\n",
"44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447\n",
"444477744444744777477747744777774747747447444774444477774774777447474777747444447447777777777477774774477447747444... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744... |
1485_C. Floor and Mod_14768 | A pair of positive integers (a,b) is called special if ⌊ a/b ⌋ = a mod b. Here, ⌊ a/b ⌋ is the result of the integer division between a and b, while a mod b is its remainder.
You are given two integers x and y. Find the number of special pairs (a,b) such that 1≤ a ≤ x and 1 ≤ b ≤ y.
Input
The first line contains a s... | import sys
input = sys.stdin.readline
import math
t = int(input())
for f in range(t):
x,y = map(int,input().split())
ok = 1
ng = y+1
while ng-ok > 1:
c = (ng+ok)//2
if c*c-1 <= x:
ok = c
else:
ng = c
ans = 0
ans += (ok*(ok-1))//2
if ok != y:
... | {
"input": [
"9\n3 4\n2 100\n4 3\n50 3\n12 4\n69 420\n12345 6789\n123456 789\n12345678 9\n",
"1\n3 1\n",
"9\n3 4\n2 100\n4 3\n50 3\n12 4\n69 420\n12345 6789\n123456 789\n16177647 9\n",
"9\n3 6\n1 101\n7 3\n50 3\n12 4\n69 420\n12345 6789\n35053 789\n16177647 9\n",
"9\n3 6\n1 101\n7 3\n50 3\n1 4\n69... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A pair of positive integers (a,b) is called special if ⌊ a/b ⌋ = a mod b. Here, ⌊ a/b ⌋ is the result of the integer division between a and b, while a mod b is its remainder.
You are... |
150_A. Win or Freeze_14772 | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circl... | n = int(input())
p = n
arr = []
while p%2==0:
arr.append(2)
p = p//2
x = int(p**0.5)+1
for i in range(3,x,2):
while p%i==0:
arr.append(i)
p = p//i
if p>2:
arr.append(p)
if n==1 or len(arr)==1:
print(1)
print(0)
elif len(arr)==2:
print(2)
else:
x = arr[0]*arr[1]
print(... | {
"input": [
"30\n",
"1\n",
"6\n",
"8587340257\n",
"7420738134810\n",
"2975\n",
"1000000000000\n",
"236\n",
"27\n",
"9\n",
"3047527844089\n",
"16\n",
"5\n",
"614125\n",
"9999925100701\n",
"30971726\n",
"266418\n",
"401120980262\n",
"319757451... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a... |
1535_E. Gold Transfer_14775 | You are given a rooted tree. Each vertex contains a_i tons of gold, which costs c_i per one ton. Initially, the tree consists only a root numbered 0 with a_0 tons of gold and price c_0 per ton.
There are q queries. Each query has one of two types:
1. Add vertex i (where i is an index of query) as a son to some ver... | import os
import sys
input = sys.stdin.buffer.readline
def main():
(Q, A0, C0) = [int(x) for x in input().split()]
N = Q + 2
A = [0] * N
C = [0] * N
P = [0] * N
pref = [0] * N # pref[u] is sum of A from root to u (inclusive, immutable)
anc = [None for i in range(N)] # anc[u][k] is (2*... | {
"input": [
"5 5 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0 1 3\n2 4 2\n",
"5 5 2\n2 0 2\n1 0 1 4\n2 2 4\n1 0 1 3\n2 4 2\n",
"5 10 2\n2 0 2\n1 0 3 4\n2 2 4\n1 0 1 3\n2 4 2\n",
"1 5 2\n2 0 2\n1 0 1 4\n2 2 4\n1 0 1 3\n2 4 2\n",
"1 5 4\n2 0 2\n1 0 1 4\n7 2 4\n1 0 1 3\n2 4 1\n",
"1 5 1\n2 0 2\n1 0 1 4\n2 2 4\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rooted tree. Each vertex contains a_i tons of gold, which costs c_i per one ton. Initially, the tree consists only a root numbered 0 with a_0 tons of gold and price c_... |
182_D. Common Divisors_14779 | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ... | s1=input()
s2=input()
n=len(s1)
m=len(s2)
cnt=0
from math import gcd
g=gcd(n,m)
for i in range(g):
#curr=s1[:i+1]
if n%(i+1)==0 and m%(i+1)==0:
if s1[:i+1]*(n//(i+1))==s1 and s1[:i+1]*(m//(i+1))==s2:
cnt+=1
print(cnt) | {
"input": [
"aaa\naa\n",
"abcdabcd\nabcdabcdabcdabcd\n",
"aba\nabaaba\n",
"ab\nab\n",
"aaa\naaaaab\n",
"aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa\n",
"ab\naa\n",
"ab\nac\n",
"aa\nbb\n",
"abcabc\nabdabdabd\n",
"abcabcabc\nertert\n",
"aa\naac\n",
"aaaaaa\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String a is the divisor of string b if and ... |
22_E. Scheme_14786 | To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem... | import sys
n = int(input())
g = [int(i) - 1 for i in sys.stdin.readline().split()]
def solve(n, g):
vertex_id = [-1]*n
current_id = 0
cycle_starts = []
cycle_starts_by_vertex = [-1]*n
cycle_vertex_sample = []
start_on_cycle = []
cycle_index_by_ID = []
for v in range(n):
if ... | {
"input": [
"3\n3 3 2\n",
"7\n2 3 1 3 4 4 1\n",
"9\n2 5 6 7 4 1 9 6 8\n",
"7\n3 1 2 5 6 7 4\n",
"7\n2 3 1 3 4 4 1\n",
"20\n20 10 16 14 9 20 6 20 14 19 17 13 16 13 14 8 8 8 8 19\n",
"2\n2 1\n",
"3\n2 3 1\n",
"5\n5 3 5 2 3\n",
"4\n2 4 4 3\n",
"100\n13 71 16 92 25 53 97 63 70... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to t... |
255_D. Mr. Bender and Square_14790 | Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right f... | import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
sdata = lambda: list(ii())
def solve():
n, x, y, c = idata()
r = n ** 2
l = -1
while l + 1 < r:
middle = (l + r) // 2
ans = 1 + 2 * (middle + 1) * middle
ans -= pow(middle - n + y... | {
"input": [
"9 3 8 10\n",
"6 4 3 1\n",
"1000000000 63 65 384381709\n",
"9 4 3 10\n",
"847251738 695702891 698306947 648440371\n",
"958 768 649 298927\n",
"8 2 6 10\n",
"9 8 2 50\n",
"1000000000 55 999999916 423654797\n",
"8 8 3 1\n",
"8 1 2 10\n",
"1000000000 6 9999999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bend... |
279_D. The Minimum Number of Variables_14793 | You've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence, consisting of n operations.
The first operation is assigning the value of... | def Solve(x,B):
if((X,x,B) in Mem):
return Mem[(X,x,B)]
if(len(B)>X):
return False
if(x==len(L)):
return True
if(Form(L[x],B)):
A=list(B)
for e in range(len(B)):
r=A[e]
A[e]=L[x]
if(Solve(x+1,tuple(sorted(A)))):
... | {
"input": [
"5\n1 2 3 6 8\n",
"3\n3 6 5\n",
"6\n2 4 8 6 10 18\n",
"23\n26988535 53977070 107954140 161931210 323862420 215908280 431816560 647724840 269885350 242896815 755678980 485793630 863633120 404828025 539770700 134942675 593747770 377839490 917610190 809656050 620736305 971587260 458805095\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≤ i ≤ m... |
301_C. Yaroslav and Algorithm_14797 | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strin... | print ( """0??<>1
1??<>2
2??<>3
3??<>4
4??<>5
5??<>6
6??<>7
7??<>8
8??<>9
9??>>??0
??<>1
?0>>0?
?1>>1?
?2>>2?
?3>>3?
?4>>4?
?5>>5?
?6>>6?
?7>>7?
?8>>8?
?9>>9?
?>>??
>>?""" )
| {
"input": [
"2\n10\n79\n",
"10\n630\n624\n85\n955\n757\n841\n967\n377\n932\n309\n",
"10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n",
"10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896\n",
"10\n447\n806\n891\n730\n371\n351\n7\n102\n394\n549\n",
"10\n317\n36\n191\n843\n289\n107\n41\n943\n265\n649\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm con... |
328_A. IQ Test_14801 | Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence a1, a1 + d, a1 + 2d, ..., a1 + (n - 1)d, where a1 and d are any numbers.
Ge... | import sys
fin = sys.stdin
a = list(map(int, fin.readline().split()))
d = a[1] - a[0]
if a[2] - a[1] == a[3] - a[2] == d:
print(a[3] + d)
else:
d = a[1] / a[0]
if a[2] / a[1] == a[3] / a[2] == d and d * a[3] == int(d * a[3]):
print(int(d * a[3]))
else:
print(42) | {
"input": [
"1 334 667 1000\n",
"836 624 412 200\n",
"501 451 400 350\n",
"891 297 99 33\n",
"2 4 9 16\n",
"3 18 108 648\n",
"4 32 48 64\n",
"2 4 6 14\n",
"1 2 10 20\n",
"256 64 16 8\n",
"1000 100 10 1\n",
"8 4 2 1\n",
"11 234 457 680\n",
"2 9 27 81\n",
"2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or g... |
34_B. Sale_14805 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he ... | n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(len(a)):
if a[i] < 0:
ans += a[i]
m -= 1
if m == 0:
break
print(-1 * ans) | {
"input": [
"4 2\n7 0 0 -7\n",
"5 3\n-6 0 35 -2 4\n",
"50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -79... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob ... |
373_C. Counting Kangaroos is Fun_14809 | There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who is ... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... | {
"input": [
"8\n9\n1\n6\n2\n6\n5\n8\n3\n",
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"4\n1\n1\n1\n2\n",
"1\n1\n",
"100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangar... |
418_A. Football_14815 | One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wi... | n,k=map(int,input().split())
a=n*(n-1)//2
if(n*k>a):
print(-1)
else:
print(n*k)
for i in range(1,n+1):
for j in range(k):
print(i,(i+j)%n+1) | {
"input": [
"3 1\n",
"11 6\n",
"2 1\n",
"10 5\n",
"4 1\n",
"1 1\n",
"648 581\n",
"947 868\n",
"980 680\n",
"248 54\n",
"775 388\n",
"47 24\n",
"131 65\n",
"197 182\n",
"786 393\n",
"609 305\n",
"445 223\n",
"57 13\n",
"1 2\n",
"1000 751\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two team... |
466_E. Information Graph_14820 | There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place:
* either employee y became the boss of employee x (at that, employee x didn't have a bos... | import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
n, m = map(int, input().split())
ev = [tuple(map(int, input().split())) for _ in range(m)]
g = [[] for _ in range(n + 1)]
qry = [[] for _ in range(m + 1)]
roots = set(range(1, n + 1))
qcnt = 0
for e in ev:
if e[0] == 1:
g[e[2]].append(... | {
"input": [
"4 9\n1 4 3\n2 4\n3 3 1\n1 2 3\n2 2\n3 1 2\n1 3 1\n2 2\n3 1 3\n",
"5 10\n1 2 1\n1 3 2\n2 3\n1 4 3\n1 5 4\n2 5\n3 1 2\n2 5\n2 5\n2 5\n",
"10 10\n2 9\n1 2 1\n1 3 2\n3 1 1\n3 1 1\n2 3\n3 1 1\n3 1 1\n3 1 2\n3 1 1\n",
"5 10\n2 1\n1 1 2\n1 2 3\n2 1\n3 2 2\n3 2 2\n2 1\n3 2 1\n2 1\n1 3 4\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next... |
48_C. The Race_14824 | Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.
So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li... | eps=10**(-9)
mn=10
mx=100000000
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
mn = max(mn,(arr[i]*10)/(i+1))
mx = min(mx,((arr[i]+1)*10)/(i+1))
ans1=((n+1)*mn)//10
ans2=((n+1)*(mx-eps))//10
if ans2>ans1:
print('not unique')
else:
print('unique')
print(int(ans1))
| {
"input": [
"3\n1 2 4\n",
"2\n1 2\n",
"9\n2 5 7 10 12 15 17 20 22\n",
"50\n19876 39753 59629 79506 99382 119259 139135 159012 178889 198765 218642 238518 258395 278271 298148 318025 337901 357778 377654 397531 417407 437284 457160 477037 496914 516790 536667 556543 576420 596296 616173 636050 655926 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own nob... |
53_A. Autocomplete_14830 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | s = input()
l = len(s)
n = int(input())
u = []
for i in range(n):
a = input()
#print('Taken input', a,len(a),l)
if a[:l] == s:
if len(u) == 0:
u.append(a if len(a) == l else a[l:])
elif len(a) == l:
u = [a] + u
else:
j = 0
k = 0
while True:
if u[k] == s:
if k < len(u) - 1:
k += 1... | {
"input": [
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n",
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfind\nfindfirstof\nfindit\nf",
"msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmhmyxpld\n",
"hzk... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on ... |
567_C. Geometric Progression_14834 | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.
He wants to know how many subsequences of length three can be selected from a, so that they form a geometric p... | import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
... | {
"input": [
"10 3\n1 2 6 2 3 6 9 18 3 9\n",
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"3 200000\n999999998 999999999 1000000000\n",
"3 17\n2 34 578\n",
"3 1\n-1000000000 -1000000000 -1000000000\n",
"4 5\n0 0 0 0\n",
"5 3\n0 0 0 0 0\n",
"3 70000\n1 70000 605032704\n",
"3 4\n1 0 0\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, ... |
610_B. Vika and Squares_14840 | Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will ... | import itertools
import math
n = int(input())
a = [int(x) for x in input().split()]
amin = min(a)
b = list(filter(lambda x: x[1] == amin, enumerate(a)))
l = len(b)
k = max((b[(i+1) % l][0] - b[i][0] - 1)%n for i in range(l))
print(amin*n + k)
| {
"input": [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n",
"8\n5 4 3 2 1 1 1 1\n",
"4\n100 101 101 100\n",
"2\n10 10\n",
"3\n100 100 101\n",
"13\n2 2 2 1 1 1 1 1 1 1 2 2 2\n",
"2\n2 3\n",
"4\n2 3 2 2\n",
"10\n896619242 805194919 844752453 848347723 816995848 8568... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.
Vika also has an infinitely long rectan... |
630_L. Cracking the Code_14844 | The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.
A young hacker Vasya disassembled the program and foun... | #Nearly Lucky
'''
a=list(map(str,input()))
l=0
for i in range(len(a)):
if(a[i]=='4' or a[i]=='7'):
l+=1
if(l==4 or l==7 or l==44 or l==47 or l==74 or l==77):
print("YES")
else:
print("NO")'''
#IQ Test
'''
a=int(input())
b=list(map(int,input().strip().split()))
e,o=[],[]
for i in range(len(b)):
i... | {
"input": [
"12345\n",
"91537\n",
"13542\n",
"32036\n",
"71232\n",
"10000\n",
"70809\n",
"41675\n",
"99999\n",
"11111\n",
"19759\n",
"27599\n",
"99224\n",
"11000\n",
"40425\n",
"21973\n",
"11984\n",
"45382\n",
"12863\n",
"84484\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent... |
659_D. Bicycle Race_14848 | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the Ox axis from west to east, and th... | read = lambda: map(int, input().split())
vect = lambda a, b: a[0] * b[1] - a[1] * b[0]
vector = lambda A, B: (B[0] - A[0], B[1] - A[1])
n = int(input())
p = [tuple(read()) for i in range(n)]
cnt = 0
for i in range(2, n):
v1 = vector(p[i], p[i - 1])
v2 = vector(p[i - 1], p[i - 2])
if vect(v1, v2) < 0:
... | {
"input": [
"16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n",
"6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n",
"24\n-10000 -10000\n-10000 9998\n9998 9998\n9998 -10000\n-6364 -10000\n-6364 6362\n6362 6362\n6362 -6364\n-2728 -6364\n-2728 2726\n2726 2726\n2726 -910\n908 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sectio... |
682_A. Alyona and Numbers_14852 | After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ... | from math import ceil,floor
n,m = map(int, input().split())
res = 0
for i in range(1,n+1):
req = 5 - i%5
res += ((m-req) // 5) +1
print(res)
| {
"input": [
"5 7\n",
"1 5\n",
"21 21\n",
"6 12\n",
"11 14\n",
"3 8\n",
"4743 139826\n",
"1436 237592\n",
"2 9\n",
"171591 13322\n",
"4 4\n",
"1000000 1\n",
"253 821\n",
"1 1000000\n",
"8 2\n",
"834588 107199\n",
"478 828\n",
"827388 966812\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the 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 ... |
748_D. Santa Claus and a Palindrome_14859 | Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the same length n. We denote the beauty of the i-th string by ai. It can happen that ai is negative — that means that Santa doesn't find this s... | import sys
import math
def solve():
k, n = map(int, input().split())
D = {}
for line in sys.stdin:
s, a = line.split()
if s in D:
D[s].append(int(a))
else:
D[s] = [int(a)]
res = 0
center = 0
for s in D:
revs = s[::-1]
if not revs ... | {
"input": [
"7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4\n",
"2 5\nabcde 10000\nabcde 10000\n",
"3 1\na 1\na 2\na 3\n",
"10 10\nnjxbzflaka -1\nfelbvvtkja 6\ngxiuztqkcw 5\naomvscmtti 6\njsqmkoyuca -2\nwckqtzuixg 5\najktvvblef -5\nittmcsvmoa -1\nakalfzbxjn 10\nacuyokmqsj 8\n",
"3 3\nada... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the sa... |
771_C. Bear and Tree Jumps_14863 | A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.
Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.
Limak recently learned how to jump. He can jump from a vertex to any verte... | """
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
... | {
"input": [
"6 2\n1 2\n1 3\n2 4\n2 5\n4 6\n",
"3 5\n2 1\n3 1\n",
"13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12\n",
"12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n2 12\n9 4\n9 10\n",
"2 5\n2 1\n",
"2 1\n1 2\n",
"15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.
Limak is a little polar bear. He lives... |
796_C. Bank Hacking_14867 | Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks.
<image>
There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the ... | import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
arr = list(int(i) for i in input().split()) + [-int(1e9+3)]
c = Counter(arr)
top, sec = sorted(set(arr))[-1:-3:-1]
top_cnt = [int(i == top) for i in arr]
sec_cnt = [int(i == sec) for i in arr]
edges = list(list(map(int, input().spl... | {
"input": [
"5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5\n",
"5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4\n",
"7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6\n",
"2\n999999999 1000000000\n2 1\n",
"5\n-1 -1000000000 -1 -2 -1\n5 2\n1 2\n3 2\n4 1\n",
"3\n-1000000000 -999999999 -1000000000\n1 2\n3 1\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the... |
816_D. Karen and Test_14870 | Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.
Th... | n = int(input())
p = list(map(int,input().split()))
MOD = 10**9+7
mode = 0
if n%4 == 3:
n-= 1
new = []
for i in range(n):
if mode == 0: new.append(p[i]+p[i+1])
else: new.append(p[i]-p[i+1])
mode = 1-mode
p = new
def calc0(p):
res = 0
ncr = 1
n = len(p)//2-1
for ... | {
"input": [
"4\n3 7 5 2\n",
"5\n3 6 9 12 15\n",
"6\n58376259 643910770 5887448 757703054 544067926 902981667\n",
"16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082\n",
"7\n941492387 722... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Karen has just arrived at school, and she has a math test today!
<image>
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks fo... |
841_D. Leha and another game about graph_14873 | Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pass the level, he needs to find a «good» subset of edges of the graph or say... | import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
import heapq
INF=10**9
def Dijkstra(graph, start,m):
dist=[INF]*len(graph)
parent=[INF]*len(graph)
queue=[(0, start)]
while queue:
path_len, v=heapq.heappop(queue)
if dist[v]==INF:
dist[v]=path_len
for w in gra... | {
"input": [
"1 0\n1\n",
"3 3\n0 -1 1\n1 2\n2 3\n1 3\n",
"2 1\n1 1\n1 2\n",
"4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n",
"10 10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n6 7\n8 3\n6 4\n4 2\n9 2\n5 10\n9 8\n10 7\n5 1\n6 2\n",
"3 2\n1 0 1\n1 2\n2 3\n",
"4 5\n0 0 0 -1\n1 2\n3 3\n3 4\n1 4\n2 4\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each verte... |
862_E. Mahmoud and Ehab and the function_14877 | Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, which satisfy 0 ≤ j ≤ m - n. Suppose, ci = ai - bi + j. Then f(j) = |c1 - c2 + c3 - c4... cn|. More formally, <image>.
Dr. Evil wants Ma... | from bisect import *
f = lambda: list(map(int, input().split()))
n, m, q = f()
k = m - n + 1
a = f()
s = sum(a[0:n:2]) - sum(a[1:n:2])
b = [0] + f()
for i in range(2, m + 1, 2): b[i] = -b[i]
for i in range(m): b[i + 1] += b[i]
u = [b[j] - b[j + n] for j in range(1, k, 2)]
v = [b[j + n] - b[j] for j in range(0, k, 2... | {
"input": [
"5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1\n",
"1 1 1\n937982044\n179683049\n1 1 821220804\n",
"1 1 1\n937982044\n15017817\n1 1 821220804\n",
"5 6 3\n1 2 3 4 5\n2 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1\n",
"1 1 1\n289198726\n15017817\n1 1 821220804\n",
"5 6 3\n1 2 3 4 5\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, w... |
888_C. K-Dominant Character_14881 | You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character.
Input
The first line contains string s consisting of lowercas... | word = input()
n = len(word)
d,e = {},{}
for i in range(n):
if word[i] in d:
d[word[i]].append(i+1)
else:
e[word[i]] = 0
d[word[i]] = [i+1]
# print(d,e)
for i in d:
temp = d[i]
if len(temp)==1:
cnt = temp[0]
cnt = max(n-temp[0]+1,cnt)
e[i] = cnt
else:
... | {
"input": [
"zzzzz\n",
"abacaba\n",
"abcde\n",
"lzeznbwu\n",
"rr\n",
"abb\n",
"saaaaaaaas\n",
"gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech\n",
"a\n",
"aab\n",
"aaabbb\n",
"abghim\n",
"zx\n",
"axcbb\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to... |
911_A. Nearest Minimums_14885 | You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
Input
The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n ... | from sys import maxsize
n = int(input())
arr = list(map(int,input().split()))
m = maxsize
res= maxsize
ind = []
for i in range(len(arr)):
if arr[i] < m:
m = arr[i]
ind = [i]
res=maxsize
elif arr[i] == m:
ind.append(i)
if ind[-1]-ind[-2] < res and len(ind) > 1:
... | {
"input": [
"2\n3 3\n",
"9\n2 1 3 5 4 1 2 3 1\n",
"3\n5 6 5\n",
"10\n1 3 2 4 5 5 4 3 2 1\n",
"11\n2 2 2 2 2 2 1 1 2 2 2\n",
"8\n5 5 5 5 3 5 5 3\n",
"10\n2 2 2 2 2 1 1 2 2 2\n",
"2\n88888888 88888888\n",
"5\n100000000 100000001 100000000 100000001 100000000\n",
"8\n10 5 10 1 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at... |
95_A. Hockey_14891 | Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin ... | n = int(input())
a = []
for i in range(n):
a.append(input().rstrip())
w = list(input().rstrip())
c = input().rstrip()
m = len(w)
z = []
i = 0
while i < m:
for j in range(n):
if w[i].lower() == a[j][0].lower():
if i + len(a[j]) <= m:
f = 1
for k in range(i,i+le... | {
"input": [
"2\naCa\ncba\nabAcaba\nc\n",
"3\nbers\nucky\nelu\nPetrLoveLuckyNumbers\nt\n",
"4\nhello\nparty\nabefglghjdhfgj\nIVan\npetrsmatchwin\na\n",
"3\netr\ned\nied\nPetrUnited\nz\n",
"99\ns\nc\nN\nN\ni\ni\nW\nJ\nA\nW\nm\nB\nf\nO\nm\nk\nQ\nf\nx\np\nl\nH\nH\no\nn\nC\nK\nR\ns\nT\nJ\nv\nC\nZ\nd\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the ori... |
p02585 AtCoder Beginner Contest 175 - Moving Piece_14907 | Takahashi will play a game using a piece on an array of squares numbered 1, 2, \cdots, N. Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \cdots, N: P_1, P_2, \cdots, P_N.
Now, he will choose one square and place the piece on that square. Then, he will make the following move some n... | n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
p[i]-=1
ans=max(c)
for i in range(n):
f=i
r=0
l=[]
while True:
f=p[f]
l.append(c[f])
r+=c[f]
if f==i:
break
t=0
for j in range(len(l))... | {
"input": [
"10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719",
"3 3\n3 1 2\n-1000 -2000 -3000",
"5 2\n2 4 5 1 3\n3 4 -10 -8 8",
"2 3\n2 1\n10 -7",
"10 58\n9 1 6 7 8 4 3 2 10 5\n695279662 988782657 -119067776 38297... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi will play a game using a piece on an array of squares numbered 1, 2, \cdots, N. Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \cdots, N... |
p02716 AtCoder Beginner Contest 162 - Select Half_14911 | Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen.
Find the maximum possible sum of the chosen elements.
Here \lfloor x \rfloor denotes the greatest integer not greater than x.
... | N=int(input())
A=list(map(int, input().split()))
dp = [[0 for i in range(2)] for j in range(N+1)]
if N in [2, 3]: print(max(A))
else:
dp[2][0] = A[1]
dp[2][1] = A[0]
dp[3][0] = A[2]
dp[3][1] = max(A[1], A[0])
for i in range(4, N+1):
if i % 2 == 0:
dp[i][0] = max(max(dp[i-2][0], dp[i-2][1])+A[i-... | {
"input": [
"27\n18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49",
"5\n-1000 -100 -10 0 10",
"6\n1 2 3 4 5 6",
"10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"27\n18 -28 18 28 -45 9... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given is an integer sequence A_1, ..., A_N of length N.
We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are... |
p02845 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Colorful Hats 2_14915 | N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green.
The person numbered i says:
* "In front of me, exactly A_i people are wearing hats with the same color as mine."
Assuming that all these statements are correct, find the number of p... | N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
C = [3] + [0 for i in range(N)]
ans = 1
for a in A:
ans *= C[a]
ans %= MOD
C[a] -= 1
C[a+1] += 1
print(ans) | {
"input": [
"54\n0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17",
"3\n0 0 0",
"6\n0 1 2 3 4 5",
"54\n0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 20 13 14 14 15 15 15 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green.
The person numbered i says:
* "In front of me, ... |
p02982 AtCoder Beginner Contest 133 - Good Distance_14919 | There are N points in a D-dimensional space.
The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).
The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.
How many pairs (i, j) (i < j) are there such ... | n,d=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
for j in range(i):
dis=sum([(A[i][k]-A[j][k])**2 for k in range(d)])
if dis**(1/2)==int(dis**(1/2)):
ans+=1
print(ans) | {
"input": [
"3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3",
"3 2\n1 2\n5 5\n-2 8",
"5 1\n1\n2\n3\n4\n5",
"3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 0",
"1 1\n1\n2\n3\n4\n5",
"5 1\n0\n2\n3\n4\n5",
"3 2\n1 8\n5 5\n-2 8",
"3 2\n1 4\n5 5\n-2 8",
"3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 13 0",
"3 2\n2 4\n5... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N points in a D-dimensional space.
The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).
The distance between two points with coordinates (y_1, y_2, ..., y_... |
p03265 AtCoder Beginner Contest 108 - Ruined Square_14924 | There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)
Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).
... | a,b,c,d=map(int,input().split())
print(c+b-d,d-a+c,a+b-d,b-a+c)
| {
"input": [
"2 3 6 6",
"0 0 0 1",
"31 -41 -59 26",
"2 1 6 6",
"0 0 -1 1",
"1 -41 -59 26",
"2 2 6 6",
"0 0 -1 2",
"1 -46 -59 26",
"2 2 6 2",
"0 -1 -1 2",
"1 -46 -59 12",
"2 2 6 1",
"0 -1 -2 2",
"1 -46 -103 12",
"3 2 6 2",
"0 -1 0 2",
"1 -46 0 12"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order. (Assume that the positive x-axis po... |
p03424 AtCoder Beginner Contest 089 - Hina Arare_14928 | In Japan, people make offerings called hina arare, colorful crackers, on March 3.
We have a bag that contains N hina arare. (From here, we call them arare.)
It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.
We have ... | input()
print(['Three', 'Four']['Y' in input()]) | {
"input": [
"6\nG W Y P Y W",
"9\nG W W G P W P G G",
"8\nP Y W G Y W Y Y",
"6\nG W Y Q Y W",
"6\nG X X O X X",
"6\nF W Y P Y W",
"6\nF W Y O Y W",
"6\nG W Y O Y W",
"6\nE W Y O Y W",
"8\nO Y W G Y W Y Y",
"6\nF W Y Q Y W",
"6\nE W Y P Y W",
"8\nO Y W F Y W Y Y",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Japan, people make offerings called hina arare, colorful crackers, on March 3.
We have a bag that contains N hina arare. (From here, we call them arare.)
It is known that the bag... |
p03738 AtCoder Beginner Contest 059 - Comparison_14934 | You are given two positive integers A and B. Compare the magnitudes of these numbers.
Constraints
* 1 ≤ A, B ≤ 10^{100}
* Neither A nor B begins with a `0`.
Input
Input is given from Standard Input in the following format:
A
B
Output
Print `GREATER` if A>B, `LESS` if A<B and `EQUAL` if A=B.
Examples
Input
3... | a = int(input())
b = int(input())
print("LESS" if a<b else "EQUAL" if a == b else "GREATER")
| {
"input": [
"36\n24",
"9720246\n22516266",
"123456789012345678901234567890\n234567890123456789012345678901",
"850\n3777",
"36\n16",
"9720246\n44989358",
"36\n36",
"123456789012345678901234567890\n179827845276187955292784642083",
"850\n4141",
"36\n2",
"9720246\n38650320",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two positive integers A and B. Compare the magnitudes of these numbers.
Constraints
* 1 ≤ A, B ≤ 10^{100}
* Neither A nor B begins with a `0`.
Input
Input is given f... |
p00006 Reverse Sequence_14940 | Write a program which reverses a given string str.
Input
str (the size of str ≤ 20) is given in a line.
Output
Print the reversed str in a line.
Example
Input
w32nimda
Output
admin23w | st = input()
print(st[::-1]) | {
"input": [
"w32nimda",
"w32njmda",
"admjn23w",
"acmjn23w",
"3cmjn2aw",
"3dmjn2aw",
"wa2njmd3",
"xa2njmd3",
"xa3njmd3",
"wa3njmd3",
"wa3njme3",
"wa3njme4",
"wa3nj4em",
"xa3nj4em",
"x`3nj4em",
"x`3nk4em",
"x`3mk4em",
"xa3mk4em",
"x3amk4em",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reverses a given string str.
Input
str (the size of str ≤ 20) is given in a line.
Output
Print the reversed str in a line.
Example
Input
w32nimda
Outp... |
p00138 Track and Field Competition_14944 | The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two players in each group and the top two players from all the players in each group who are third or lower, will advance to the final.
Create... | import heapq
from collections import namedtuple
Data = namedtuple("Data", "time number")
all_player = []
for _ in range(3):
player = [input().split(" ") for lp in range(8)]
player = [Data(float(time), number) for number, time in player]
heapq.heapify(player)
data = heapq.heappop(player)
print(da... | {
"input": [
"18 25.46\n16 26.23\n3 23.00\n10 24.79\n5 22.88\n11 23.87\n19 23.90\n1 25.11\n23 23.88\n4 23.46\n7 24.12\n12 22.91\n13 21.99\n14 22.86\n21 23.12\n9 24.09\n17 22.51\n22 23.49\n6 23.02\n20 22.23\n24 21.89\n15 24.14\n8 23.77\n2 23.42",
"18 25.46\n16 26.23\n3 23.00\n10 24.79\n5 22.88\n11 23.87\n19 23... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two pl... |
p00271 Temperature Difference_14948 | Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference betwe... | c = 0
while c <= 6:
a, b = map(int,input().split())
c = c + 1
print(a - b)
| {
"input": [
"30 19\n39 20\n19 18\n25 20\n22 21\n23 10\n10 -10",
"30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n10 -10",
"30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n15 -10",
"30 19\n39 1\n19 18\n4 20\n22 21\n23 10\n15 -10",
"30 19\n39 1\n19 18\n2 20\n22 21\n23 10\n15 -10",
"30 19\n39 1\n19 18\n2 20\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates great... |
p00925 Miscalculation_14958 | Example
Input
1+2*3+4
11
Output
M | s,ans=input(),int(input())
x=int(s[0])
for i in range(1,len(s),2):
y=int(s[i+1])
x=x*y if s[i]=='*' else x+y
print("IMLU"[int(eval(s)==ans)+(int(x==ans)<<1)]) | {
"input": [
"1+2*3+4\n11",
"1+2*3+4\n9",
"0+1*3+4\n7",
"4+3*0+4\n8",
"3*1+0*4\n12",
"1+2*3+4\n7",
"0+2*3+4\n7",
"1+2+3+4\n11",
"0+2*3+4\n9",
"1+2*3+4\n14",
"4+3+2+1\n11",
"0+1*3+4\n11",
"4+3+2+1\n2",
"4+3*1+0\n11",
"1+2+3+4\n2",
"0+3*1+4\n11",
"1*2+... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
1+2*3+4
11
Output
M
### Input:
1+2*3+4
11
### Output:
M
### Input:
1+2*3+4
9
### Output:
I
### Code:
s,ans=input(),int(input())
x=int(s[0])
for i in range(1,len... |
p01943 Multiplication Is Interesting_14970 | F: Multiplication is fun --Multiplication Is Interesting -
story
Namba, a high school boy, is thinking of giving her a few lines on her birthday. She is a girl who loves multiplication, so Namba wants to give her a sequence that will allow her to enjoy multiplication as much as possible. However, when the calculation... | from decimal import *
import sys
import copy
def main():
getcontext().prec = 1000
input = sys.stdin.readline
n, k = input().split()
n = int(n)
k = Decimal(k)
a = [Decimal(input()) for i in range(n)]
if Decimal(0) in a:
print(n)
sys.exit()
if k == Decimal(0):
prin... | {
"input": [
"6 2.01\n1.10\n1.44\n0.91\n2.00\n1.12\n1.55",
"6 2.01\n1.973291582506739\n1.44\n0.91\n2.00\n1.12\n1.55",
"6 2.01\n3.193972823107136\n1.44\n1.6011184015013515\n2.00\n1.4112240923770436\n1.7115339331404038",
"6 2.01\n1.10\n1.676594273939908\n0.91\n2.00\n1.12\n1.55",
"1 2.739273044350752... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
F: Multiplication is fun --Multiplication Is Interesting -
story
Namba, a high school boy, is thinking of giving her a few lines on her birthday. She is a girl who loves multiplicat... |
p02376 Maximum Flow_14976 | A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$.
Constraints
* $2 \leq |V... | # Acceptance of input
import sys
file_input = sys.stdin
V, E = map(int, file_input.readline().split())
adj_mat = [[0] * V for i in range(V)]
for line in file_input:
u, v, c = map(int, line.split())
adj_mat[u][v] = c
# Ford???Fulkerson algorithm
import collections
# BFS for residual capacity network
def ... | {
"input": [
"4 5\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 2",
"4 2\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 2",
"3 2\n1 1 0\n0 2 1\n1 1 2\n1 3 1\n2 3 2",
"6 2\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 2",
"6 2\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 4",
"6 2\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 5",
"6 2\n0 1 0\n0 2 1\n1 2 1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow... |
1005_D. Polycarp and Div 3_14986 | Polycarp likes numbers that are divisible by 3.
He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after m such cuts, there will be m+1 parts in total. Poly... | n = input()
buf = 0
c = 0
m = 0
for i in range(len(n)):
buf += int(n[i])
m += 1
if int(n[i]) % 3 == 0 or buf % 3 == 0 or m >= 3:
buf = 0
c += 1
m = 0
print(c)
| {
"input": [
"201920181\n",
"3121\n",
"1000000000000000000000000000000000\n",
"6\n",
"11\n",
"13\n",
"31\n",
"1670000\n",
"10\n",
"10000170\n",
"4\n",
"12\n",
"14139582796\n",
"604500\n",
"40041\n",
"22\n",
"24\n",
"2812886\n",
"1872104158\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp likes numbers that are divisible by 3.
He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an a... |
1029_B. Creating the Contest_14990 | You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order.
You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to as... | n=int(input())
a=list(map(int,input().split()))
b=[]
for _ in range(n-1):
if a[_+1]<=a[_]*2:
b.append(1)
else:
b.append(0)
b.append(1); s=0; c=[]
for i in range(n):
if b[i]==1:
s+=1
c.append(s)
else:
s=0
if c[len(c)-1]==max(c) and c.count(max(c))==1:
print(max... | {
"input": [
"5\n2 10 50 110 250\n",
"10\n1 2 5 6 7 10 21 23 24 49\n",
"6\n4 7 12 100 150 199\n",
"2\n2 3\n",
"2\n10 20\n",
"5\n1 2 5 10 20\n",
"5\n1 2 4 9 18\n",
"2\n1 3\n",
"6\n1 2 5 11 22 44\n",
"3\n1 3 6\n",
"5\n1 2 4 8 16\n",
"5\n1 2 4 5 8\n",
"5\n1 2 3 4 5\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing ord... |
104_A. Blackjack_14994 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | n=int(input())
if n<11 or n>21:
print(0)
elif n==20:
print(15)
else:
print(4) | {
"input": [
"12\n",
"10\n",
"20\n",
"15\n",
"6\n",
"13\n",
"11\n",
"5\n",
"17\n",
"9\n",
"18\n",
"2\n",
"1\n",
"22\n",
"3\n",
"24\n",
"4\n",
"23\n",
"16\n",
"14\n",
"25\n",
"19\n",
"8\n",
"21\n",
"7\n",
"010\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. A... |
1071_B. Minimum path_14998 | You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix.
Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to the right or down. Each path is associated with the string that is f... | def solve(m, matrix, good, n):
c = 'z'
for x in range(n):
y = m - x
if y < 0 or y >= n: continue
if not good[x][y]: continue
if x < n - 1: c = min(c, matrix[x + 1][y])
if y < n - 1: c = min(c, matrix[x][y + 1])
for x in range(n):
y = m - x
if y < 0 or ... | {
"input": [
"4 2\nabcd\nbcde\nbcad\nbcde\n",
"7 6\nypnxnnp\npnxonpm\nnxanpou\nxnnpmud\nnhtdudu\nnpmuduh\npmutsnz\n",
"5 3\nbwwwz\nhrhdh\nsepsp\nsqfaf\najbvw\n",
"1 0\nz\n",
"1 1\ng\n",
"1 0\na\n",
"1 1\nz\n",
"1 0\ng\n",
"4 16\ndfhs\nvgca\ndfgd\nvscd\n",
"1 0\ny\n",
"1 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix.
Consider all paths from the upper left corner to the... |
1093_D. Beautiful Graph_15002 | You are given an undirected unweighted graph consisting of n vertices and m edges.
You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.
Calculate the number of possible ways t... | from collections import deque
from sys import stdin, stdout
input = stdin.readline
saida = []
t = int(input())
modulo = 998244353
for _ in range(t):
ans = 1
part = 0
factor = 0
fila = deque([])
n, m = map(int, input().split())
if m > (n // 2) * ( n // 2 + 1):
saida.append('0')
... | {
"input": [
"2\n2 1\n1 2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"12\n8 7\n2 3\n3 4\n4 5\n5 2\n6 7\n7 8\n8 6\n1 0\n2 1\n1 2\n3 3\n1 2\n2 3\n1 3\n3 2\n2 3\n3 1\n4 4\n1 2\n2 3\n3 4\n4 1\n4 4\n1 2\n2 3\n3 1\n4 1\n6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n100000 0\n1000 5\n55 56\n56 57\n57 58\n58 59\n59 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an undirected unweighted graph consisting of n vertices and m edges.
You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph ... |
1113_D. Sasha and One More Name_15006 | Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in t... | s=input()
if len(set(s[:len(s)//2]))<=1:
print("Impossible");exit()
for i in range(1,len(s)):
n=s[i:]+s[:i]
if(n==n[::-1])and(n!=s):
print(1);exit()
print(2) | {
"input": [
"nolon\n",
"kinnikkinnik\n",
"otto\n",
"qqqq\n",
"bbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgbbgggbgbggggggggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbgggggbgbgggbbgbbgbgggbbbbbbgggbgbbgbbgggbgbgggggbbbbgggbgbbgb... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my ... |
1141_F2. Same Sum Blocks (Hard)_15010 | This problem is given in two editions, which differ exclusively in the constraints on the number n.
You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of contiguous (consecutive) elements a[l], a[l+1], ..., a[r] (1 ≤ l ≤ r ≤ n). Thus, a block is defined by a pair of indices (l, r).
Find a... | n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
sm=0
for j in range(i,n):
sm+=a[j]
if sm in dic:
dic[sm].append((i,j))
else:
dic[sm]=[(i,j)]
ans=0
anskey=-1
for key in dic:
cnt=0
last=-1
for a,b in sorted(dic[key]):
if... | {
"input": [
"7\n4 1 2 2 1 5 3\n",
"4\n1 1 1 1\n",
"11\n-5 -4 -3 -2 -1 0 1 2 3 4 5\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This problem is given in two editions, which differ exclusively in the constraints on the number n.
You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of... |
1162_A. Zoning Restrictions Again_15014 | You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.
In each spot, if a house has height a, you will gain a^2 dollars fro... | n, h, m = map(int, input().split())
houses = [h] * n
for i in range(m):
tmp = list(map(int, input().split()))
for j in range(tmp[0]-1, tmp[1]):
if tmp[2] <= houses[j]:
houses[j] = tmp[2]
total = 0
for i in houses:
total += i*i
print(total) | {
"input": [
"3 3 3\n1 1 1\n2 2 3\n3 3 2\n",
"4 10 2\n2 3 8\n3 4 7\n",
"50 50 50\n15 21 1\n8 40 30\n25 34 4\n19 46 8\n24 32 16\n2 31 37\n18 18 43\n27 42 37\n7 28 48\n2 31 36\n43 45 19\n8 48 25\n4 26 13\n36 42 20\n15 26 18\n28 43 18\n7 32 47\n18 46 7\n9 39 5\n17 35 21\n21 24 38\n12 30 34\n18 49 38\n28 46 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each ... |
1200_A. Hotelier_15020 | Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.
The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similar... | input()
l = [0]*10
s = input()
for i in range(len(s)):
e = s[i]
if e == 'L':
l[l.index(0)] = 1
elif e == 'R':
l[len(l) - l[::-1].index(0) - 1] = 1
else:
l[int(e)] = 0
print(*l, sep = '')
| {
"input": [
"9\nL0L0LLRR9\n",
"8\nLLRL1RL1\n",
"8\nLLLL1LLL\n",
"4\nRRRL\n",
"12\nRRRRRRRRRR9L\n",
"8\nLLLLLLL1\n",
"7\nLRLLRLL\n",
"12\nLLLLLLLLLL1R\n",
"12\nLLLLLRRRRR8L\n",
"2\nLR\n",
"5\nLRLLL\n",
"10\nLRRLRRLRRL\n",
"6\nLRRRRR\n",
"12\nLLLLLLLLLL7R\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.
The hotel has two entrances — one from the left end, and another from the right end.... |
1240_F. Football_15025 | There are n football teams in the world.
The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums.
Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much... | import random
import math
def set_color(game, color):
color_count[game[0]][game[2]] -= 1
color_count[game[1]][game[2]] -= 1
game[2] = color
color_count[game[0]][game[2]] += 1
color_count[game[1]][game[2]] += 1
def fix(node):
minimum = math.inf
maximum = 0
for i in range(k):
mi... | {
"input": [
"7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n",
"7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n",
"7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n",
"7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n football teams in the world.
The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in on... |
1261_A. Messy_15028 | You are fed up with your messy room, so you decided to clean it up.
Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'.
In one operation you can choose any consecutive substring of s and reverse it. In other words,... | import os, sys, math
def solve(seq, k):
seq = [ 1 if a == '(' else -1 for a in seq ]
size = len(seq)
result = []
def rotate(fr, to):
assert fr <= to
result.append((fr + 1, to + 1))
while fr < to:
seq[fr], seq[to] = seq[to], seq[fr]
fr += 1
to -= 1
# print(''.join('(' if q > 0 else ')' for q in se... | {
"input": [
"4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n",
"4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n",
"4\n8 2\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n)(\n",
"4\n8 2\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n()\n",
"4\n8 1\n()(())()\n10 1\n))()()()((\n2 1\n()\n2 1\n()... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are fed up with your messy room, so you decided to clean it up.
Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an open... |
1283_B. Candies Division_15032 | Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.
Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the max... | n = int(input())
k = []
d = []
r = []
m = []
dk = []
h = 0
z = []
for i in range(n):
a = list(map(int,input().split()))
k.append(a[0])
d.append(a[1])
r.append(a[0] // a[1])
h += r[i] * a[1]
m.append(a[0]-((a[0] // a[1])*a[1]))
if (a[1]//2 == m[i]):
h += m[i]
elif (a[1]//2 < m[i])... | {
"input": [
"5\n5 2\n19 4\n12 7\n6 2\n100000 50010\n",
"1\n1233212 4\n",
"1\n1233212 2\n",
"5\n5 2\n19 4\n12 7\n6 2\n100001 50010\n",
"1\n311687 2\n",
"5\n5 2\n19 4\n12 7\n6 2\n100000 90586\n",
"5\n5 2\n1 4\n12 7\n6 2\n100000 90586\n",
"5\n5 2\n1 4\n12 7\n8 2\n100000 90586\n",
"5\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed t... |
1367_F1. Flying Sort (Easy Version)_15037 | This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem.
You are given an array a of n integers (there are no equals elements in the array). You can perform the following operations on array elements:... | t=int(input())
for you in range(t):
n=int(input())
l=input().split()
li=[int(i) for i in l]
z=list(li)
z.sort()
hashi=dict()
for i in range(n):
hashi[z[i]]=i+1
for i in range(n):
li[i]=hashi[li[i]]
hashi=dict()
dp=[0 for i in range(n)]
for i in range(n):
... | {
"input": [
"4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n",
"9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\n",
"9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n-1 1 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem.
You ar... |
1389_A. LCM Problem_15041 | Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18.
You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r.
Input
The first line contains one integer t (1 ≤ t ≤ 10000) — the number of tes... | T=int(input())
for _ in range(T):
l,r=map(int,input().split())
if abs(l-r)==1 and l!=1:
print(-1,-1)
elif 2*l>r :
print(-1,-1)
else:
print(l,2*l)
| {
"input": [
"4\n1 1337\n13 69\n2 4\n88 89\n",
"1\n80000000 160000000\n",
"1\n78788 157576\n",
"1\n1000003 100000000\n",
"1\n96777 19555557\n",
"4\n1 1337\n13 69\n2 4\n88 89\n",
"69\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18.
You are given two integers l and r. Find two integers... |
1409_D. Decrease the Sum of Digits_15045 | You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.
You have to answer t independent test cases.
Input
The first line of the input co... | for _ in range(int(input())):
n,k=[int(x) for x in input().split()]
if n%k==0:print(0)
else:print(k-(n%k)) | {
"input": [
"5\n2 1\n1 1\n500 4\n217871987498122 10\n100000000000000001 1\n",
"1\n9987 1\n",
"21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to mak... |
1430_B. Barrels_15049 | You have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water.
You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels x and y (the x-th barrel shouldn't be empty) and pour any possible amount of wa... | def solve():
n,k=map(int,input().split())
if n==1:
print(0)
return
ls=list(map(int,input().split()))
ls.sort()
res=ls.pop()
for i in range(k):
if ls:
res+=ls.pop()
print(res)
return
for _ in range(int(input())):
solve() | {
"input": [
"2\n4 1\n5 5 5 5\n3 2\n0 0 0\n",
"2\n4 2\n5 5 5 5\n3 2\n0 0 0\n",
"2\n4 2\n5 5 5 5\n3 2\n0 0 1\n",
"2\n4 3\n5 5 2 5\n3 2\n0 1 0\n",
"2\n4 3\n5 5 2 1\n3 2\n0 1 0\n",
"2\n4 3\n5 1 2 1\n3 2\n0 1 0\n",
"2\n4 2\n2 5 5 0\n3 2\n0 0 0\n",
"2\n4 3\n5 1 2 2\n3 2\n0 1 0\n",
"2\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water.
You can pour water from one barrel to another. In... |
1453_D. Checkpoints_15053 | Gildong is developing a game consisting of n stages numbered from 1 to n. The player starts the game from the 1-st stage and should beat the stages in increasing order of the stage number. The player wins the game after beating the n-th stage.
There is at most one checkpoint on each stage, and there is always a checkp... | t=int(input())
for _ in range(t):
n=int(input())
if n%2==1:
print(-1)
continue
ans=[]
tmp=0
for i in range(2,62):
if 1<<i&n:
ans.append('1')
for j in range(i-2):
ans.append('0')
tmp+=1
for i in range(tmp):
ans.append('1')
if 2&n:
ans.append('1')
print(len(an... | {
"input": [
"4\n1\n2\n8\n12\n",
"50\n1000000\n1000002\n1000004\n1000006\n1000008\n1000010\n1000012\n1000014\n1000016\n1000018\n1000020\n1000022\n1000024\n1000026\n1000028\n1000030\n1000032\n1000034\n1000036\n1000038\n1000040\n1000042\n1000044\n1000046\n1000048\n1000050\n1000052\n1000054\n1000056\n1000058\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gildong is developing a game consisting of n stages numbered from 1 to n. The player starts the game from the 1-st stage and should beat the stages in increasing order of the stage nu... |
1477_B. Nezzar and Binary String_15056 | Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because it looks better.
It is known that Nanako loves consistency so much. On th... | import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buf... | {
"input": [
"4\n5 2\n00000\n00111\n1 5\n1 3\n2 1\n00\n01\n1 2\n10 6\n1111111111\n0110001110\n1 10\n5 9\n7 10\n1 7\n3 5\n6 10\n5 2\n10000\n11000\n2 5\n1 3\n",
"1\n4 1\n0011\n0011\n1 4\n",
"1\n4 1\n0011\n0111\n1 4\n",
"1\n4 1\n0011\n0011\n4 4\n",
"4\n5 2\n00000\n00111\n1 5\n1 3\n2 1\n00\n01\n1 2\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to ... |
1527_D. MEX Tree_15060 | You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including end points) is k.
The MEX of a sequence of integers is the smallest non-n... | import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data()... | {
"input": [
"2\n4\n0 1\n0 2\n2 3\n2\n1 0\n",
"2\n4\n0 1\n1 2\n2 3\n2\n1 0\n",
"2\n4\n0 1\n1 2\n1 3\n2\n1 0\n",
"2\n4\n0 1\n1 2\n0 3\n2\n1 0\n",
"2\n4\n0 1\n0 2\n0 3\n2\n1 0\n",
"2\n4\n0 1\n1 3\n2 3\n2\n1 0\n",
"2\n4\n0 3\n1 2\n2 3\n2\n1 0\n",
"2\n4\n0 3\n1 2\n1 3\n2\n1 0\n",
"2\n4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of a... |
159_C. String Manipulation 1.0_15064 | One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of character c from the name. After the user changed his name, he can't undo th... | # cook your dish here
n=int(input())
s=list(input())*n
d={}
for i in range(len(s)):
if s[i] not in d:
d[s[i]]=[i]
else:
d[s[i]].append(i)
m=int(input())
for i in range(m):
o,c=input().split()
s[d[c].pop(int(o)-1)]=''
print(''.join(s)) | {
"input": [
"2\nbac\n3\n2 a\n1 b\n2 c\n",
"1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n",
"10\nccbcabbaca\n40\n2 c\n8 b\n26 b\n12 b\n24 a\n29 a\n20 c\n17 b\n32 c\n9 c\n16 b\n13 b\n19 a\n3 c\n2 b\n18 c\n4 a\n13 c\n8 c\n5 c\n13 a\n19 c\n26 c\n13 c\n6 c\n3 c\n4 a\n5 a\n9 c\n8 b\n9 c\n2 c\n19 a\n5 a\n12 c\n10 c\n2 b\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pic... |
201_A. Clear Symmetry_15070 | Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.
L... | x=int(input())
n=1
while n*n+1<2*x:
n+=2
if x==3:
n=5
print(n) | {
"input": [
"9\n",
"4\n",
"6\n",
"89\n",
"15\n",
"91\n",
"76\n",
"80\n",
"96\n",
"72\n",
"79\n",
"5\n",
"74\n",
"97\n",
"47\n",
"50\n",
"3\n",
"7\n",
"94\n",
"20\n",
"75\n",
"66\n",
"46\n",
"14\n",
"71\n",
"22\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right ... |
225_E. Unsolvable_15074 | Consider the following equation:
<image> where sign [a] represents the integer part of number a.
Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers x and y (x, y > 0), for which the ... | print([0,1,3,15,63,4095,65535,262143,73741816,536396503,140130950,487761805,319908070,106681874,373391776,317758023,191994803,416292236,110940209,599412198,383601260,910358878,532737550,348927936,923450985,470083777,642578561,428308066,485739298,419990027,287292016,202484167,389339971,848994100,273206869,853092282,4116... | {
"input": [
"2\n",
"3\n",
"1\n",
"14\n",
"38\n",
"25\n",
"22\n",
"26\n",
"20\n",
"34\n",
"8\n",
"32\n",
"16\n",
"30\n",
"28\n",
"18\n",
"37\n",
"10\n",
"39\n",
"35\n",
"15\n",
"27\n",
"12\n",
"31\n",
"24\n",
"5\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider the following equation:
<image> where sign [a] represents the integer part of number a.
Let's find all integer z (z > 0), for which this equation is unsolvable in positive... |
24_C. Sequence of points_15078 | You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural number i). Here point B is symmetric to A according M, if M is the center o... | n, k = map(int, input().split())
ax = []
ay = []
mx, my = map(int, input().split())
for i in range(n):
x, y = map(int, input().split())
ax.append(x)
ay.append(y)
k %= 2*n
for i in range(k):
mx = 2*ax[i % n] - mx
my = 2*ay[i % n] - my
print(mx, " ", my) | {
"input": [
"3 4\n0 0\n1 1\n2 3\n-5 3\n",
"3 1\n5 5\n1000 1000\n-1000 1000\n3 100\n",
"1 1000000000000000000\n-1000 1000\n1000 -1000\n",
"1 1\n-1000 -1000\n1000 1000\n",
"1 900000000000000001\n-1000 -1000\n-1000 -1000\n",
"1 1000000000000000000\n-1000 1000\n1001 -1000\n",
"1 1\n-1000 -100... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: M... |
298_A. Snow Footprints_15085 | There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ... | arg = int(input())
s2=input()
start = -1
ending = -1
flag9 = 0
if "R" in s2:
for n in range(0, arg):
if s2[n]=="R" and flag9 == 0:
start = n + 1
flag9 = 1
if s2[n]== "R" and s2[n+1] == "L":
ending = n + 1
elif s2[n] == "R":
ending = n + 2
else:
for n in range(0, arg):
if s2[n]=="L" and flag9... | {
"input": [
"11\n.RRRLLLLL..\n",
"9\n..RRLL...\n",
"13\n....LLLLLL...\n",
"3\n.L.\n",
"3\n.R.\n",
"4\n.RL.\n",
"17\n.......RRRRR.....\n",
"13\n...LLLLLL....\n",
"17\n.....RRRRR.......\n",
"4\n..RL\n",
"17\n......RRRRR......\n"
],
"output": [
"2 4\n",
"3 4\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave ... |
320_D. Psychos in a Line_15089 | There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.
You're given the initial arrangeme... | n = int(input())
aa = list(map(int,input().split()))
live = []
ans=0
for i in range(n-1,-1,-1):
c = 0
while len(live)!=0 and live[-1][0]<aa[i]:
c = max(c+1,live[-1][1])
live.pop()
if c>ans: ans =c
live.append((aa[i],c))
print(ans) | {
"input": [
"6\n1 2 3 4 5 6\n",
"10\n10 9 7 8 6 5 3 4 2 1\n",
"1\n1\n",
"6\n6 5 4 3 2 1\n",
"15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4\n",
"2\n1 2\n",
"100\n61 96 25 10 50 71 38 77 76 75 59 100 89 66 6 99 2 13 3 23 91 93 22 92 4 86 90 44 39 31 9 47 28 95 18 54 1 73 94 78 60 20 42 84 97 83 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) ... |
369_A. Valera and Plates_15093 | Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat d... | class CodeforcesTask369ASolution:
def __init__(self):
self.result = ''
self.n_m_k = []
self.plan = []
def read_input(self):
self.n_m_k = [int(x) for x in input().split(" ")]
self.plan = [int(x) for x in input().split(" ")]
def process_task(self):
cleans = 0
... | {
"input": [
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"3 1 1\n1 2 1\n",
"8 2 2\n1 2 1 2 1 2 1 2\n",
"5 2 1\n1 1 2 2 2\n",
"2 100 100\n2 2\n",
"14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2\n",
"233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At th... |
391_B. Word Folding_15097 | You will receive 5 points for solving this problem.
Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t... | t = {}
for i, c in enumerate(input()):
if c not in t: t[c] = (i, 1)
elif (t[c][0] - i) & 1: t[c] = (i, t[c][1] + 1)
print(max(b for a, b in t.values())) | {
"input": [
"ABBBCBDB\n",
"ABRACADABRA\n",
"AB\n",
"ABACBCABACACB\n",
"ZZ\n",
"THISISTHELASTTEST\n",
"ABBCDEFB\n",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
"THISISATEST\n",
"LEHLLLLLLHAFGEGLLHAFDLHHLLLLLDGGEHGGHLLLLLLLLDFLCBLLEFLLCBLLCGLEDLGGLECLDGLEHLLLGELLLEGLLLLGDLLLDALD\n",
"Z\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You will receive 5 points for solving this problem.
Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and ... |
413_A. Data Recovery_15101 | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in... | n, m, mmin, mmax = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
if s[0] < mmin or s[m - 1] > mmax:
print("Incorrect")
elif s[0] == mmin and s[m - 1] == mmax:
print("Correct")
elif s[0] != mmin and s[m - 1] != mmax:
if n - m < 2:
print("Incorrect")
else:
pri... | {
"input": [
"2 1 1 3\n2\n",
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"100 99 1 2\n2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 2\n",
"4 1 2 100\n1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
T... |
43_C. Lucky Tickets_15105 | Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid a... | n=int(input())
inp = list(map(int,input().split()))
l=[0,0,0]
for item in inp:
l[item%3]+=1
a=l[0]
b=l[1]
c=l[2]
print (min(b,c)+a//2) | {
"input": [
"3\n123 123 99\n",
"6\n1 1 1 23 10 3\n",
"2\n55431511 35254032\n",
"3\n43440907 58238452 82582355\n",
"1\n19938466\n",
"10\n77241684 71795210 50866429 35232438 22664883 56785812 91050433 75677099 84393937 43832346\n",
"5\n83280 20492640 21552119 7655071 47966344\n",
"2\n28... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was havin... |
509_D. Restoring Numbers_15113 | Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula:
<image>
Vasya wrote down matrix v on a piece of paper and put it in the table.
A year later Vasya was cleaning his table when he found a p... | """
Codeforces Contest 289 Div 2 Problem D
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
n,m = read()
matrix = [read() for _ in range(n)]
mod = 10**11
for i in range(n-1):
poss = set()
for j in range(m):
... | {
"input": [
"2 2\n1 2\n2 1\n",
"2 2\n1 2\n2 0\n",
"2 3\n1 2 3\n2 3 4\n",
"2 2\n0 2\n2 1\n",
"1 1\n3\n",
"3 2\n3 0\n1 3\n3 1\n",
"2 2\n2 1\n0 2\n",
"2 2\n0 1000000000\n1000000000 57\n",
"2 2\n2 0\n1 2\n",
"2 3\n1 3 3\n3 0 1\n",
"3 2\n3 1\n3 0\n1 3\n",
"5 5\n65 65 63 66 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula:
<im... |
584_C. Marina and Vasya_15122 | Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ... | fs = frozenset(list("abc"))
def calc(s1, s2):
return len(list(filter(lambda x: x[0] == x[1], zip(s1, s2))))
if __name__ == '__main__':
n, t = map(int, input().split())
s1 = input()
s2 = input()
q = n - t
c = calc(s1, s2)
need = q - c
w = 0
ss = ['x'] * len(s1)
if n - c >= 2 ... | {
"input": [
"1 0\nc\nb\n",
"3 2\nabc\nxyc\n",
"1 0\nz\nz\n",
"2 2\nbb\ncb\n",
"1 1\na\nc\n",
"20 2\nywpcwcwgkhdeonzbeamf\ngdcmwcwgkhdeonzbeamf\n",
"5 2\nabaac\nbbbaa\n",
"3 1\nlos\nlns\n",
"7 4\nycgdbph\nfdtapch\n",
"10 6\nrnsssbuiaq\npfsbsbuoay\n",
"5 1\nicahj\nxdvch\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More form... |
606_C. Sorting Railway Cars_15126 | An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it... | def LIS(s):
n = len(s)
L = [0]*n
appear = [False]*n
L[0] = 1
find = [-1]*n
appear[s[0]] = True
find[s[0]] = 0
for i in range(1,len(s)):
if s[i]>0 and appear[s[i]-1]:
L[i] = L[find[s[i]-1]] + 1
else:
L[i] = 1
appear[s[i]] = True
find... | {
"input": [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n",
"50\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41\n",
"50\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to s... |
628_C. Bear and String Distance_15130 | Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, <image>, and <image>.
Also, the distance between two nice strings is defined as t... | #import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
alph = 'abcdefghijklmnopqrstuvwxyz'
n,k = map(int, input().split())
s = input()
res = ''
for c in s:
if k > 0:
r = ord('z') - ord(c)
l = ord(c) - ord('a')
if r >= l:
if k >= r:
... | {
"input": [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n",
"10 100\naddaiyssyp\n",
"2 49\nzz\n",
"2 1\nzz\n",
"1 24\ny\n",
"4 17\nrzsq\n",
"1 24\nz\n",
"2 48\nab\n",
"1 8\nc\n",
"5 24\nizrqp\n",
"1 25\na\n",
"1 25\nz\n",
"1 26\na\n",
"2 9\nbc\n",
"1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.