context stringlengths 88 7.54k | groundtruth stringlengths 9 28.8k | groundtruth_language stringclasses 3
values | type stringclasses 2
values | code_test_cases listlengths 1 565 ⌀ | dataset stringclasses 6
values | code_language stringclasses 1
value | difficulty float64 0 1 ⌀ | mid stringlengths 32 32 |
|---|---|---|---|---|---|---|---|---|
Mr. Chanek has an integer represented by a string s. Zero or more digits have been erased and are denoted by the character _. There are also zero or more digits marked by the character X, meaning they're the same digit.
Mr. Chanek wants to count the number of possible integer s, where s is divisible by 25. Of course, ... | s = input()
ways = 0
if len(s) == 1:
if s in ['_', 'X', '0']:
ways = 1
elif len(s) == 2:
if s in ['25', '50', '75']:
ways = 1
elif s in ['__', '_X', 'X_']:
ways = 3
elif s == '_0':
ways = 1
elif s in ['_5', 'X5']:
ways = 2
elif s in ['2_', '5_', '7_', '2X'... | python | code_algorithm | [
{
"input": "0\n",
"output": "1\n"
},
{
"input": "_XX\n",
"output": "9\n"
},
{
"input": "_00\n",
"output": "9\n"
},
{
"input": "0_25\n",
"output": "0\n"
},
{
"input": "25\n",
"output": "1\n"
},
{
"input": "X\n",
"output": "1\n"
},
{
"input":... | code_contests | python | 0 | ed6f1257ca12e3c82eb8f21afb8ef487 |
Mr. Chanek wants to knit a batik, a traditional cloth from Indonesia. The cloth forms a grid a with size n × m. There are k colors, and each cell in the grid can be one of the k colors.
Define a sub-rectangle as an ordered pair of two cells ((x_1, y_1), (x_2, y_2)), denoting the top-left cell and bottom-right cell (in... | n, m, k, r, c = map(int, input().split())
ax, ay, bx, by = map(int, input().split())
p = n * m
if ax != bx or ay != by:
p -= r * c
print(pow(k, p, 1000000007)) | python | code_algorithm | [
{
"input": "4 5 170845 2 2\n1 4 3 1\n",
"output": "756680455\n"
},
{
"input": "3 3 2 2 2\n1 1 2 2\n",
"output": "32\n"
},
{
"input": "997824195 298198038 671030405 831526 973640\n694897941 219757278 695597597 220039071\n",
"output": "885735196\n"
},
{
"input": "78 15 96708421... | code_contests | python | 0 | d33e36bf94b08b4d06c6cb4c1381cc4f |
Casimir has a rectangular piece of paper with a checkered field of size n × m. Initially, all cells of the field are white.
Let us denote the cell with coordinates i vertically and j horizontally by (i, j). The upper left cell will be referred to as (1, 1) and the lower right cell as (n, m).
Casimir draws ticks of di... | import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict, deque
from io import BytesIO, IOBase
from itertools import permutations
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
... | python | code_algorithm | [
{
"input": "8\n2 3 1\n*.*\n...\n4 9 2\n*.*.*...*\n.*.*...*.\n..*.*.*..\n.....*...\n4 4 1\n*.*.\n****\n.**.\n....\n5 5 1\n.....\n*...*\n.*.*.\n..*.*\n...*.\n5 5 2\n.....\n*...*\n.*.*.\n..*.*\n...*.\n4 7 1\n*.....*\n.....*.\n..*.*..\n...*...\n3 3 1\n***\n***\n***\n3 5 1\n*...*\n.***.\n.**..\n",
"output": "NO\... | code_contests | python | 0 | ca88f3cd16ba3a4859a25088141e9b4f |
CQXYM is counting permutations length of 2n.
A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
A... | from sys import stdin, gettrace
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
LIMIT = 200001
MOD = 1000000007
def solve(factorial):
n = int(input())
print( (factorial[2*n]*pow(2, MOD-2,... | python | code_algorithm | [
{
"input": "4\n1\n2\n9\n91234\n",
"output": "1\n12\n830455698\n890287984\n"
},
{
"input": "2\n99997\n3\n",
"output": "979296788\n360\n"
},
{
"input": "14\n13633\n739\n4\n1\n23481\n279\n5113\n2013\n48785\n12\n44\n5766\n3\n127\n",
"output": "265272552\n34141923\n20160\n1\n405591801\n64... | code_contests | python | 0 | dded87415d219981884917305a6a7adc |
CQXYM wants to create a connected undirected graph with n nodes and m edges, and the diameter of the graph must be strictly less than k-1. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one ed... | for _ in range(int(input())):n, m, k = map(int, input().split());print('YES') if (k == 3 and m == (n * (n - 1)) // 2) or (k > 3 and m >= n - 1 and m <= (n * (n - 1)) // 2) or (n == 1 and m == 0 and k > 1) else print('NO') | python | code_algorithm | [
{
"input": "5\n1 0 3\n4 5 3\n4 6 3\n5 4 1\n2 1 1\n",
"output": "YES\nNO\nYES\nNO\nNO\n"
},
{
"input": "1\n1 0 0\n",
"output": "NO\n"
},
{
"input": "1\n5 7 0\n",
"output": "NO\n"
},
{
"input": "5\n1 0 2\n1 0 1\n5 20 3\n5 20 4\n5 20 5\n",
"output": "YES\nNO\nNO\nNO\nNO\n"
... | code_contests | python | 0 | c778c5080a0af3985dbf796423726d96 |
The problem statement looms below, filling you with determination.
Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in ... | # SHRi GANESHA author: Kunal Verma #
import os
import sys
from collections import defaultdict, Counter
from io import BytesIO, IOBase
from math import gcd
def lcm(a, b):
return (a * b) // gcd(a, b)
'''
mod = 10 ** 9 + 7
fac = [1]
for i in range(1, 2 * 10 ** 5 + 1):
fac.append((fac[-1] *... | python | code_algorithm | [
{
"input": "4 5\n..XXX\n...X.\n...X.\n...X.\n5\n1 3\n3 3\n4 5\n5 5\n1 5\n",
"output": "YES\nYES\nNO\nYES\nNO\n"
},
{
"input": "3 3\n...\nXXX\nXX.\n10\n2 3\n1 2\n2 2\n1 3\n2 3\n1 2\n1 3\n1 3\n2 3\n1 1\n",
"output": "NO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\n"
},
{
"input": "1 1\n.\n1\n1 1... | code_contests | python | 0 | 027ae5229e7bff4483923b232d817be2 |
Omkar is creating a mosaic using colored square tiles, which he places in an n × n grid. When the mosaic is complete, each cell in the grid will have either a glaucous or sinoper tile. However, currently he has only placed tiles in some cells.
A completed mosaic will be a mastapeece if and only if each tile is adjace... | import sys
o = {'G':'S', 'S':'G'};n = int(input());d = [list(input()[:n]) for _ in range(n)];f = [1] * (n * n);finished = 1
if n % 2: print('NONE'); sys.exit()
x = [''] * (n // 2)
def findt(i, j): return abs(j - i) // 2 if (j - i) % 2 else min(i + j, 2 * (n - 1) - j - i) // 2
def findr(i, j, t):
if (j - i) % 2: ret... | python | code_algorithm | [
{
"input": "10\n.S....S...\n..........\n...SSS....\n..........\n..........\n...GS.....\n....G...G.\n..........\n......G...\n..........\n",
"output": "UNIQUE\nSSSSSSSSSS\nSGGGGGGGGS\nSGSSSSSSGS\nSGSGGGGSGS\nSGSGSSGSGS\nSGSGSSGSGS\nSGSGGGGSGS\nSGSSSSSSGS\nSGGGGGGGGS\nSSSSSSSSSS\n"
},
{
"input": "4\nS.... | code_contests | python | 0 | 7340efb269e595e32d5cd4256348800d |
It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.
Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?
You have a perfect binary tree of 2^k... | n = int(input())
vid = 6
k = 2
m = int(1e9 + 7)
for i in range(n - 1):
vid = (vid * pow(4, k, m)) % m
k *= 2
print(vid)
| python | code_algorithm | [
{
"input": "14\n",
"output": "934234\n"
},
{
"input": "3\n",
"output": "24576\n"
},
{
"input": "50\n",
"output": "902552662\n"
},
{
"input": "60\n",
"output": "937481864\n"
},
{
"input": "40\n",
"output": "622757975\n"
},
{
"input": "10\n",
"output... | code_contests | python | 0 | 03949d61d7e32aef9a92ff98a89330ef |
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors.
Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?
You have a perfect binary tree of 2^k - ... | import io,os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = 10**9 + 7
colors = {'white':0,'yellow':0,'green':1,'blue':1,'red':2,'orange':2}
def getnext(index,n,colored,dic,layer):
if layer==n:
if index not in dic: return [2,2,2]
else:
dic[index][colored[index]] +... | python | code_algorithm | [
{
"input": "10\n3\n1 blue\n4 red\n5 orange\n",
"output": "328925088\n"
},
{
"input": "3\n2\n5 orange\n2 white\n",
"output": "1024\n"
},
{
"input": "2\n2\n1 white\n2 white\n",
"output": "0\n"
},
{
"input": "5\n9\n31 yellow\n30 green\n26 yellow\n13 red\n2 red\n22 white\n12 red\... | code_contests | python | 0 | 013e36f8f3dee7c47acbe89bf885a328 |
You are given a matrix, consisting of n rows and m columns. The rows are numbered top to bottom, the columns are numbered left to right.
Each cell of the matrix can be either free or locked.
Let's call a path in the matrix a staircase if it:
* starts and ends in the free cell;
* visits only free cells;
* ha... | ''' E. Staircases
https://codeforces.com/contest/1598/problem/E
'''
import sys
input = sys.stdin.readline
output = sys.stdout.write
def solve(R, C, Q, queries):
blocked = [[0]*C for _ in range(R)]
# total staircases if no cell blocked
res = R*C # 1-block
for c in range(C): # right-down from row 0
for ln in r... | python | code_algorithm | [
{
"input": "3 4 10\n1 4\n1 2\n2 3\n1 2\n2 3\n3 2\n1 3\n3 4\n1 3\n3 1\n",
"output": "49\n35\n24\n29\n49\n39\n31\n23\n29\n27\n"
},
{
"input": "1000 1000 2\n239 634\n239 634\n",
"output": "1332632508\n1333333000\n"
},
{
"input": "2 2 8\n1 1\n1 1\n1 1\n2 2\n1 1\n1 2\n2 1\n1 1\n",
"output... | code_contests | python | 0 | e4315068752313a050d2199207c8eaa7 |
Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players.
Each game is set in one of the N maps, each having different terrain configuration. First phase of each game decides on which map the gam... |
n,target = map(float,input().split())
n = int(n)
def getprob(study):
tot = n*(n-1)*(n-2)//6
case1 = study*(study-1)*(study-2)//6
case2 = study*(study-1)*(n-study)//2
case3 = study*(n-study)*(n-study-1)//2
return (case1+case2+case3*0.5)*1.0/tot
front = 0
rear = n
while front<rear:
mid... | python | code_algorithm | [
{
"input": "7 1.0000\n",
"output": "6\n"
},
{
"input": "956 0.9733\n",
"output": "826\n"
},
{
"input": "444 0.0265\n",
"output": "8\n"
},
{
"input": "267 0.4122\n",
"output": "76\n"
},
{
"input": "840 0.5672\n",
"output": "336\n"
},
{
"input": "937 0.8... | code_contests | python | 0 | 37c5323b7eec8e56d57a3d9db5cb7b1b |
Alice and Bob are playing a game. They are given an array A of length N. The array consists of integers. They are building a sequence together. In the beginning, the sequence is empty. In one turn a player can remove a number from the left or right side of the array and append it to the sequence. The rule is that the s... | from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
#from collections import deque, Counter, OrderedDict, defaultdict
#import heapq
#ceil,floor,log,sqrt,factorial,pow,pi,gcd
#import bisect
#from bisect import bisect_left,bisect_right
BUFSIZE = 8192
class Fa... | python | code_algorithm | [
{
"input": "6\n5 8 2 1 10 9\n",
"output": "Bob\n"
},
{
"input": "3\n5 4 5\n",
"output": "Alice\n"
},
{
"input": "1\n5\n",
"output": "Alice\n"
},
{
"input": "3\n5 6 5\n",
"output": "Bob\n"
},
{
"input": "2\n5 12\n",
"output": "Alice\n"
}
] | code_contests | python | 0 | 0b82e39a18efc587bc5fec3b4162b3aa |
On the great island of Baltia, there live N people, numbered from 1 to N. There are exactly M pairs of people that are friends with each other. The people of Baltia want to organize a successful party, but they have very strict rules on what a party is and when the party is successful. On the island of Baltia, a party ... | import sys
input = sys.stdin.readline
n,m = map(int,input().split())
G = [[] for _ in range(n)]
for _ in range(m):
u,v = map(int,input().split())
u -= 1
v -= 1
if u >= 48 or v >= 48:
continue
G[u].append(v)
G[v].append(u)
if n >= 48:
G = G[:48]
def ok(a,b,c,d,e):
allfd = Tr... | python | code_algorithm | [
{
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n",
"output": "-1\n"
},
{
"input": "6 3\n1 4\n4 2\n5 4\n",
"output": "1 2 3 5 6\n"
},
{
"input": "6 13\n5 6\n2 5\n1 4\n6 2\n3 5\n4 5\n6 4\n3 1\n1 6\n1 5\n2 4\n6 3\n1 2\n",
"output": "1 2 4 5 6\n"
},
{
"input": "10 8\n5 2\n1 8\n5 7\n1 9\n6 4... | code_contests | python | 0.6 | 190d012411765eb1e1bcac2fefb45fe0 |
Berland State University has received a new update for the operating system. Initially it is installed only on the 1-st computer.
Update files should be copied to all n computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them usin... | import sys
for t in range(int(input())):
n, k = map(int, sys.stdin.readline().strip().split())
ans = 0
cur = 1
while cur <= k and cur < n:
cur *= 2
ans += 1
if cur <= n:
ans += (n - cur + k - 1) // k
print(ans)
| python | code_algorithm | [
{
"input": "4\n8 3\n6 6\n7 1\n1 1\n",
"output": "4\n3\n6\n0\n"
},
{
"input": "1\n576460752303423489 576460752303423489\n",
"output": "60\n"
},
{
"input": "1\n36028797018963968 18014398509481983\n",
"output": "56\n"
},
{
"input": "4\n576460752303423488 288230376151711743\n5764... | code_contests | python | 0 | eaaf5d959fe53391d06797f073326264 |
Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer x with p zeros appended to its end.
Now Monocarp asks you to compare these two numbers. Can you help him?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of testcases.
The first li... | #for line in sys.stdin.readlines()...line = line.strip()
#list(map(int,input().split(" ")))
#list(itertools.permutations([..,..,..]))
#list(itertools.combinations([..,..,..], 3)
import sys
import math
from math import log2 as lg
from collections import deque
import random
import heapq
import itertools
const = 10000000... | python | code_algorithm | [
{
"input": "5\n2 1\n19 0\n10 2\n100 1\n1999 0\n2 3\n1 0\n1 0\n99 0\n1 2\n",
"output": ">\n=\n<\n=\n<\n"
},
{
"input": "1\n2000 0\n2 3\n",
"output": "=\n"
},
{
"input": "1\n1 6\n1000000 0\n",
"output": "=\n"
},
{
"input": "3\n1 3\n100 1\n2 3\n200 1\n6 3\n600 1\n",
"output"... | code_contests | python | 0.7 | e2bf854e57e1f6db0f88220b81e7c86d |
You are given a sequence a_1, a_2, ..., a_n consisting of n pairwise distinct positive integers.
Find \left⌊ \frac n 2 \right⌋ different pairs of integers x and y such that:
* x ≠ y;
* x and y appear in a;
* x~mod~y doesn't appear in a.
Note that some x or y can belong to multiple pairs.
⌊ x ⌋ denotes t... | for _ in range(int(input())):
n=int(input())
a=list(map(int, input().split()))
a.sort()
y=a[0]
for i in range(1,n//2 + 1):
print(a[i] , y)
| python | code_algorithm | [
{
"input": "4\n2\n1 4\n4\n2 8 3 4\n5\n3 8 5 9 7\n6\n2 7 5 3 4 8\n",
"output": "4 1\n3 2\n4 2\n5 3\n7 3\n3 2\n4 2\n5 2\n"
},
{
"input": "1\n5\n200005 200006 200007 200008 200009\n",
"output": "200006 200005\n200007 200005\n"
},
{
"input": "1\n2\n4 2\n",
"output": "4 2\n"
},
{
... | code_contests | python | 0 | 7a181447fbe88b957d382a337e51b4a8 |
Monocarp is playing yet another computer game. In this game, his character has to kill a dragon. The battle with the dragon lasts 100^{500} seconds, during which Monocarp attacks the dragon with a poisoned dagger. The i-th attack is performed at the beginning of the a_i-th second from the battle start. The dagger itsel... | import math
#s = input()
#n= (map(int, input().split()))
#(map(int, input().split()))
#a, b = (map(int, input().split()))
for i in range(0, int(input())):
n, h =(map(int, input().split()))
a = list(map(int, input().split()))
dist = list()
for j in range(0, len(a)-1):
dist.append(a[j+1]-a[... | python | code_algorithm | [
{
"input": "4\n2 5\n1 5\n3 10\n2 4 10\n5 3\n1 2 4 5 7\n4 1000\n3 25 64 1337\n",
"output": "3\n4\n1\n470\n"
},
{
"input": "1\n2 1000000000000000000\n1 1000000000\n",
"output": "999999999000000001\n"
},
{
"input": "1\n2 1000000000000000000\n1000000 1000000000\n",
"output": "99999999900... | code_contests | python | 0 | c9f6ae263bdc8682251c0d4c7108f19a |
You are given an array a of n integers, and another integer k such that 2k ≤ n.
You have to perform exactly k operations with this array. In one operation, you have to choose two elements of the array (let them be a_i and a_j; they can be equal or different, but their positions in the array must not be the same), remo... | import math
import os
import sys
from io import BytesIO, IOBase
M = 1000000007
import random
import heapq
import threading
import bisect
import time
#sys.setrecursionlimit(2*(10**5))
from functools import *
from collections import *
from itertools import *
BUFSIZE = 8192
import array
class FastIO(IOBase):
newlines ... | python | code_algorithm | [
{
"input": "5\n7 3\n1 1 1 2 1 3 1\n5 1\n5 5 5 5 5\n4 2\n1 3 3 7\n2 0\n4 2\n9 2\n1 10 10 1 10 2 7 10 3\n",
"output": "2\n16\n0\n6\n16\n"
},
{
"input": "1\n6 3\n4 4 5 5 6 6\n",
"output": "0\n"
},
{
"input": "1\n6 3\n1 1 1 1 2 2\n",
"output": "1\n"
},
{
"input": "1\n9 3\n1 1 1 2... | code_contests | python | 0 | c843f5a976f762c8c026a79e8501c443 |
You are given two positive integers x and y. You can perform the following operation with x: write it in its binary form without leading zeros, add 0 or 1 to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of x.
For example:
* 34 can be turned into 81 v... | #import io,os
#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque
def main(t):
x, y = map(int,input().split())
sx, sy = bin(x)[2:],bin(y)[2:]
dic = {}
queue = deque()
queue.append(sx)
dic[sx] = 1
i = len(sx)-1
while i>=0 and sx[i]=='0': ... | python | code_algorithm | [
{
"input": "2 8\n",
"output": "NO\n"
},
{
"input": "7 4\n",
"output": "NO\n"
},
{
"input": "8935891487501725 71487131900013807\n",
"output": "YES\n"
},
{
"input": "3 3\n",
"output": "YES\n"
},
{
"input": "34 69\n",
"output": "YES\n"
},
{
"input": "4700... | code_contests | python | 0 | ee919416f7547b59f73998f57b6dcd6e |
Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: 1, 4, 8, 9, ....
For a given number n, count the number of integers from 1 to n that Polycarp likes. In other words, find the number of such x that x is a square of a positive integer number or a cube of a... |
for i in range(int(input())):
n=int(input())
count=[0]
if n==1:
print(1)
else:
for i in range(1,n):
if i*i>n:
break
if i*i<=n:
count.append(i*i)
if i*i*i<=n:
count.append(i*i*i)
else:
pass
print(len(set(count))-1)
| python | code_algorithm | [
{
"input": "6\n10\n1\n25\n1000000000\n999999999\n500000000\n",
"output": "4\n1\n6\n32591\n32590\n23125\n"
},
{
"input": "2\n64\n15625\n",
"output": "10\n145\n"
},
{
"input": "8\n64000000\n85766121\n113379904\n148035889\n191102976\n244140625\n594823321\n887503681\n",
"output": "8380\n... | code_contests | python | 0 | 6c9f898ead11fb33b5717e51cc446587 |
You are given a permutation p of n elements. A permutation of n elements is an array of length n containing each integer from 1 to n exactly once. For example, [1, 2, 3] and [4, 3, 5, 1, 2] are permutations, but [1, 2, 4] and [4, 3, 2, 1, 2] are not permutations. You should perform q queries.
There are two types of qu... |
def main():
n, q = readIntArr()
p = readIntArr()
for i in range(n):
p[i] -= 1 # make 0-index
base = int(n ** 0.5 + 1)
a = [-1] * n # a[i] is i after base operations
r = [-1] * n # r is reverse of p, i.e. base operations back. r[p[i]] = i
for i in range(n):
r[p[i]] ... | python | code_algorithm | [
{
"input": "5 9\n2 3 5 1 4\n2 3 5\n2 5 5\n2 5 1\n2 5 3\n2 5 4\n1 5 4\n2 5 3\n2 2 5\n2 5 1\n",
"output": "3\n5\n4\n2\n3\n3\n3\n1\n"
},
{
"input": "5 4\n5 3 4 2 1\n2 3 1\n2 1 2\n1 1 3\n2 1 2\n",
"output": "4\n1\n2\n"
},
{
"input": "1 1\n1\n2 1 1\n",
"output": "1\n"
},
{
"input"... | code_contests | python | 0.8 | e8a840ec24cea991b3b6d2646ecca5d8 |
You had n positive integers a_1, a_2, ..., a_n arranged in a circle. For each pair of neighboring numbers (a_1 and a_2, a_2 and a_3, ..., a_{n - 1} and a_n, and a_n and a_1), you wrote down: are the numbers in the pair equal or not.
Unfortunately, you've lost a piece of paper with the array a. Moreover, you are afraid... | from itertools import permutations as per
from math import factorial as fact
from difflib import SequenceMatcher
t = int(input())
# map(int,input().split())
# [int(i) for i in input().split()]
for _ in range(t):
s = input()
print("YES") if s.count('N') != 1 else print("NO") | python | code_algorithm | [
{
"input": "4\nEEE\nEN\nENNEENE\nNENN\n",
"output": "YES\nNO\nYES\nYES\n"
},
{
"input": "1\nNEEEEEEEEEEEEEEEEEEEEEEEEEEEEENNNNEENNE\n",
"output": "YES\n"
},
{
"input": "2\nEEEEEEN\nEEEEEEEN\n",
"output": "NO\nNO\n"
},
{
"input": "2\nEEEEEN\nEEEEEN\n",
"output": "NO\nNO\n"... | code_contests | python | 0 | b2054af6a0a54119a2c0860d5993b939 |
There are three sticks with integer lengths l_1, l_2 and l_3.
You are asked to break exactly one of them into two pieces in such a way that:
* both pieces have positive (strictly greater than 0) integer length;
* the total length of the pieces is equal to the original length of the stick;
* it's possible to ... | for _ in range(int(input())):
a, b, c = map(int, input().split())
if a == b + c or b == a + c or c == a + b:
print('YES')
elif a == b and c % 2 == 0:
print('YES')
elif a == c and b % 2 == 0:
print('YES')
elif b == c and a % 2 == 0:
print('YES')
else:
print... | python | code_algorithm | [
{
"input": "4\n6 1 5\n2 5 2\n2 4 2\n5 5 4\n",
"output": "YES\nNO\nYES\nYES\n"
},
{
"input": "2\n1 2 3\n2 2 4\n",
"output": "YES\nYES\n"
},
{
"input": "1\n1 98 99\n",
"output": "YES\n"
},
{
"input": "3\n1 1 1\n2 1 3\n5 6 7\n",
"output": "NO\nYES\nNO\n"
},
{
"input"... | code_contests | python | 0.1 | 2879205d306123ae9ce4dbcf776f3007 |
You are given an integer array a_1, a_2, ..., a_n and integer k.
In one step you can
* either choose some index i and decrease a_i by one (make a_i = a_i - 1);
* or choose two indices i and j and set a_i equal to a_j (make a_i = a_j).
What is the minimum number of steps you need to make the sum of array ∑_{... | import sys
import os.path
from collections import *
import math
import bisect
import heapq as hq
from fractions import Fraction
from random import randint
if os.path.exists("input.txt"):
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
input = sys.stdin.readline
#######################... | python | code_algorithm | [
{
"input": "4\n1 10\n20\n2 69\n6 9\n7 8\n1 2 1 3 1 2 1\n10 1\n1 2 3 1 2 6 1 6 8 10\n",
"output": "10\n0\n2\n7\n"
},
{
"input": "1\n84 781\n403 867 729 928 240 410 849 95 651 852 230 209 358 596 576 230 924 448 288 19 680 470 839 107 931 809 347 903 399 185 840 326 338 758 584 385 862 140 256 537 677... | code_contests | python | 0 | dca475f9b068aea1d370ddd66b3407af |
You are given a binary string (i. e. a string consisting of characters 0 and/or 1) s of length n. You can perform the following operation with the string s at most once: choose a substring (a contiguous subsequence) of s having exactly k characters 1 in it, and shuffle it (reorder the characters in the substring as you... | from sys import stdin, stdout
N = 998244353
def egcd(a, b):
"""return (g, x, y) such that a*x + b*y = g = gcd(a, b)"""
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)
def modinv(a, m = N):
"""return inverse of a mod m"""
g, x, y =... | python | code_algorithm | [
{
"input": "10 8\n0010011000\n",
"output": "1\n"
},
{
"input": "5 0\n10010\n",
"output": "1\n"
},
{
"input": "8 1\n10001000\n",
"output": "10\n"
},
{
"input": "7 2\n1100110\n",
"output": "16\n"
},
{
"input": "5 2\n00011\n",
"output": "10\n"
},
{
"input... | code_contests | python | 0 | 0921790b4d1ff3f65f38259f2a60ad25 |
The statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different.
A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are num... | import sys
from sys import stdin
import math
mod = 10**9+7
def inverse(n,mod):
return pow(n,mod-2,mod)
onehand = inverse(100,mod)
tt = int(stdin.readline())
ANS = []
for _ in range(tt):
n,m,rb,cb,rd,cd,p = map(int,stdin.readline().split())
p = p*onehand % mod
#print (p)
loop = 2*(n-1)*2*(m-1... | python | code_algorithm | [
{
"input": "6\n2 2 1 1 2 1 25\n3 3 1 2 2 2 25\n10 10 1 1 10 10 75\n10 10 10 10 1 1 75\n5 5 1 3 2 2 10\n97 98 3 5 41 43 50\n",
"output": "3\n3\n15\n15\n332103349\n99224487\n"
},
{
"input": "10\n8 5279 1 1543 6 1521 6\n25276 2 25276 2 1365 1 36\n49526 2 1 1 9796 2 29\n374 73 225 73 291 27 26\n4786 11 ... | code_contests | python | 0 | b2718767b99e2fd1d164651d564eb67d |
There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:
* ... | from collections import deque
def solve(adj, m, k, uv):
n = len(adj)
nn = [len(a) for a in adj]
q = deque()
for i in range(n):
if nn[i] < k:
q.append(i)
while q:
v = q.popleft()
for u in adj[v]:
nn[u] -= 1
if nn[u] == k-1:
... | python | code_algorithm | [
{
"input": "4 4 2\n2 3\n1 2\n1 3\n1 4\n",
"output": "0\n0\n3\n3\n"
},
{
"input": "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n",
"output": "0\n0\n0\n3\n3\n4\n4\n5\n"
},
{
"input": "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n",
"output": "0\n0\n0\n0\n3\n4\n4\n"
},
{
"input":... | code_contests | python | 0 | beb0dd6a12442bd279058321cc62f55b |
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone n... | n = int(input())
s = input()
k = s.count("8")
l = n - k
if k <= l//10: print(k)
else:
while k > l//10:
k -= 1
l += 1
print(min(k, l//10))
| python | code_algorithm | [
{
"input": "22\n0011223344556677889988\n",
"output": "2\n"
},
{
"input": "11\n00000000008\n",
"output": "1\n"
},
{
"input": "11\n31415926535\n",
"output": "0\n"
},
{
"input": "51\n882889888888689888850888388887688788888888888858888\n",
"output": "4\n"
},
{
"input"... | code_contests | python | 0.7 | b01666dd88e1ad0a807582f711932e08 |
You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l ≤ x ≤ r.
Input
The first l... | n = int(input())
A = []
for i in range(n):
A = A+[input().split()]
for a in A:
if int(a[2]) < int(a[0]) or int(a[2]) > int(a[1]):
print(a[2])
else:
print(int(a[2])*(int(a[1])//int(a[2])+1))
| python | code_algorithm | [
{
"input": "5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"output": "6\n4\n1\n3\n10\n"
},
{
"input": "20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 100... | code_contests | python | 0.6 | 59abd6c42ba050b98fa6f7b72a5aaba5 |
An array of integers p_{1},p_{2}, …,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4].
There is a hidden permutation of length n.
... | from sys import stdin,stdout
class Tree(object):
def __init__(self,n):
self.tree=[0]*(4*n+10)
self.b=[0]*(n+10)
self.a=list(map(int,stdin.readline().split()))
self.n=n
def update(self,L,C,l,r,rt):
if l==r:
self.tree[rt]+=C
return
mid=(l+r)... | python | code_algorithm | [
{
"input": "3\n0 0 0\n",
"output": "3 2 1 "
},
{
"input": "5\n0 1 1 1 10\n",
"output": "1 4 3 2 5 "
},
{
"input": "2\n0 1\n",
"output": "1 2 "
},
{
"input": "100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1... | code_contests | python | 0 | 604af8f068c0bed3738b6e00e0ab903d |
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily... | # class SegmentTree(): # adapted from https://www.geeksforgeeks.org/segment-tree-efficient-implementation/
# def __init__(self,arr,func,initialRes=0):
# self.f=func
# self.N=len(arr)
# self.tree=[0 for _ in range(2*self.N)]
# self.initialRes=initialRes
# for i in range(self.... | python | code_algorithm | [
{
"input": "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n",
"output": "20\n10\n20\n10\n20\n10\n"
},
{
"input": "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n",
"output": "2\n3\n2\n3\n2\n3\n1\n1\n3\n"
},
{
"input": "2\n1 10\n3\n2 2\n2 1\n1 1\n",
"output": "10\n1\... | code_contests | python | 0.3 | 760b8bb2034c3becd8829ce071321ee1 |
There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
You're given k subsets A_1, …, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 ≤ i_1 < i_2 < i_3 ≤ k, A_{i_1} ∩ A_{i_2} ∩ A_{i_3} = ∅.
In one operation, you ... | from sys import stdin
input = stdin.readline
n , k = [int(i) for i in input().split()]
pairs = [i + k for i in range(k)] + [i for i in range(k)]
initial_condition = list(map(lambda x: x == '1',input().strip()))
data = [i for i in range(2*k)]
constrain = [-1] * (2*k)
h = [0] * (2*k)
L = [1] * k + [0] * k
dp1 = [-1 for... | python | code_algorithm | [
{
"input": "5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n",
"output": "1\n1\n1\n1\n1\n"
},
{
"input": "8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n",
"output": "1\n1\n1\n1\n1\n1\n4\n4\n"
},
{
"input": "19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16... | code_contests | python | 0 | ae86fea13f1ef4e812fa9f7d6a89219a |
Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size n× n and he wants to traverse his grid f... | l=[]
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(list(input()))
if a[0][1]==a[1][0]:
if a[n-1][n-2]==a[n-2][n-1]:
if a[n-1][n-2]==a[0][1]:
l.append("2")
l.append("1 2")
l.append("2 1")
... | python | code_algorithm | [
{
"input": "3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n",
"output": "1\n3 4\n2\n1 2\n2 1\n0\n"
},
{
"input": "1\n3\nS01\n111\n00F\n",
"output": "2\n1 2\n2 3\n"
},
{
"input": "1\n5\nS0000\n00000\n00000\n00000\n0000F\n",
"output": "2\n1 2\n2 1... | code_contests | python | 0 | 0e7a1641aa74ffc84054534c56b96a9c |
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | inn = list(map(int, input().split(" ")))
r1 = inn[0]
r2 = inn[1]
inn = list(map(int, input().split(" ")))
c1 = inn[0]
c2 = inn[1]
inn = list(map(int, input().split(" ")))
d1 = inn[0]
d2 = inn[1]
x = int((d1+c1-r2)/2)
y = int(((2*r1)-d1-c1+r2)/2)
a = int(((2*c1)-d1-c1+r2)/2)
b = int((r2-(2*c1)+d1+c1)/2)
if x == y or x ... | python | code_algorithm | [
{
"input": "1 2\n3 4\n5 6\n",
"output": "-1\n"
},
{
"input": "11 10\n13 8\n5 16\n",
"output": "4 7\n9 1\n"
},
{
"input": "3 7\n4 6\n5 5\n",
"output": "1 2\n3 4\n"
},
{
"input": "10 10\n10 10\n10 10\n",
"output": "-1\n"
},
{
"input": "3 14\n8 9\n10 7\n",
"outpu... | code_contests | python | 0.6 | 9e58991860e856dce4bee86fc9243d92 |
This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
The process is an infinite sequence of operations. Each operat... | def putin():
return map(int, input().split())
def sol():
n = int(input())
C = list(putin())
B = list(putin())
q = int(input())
x = int(input())
min_arr = [x]
min_part_sums = [x]
part_sums = [C[0]]
for i in range(1, n):
part_sums.append(part_sums[-1] + C[i])
for elem... | python | code_algorithm | [
{
"input": "3\n2 3 4\n2 1\n1\n-1\n",
"output": "56\n"
},
{
"input": "100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 9... | code_contests | python | 0 | b7f843cc7856e86bbd1dcf8832051cd5 |
Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administr... | num,wiz,per = map(int,input().split())
k = 0
while (k+wiz)/num*100 < per:
k += 1
print(k) | python | code_algorithm | [
{
"input": "1000 352 146\n",
"output": "1108\n"
},
{
"input": "10 1 14\n",
"output": "1\n"
},
{
"input": "20 10 50\n",
"output": "0\n"
},
{
"input": "7879 2590 2818\n",
"output": "219441\n"
},
{
"input": "78 28 27\n",
"output": "0\n"
},
{
"input": "917... | code_contests | python | 1 | 448467bd18f58351ae6cb788118b535b |
A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say tha... | s=input()
n=len(s)
l=list("0987654321")
cnt={}
for i in range(n-9):
t=s[i:i+10]
if t[0] in l and t[1] in l and t[2]=="-" and t[3] in l and t[4] in l and t[5]=="-" and t[6] in l and t[7] in l and t[8] in l and t[9] in l:
if 2013<=int(t[6:11])<=2015 and 1<=int(t[3:5])<=12:
if int(t[3:5]) in [1,3,5,7,8,10,1... | python | code_algorithm | [
{
"input": "777-444---21-12-2013-12-2013-12-2013---444-777\n",
"output": "13-12-2013\n"
},
{
"input": "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n",
"output": "12-12-2013\n"
},
{
"input": "01--01--2013-12-2013-0... | code_contests | python | 0 | 9d239ad589285ee12c32b4c7a30ff051 |
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... | a, b = map(int, input().split())
c, s = a, 0
while a >= b:
s += a // b
a = (a // b) + (a % b)
print(s + c)
| python | code_algorithm | [
{
"input": "4 2\n",
"output": "7\n"
},
{
"input": "6 3\n",
"output": "8\n"
},
{
"input": "5 3\n",
"output": "7\n"
},
{
"input": "1000 3\n",
"output": "1499\n"
},
{
"input": "777 17\n",
"output": "825\n"
},
{
"input": "4 3\n",
"output": "5\n"
},
... | code_contests | python | 1 | 8915a1a694bf86827f735bc79cf88e2d |
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | def nik(rudy,x,y,z,cot):
for i in range(z+1):
for j in range(y+1):
t = rudy - i*2 -j
if t>=0 and x*0.5 >= t:
cot+=1
return cot
rudy, x, y, z = list(map(int,input().split()))
cot = 0
print(nik(rudy,x,y,z,cot))
| python | code_algorithm | [
{
"input": "10 5 5 5\n",
"output": "9\n"
},
{
"input": "3 0 0 2\n",
"output": "0\n"
},
{
"input": "10 20 10 5\n",
"output": "36\n"
},
{
"input": "20 1 2 3\n",
"output": "0\n"
},
{
"input": "7 2 2 2\n",
"output": "1\n"
},
{
"input": "25 10 5 10\n",
... | code_contests | python | 0 | 43b30ec367ef72433f9dcadacd92e159 |
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | n = int(input())
a_sum = sum(map(int, input().split()))
b_sum = sum(map(int, input().split()))
c_sum = sum(map(int, input().split()))
print(a_sum - b_sum)
print(b_sum - c_sum) | python | code_algorithm | [
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"output": "1\n3\n"
},
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"output": "8\n123\n"
},
{
"input": "3\n1 2 3\n3 2\n2\n",
"output": "1\n3\n"
},
{
"input": "3\n84 30 9\n9 84\n9\n",
"output": "30\n84\n"
},
{
"... | code_contests | python | 0.7 | c9cd3f8280a7cdbc60d57c9ebe1ce496 |
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | ll=lambda:map(int,input().split())
t=lambda:int(input())
ss=lambda:input()
#from math import log10 ,log2,ceil,factorial as f,gcd
#from itertools import combinations_with_replacement as cs
#from functools import reduce
#from bisect import bisect_right as br
#from collections import Counter
n=t()
x,h=[],[]
for _ in ran... | python | code_algorithm | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"output": "4\n"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"output": "3\n"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1\n",
"output": "4\n"
},
{
"input": "2\n1 999999999\n1000000000 1000000000\n",
"output": "2\n"
},
{
... | code_contests | python | 0 | 27cddf12656da9ed27befa5451b17836 |
Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | import math
nm = input().split()
n = int(nm[0])
m = int(nm[1])
lis = [ 0 for i in range(m+1)]
for _ in range(n) :
inp = list(map(int, input().split()))
inp.pop(0)
for i in inp:
lis[i]=1
prev = i
if sum(lis)==m:
print("YES")
else:
print("NO") | python | code_algorithm | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2\n",
"output": "YES\n"
},
{
"input": "3 3\n1 1\n1 2\n1 1\n",
"output": "NO\n"
},
{
"input": "3 4\n1 1\n1 2\n1 3\n",
"output": "NO\n"
},
{
"input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3... | code_contests | python | 1 | 1e0fc159cc586e0b93922ac769ee474a |
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | def main():
l = input().split()
print(*l)
for _ in range(int(input())):
a, b = input().split()
l[a == l[1]] = b
print(*l)
if __name__ == '__main__':
main()
| python | code_algorithm | [
{
"input": "icm codeforces\n1\ncodeforces technex\n",
"output": "icm codeforces\nicm technex\n"
},
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n"
},
{
"input": "wwwww... | code_contests | python | 0.3 | f7468dba19ad098239fa7efec4acc4cb |
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | t, m = map(int, input().split())
disk = [False] * m
req = 0
for i in range(t):
inp = input().split()
if inp[0][0] == "a":
c = 0
inp[1] = int(inp[1])
for j in range(m):
if disk[j]:
c = 0
else:
c += 1
if c == inp[1]:
... | python | code_algorithm | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"output": "1\n2\nNULL\n3\n"
},
{
"input": "3 1\nerase -1\nerase 0\nerase -2147483648\n",
"output": "ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n"
},
{
"input": "26 25\ndefragment\ner... | code_contests | python | 0 | 26e6f8ab82989c487d130c5a82b327ab |
Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
inf = [0] * (n + 1)
curr = 0
d = 0
for i in range(n):
curr += abs(i + 1 - a[i])
if a[i] > i + 1:
d += 1
inf[a[i] - i - 1] += 1
elif a[i] <= i +... | python | code_algorithm | [
{
"input": "3\n3 2 1\n",
"output": "2 1\n"
},
{
"input": "3\n1 2 3\n",
"output": "0 0\n"
},
{
"input": "3\n2 3 1\n",
"output": "0 1\n"
},
{
"input": "4\n1 2 4 3\n",
"output": "2 0\n"
},
{
"input": "4\n2 1 4 3\n",
"output": "4 0\n"
},
{
"input": "10\n1 ... | code_contests | python | 0.5 | 65f9e6f27980b75233674c2fcfd9bf07 |
Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | import sys
# @profile
def main():
f = sys.stdin
# f = open('input.txt', 'r')
# fo = open('log.txt', 'w')
n = int(f.readline())
# b = []
# for i in range(n):
# b.append()
b = list(map(int, f.readline().strip().split(' ')))
a = list(map(int, f.readline().strip().split(' ')))
# ... | python | code_algorithm | [
{
"input": "3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"output": "NO\n"
},
{
"input": "3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"output": "YES\n"
},
{
"input": "5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"output": "NO\n"
},
... | code_contests | python | 0 | 6320bf5975516c11a22238f42feb9d0e |
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | #Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)
n, d = map(int, input().split())
a = list(map(int, input().split()))
p = [0 for i in range(n)]
for i in range(n):
p[i] = p[i-1]+a[i]
mx = [-1 for i in ra... | python | code_algorithm | [
{
"input": "5 10\n-5 0 10 -11 0\n",
"output": "2\n"
},
{
"input": "5 10\n-1 5 0 -5 3\n",
"output": "0\n"
},
{
"input": "3 4\n-10 0 20\n",
"output": "-1\n"
},
{
"input": "9 13\n6 14 19 5 -5 6 -10 20 8\n",
"output": "-1\n"
},
{
"input": "8 9\n6 -1 5 -5 -8 -7 -8 -7\n... | code_contests | python | 0 | 33225e8e01201c2b2b907a4331fd0dac |
Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | def is_prime(a):
return all(a % i for i in range(2, a))
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if is_prime(k):
if k in l:
print(1)
else:
print(k)
else:
ll = []
for i in range(len(l)):
if k % l[i] == 0:
ll.append(l[i])
print(k ... | python | code_algorithm | [
{
"input": "3 6\n2 3 5\n",
"output": "2\n"
},
{
"input": "6 7\n1 2 3 4 5 6\n",
"output": "7\n"
},
{
"input": "3 7\n3 2 1\n",
"output": "7\n"
},
{
"input": "4 97\n97 1 50 10\n",
"output": "1\n"
},
{
"input": "5 25\n24 5 15 25 23\n",
"output": "1\n"
},
{
... | code_contests | python | 0.5 | 3b105121cca3287972bd6dd6b9210cef |
You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... | input()
a=list(map(int,input().split()))
ans=0
for x in a:
z=min(x-1,1000000-x)
ans=max(z,ans)
print(ans)
| python | code_algorithm | [
{
"input": "2\n2 999995\n",
"output": "5\n"
},
{
"input": "3\n2 3 9\n",
"output": "8\n"
},
{
"input": "3\n500000 500001 500002\n",
"output": "499999\n"
},
{
"input": "1\n505050\n",
"output": "494950\n"
},
{
"input": "2\n999998 999999\n",
"output": "2\n"
},
... | code_contests | python | 0.2 | 2ccad2343428afdd712d95cd5fd34968 |
Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... | import sys
from array import array
n, m, k = map(int, input().split())
block = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
if block and block[0] == 0:
print(-1)
exit()
prev = array('i', list(range(n)))
for x in block:
prev[x] = -1
for i in range(1, n):
if prev[i] == -1:... | python | code_algorithm | [
{
"input": "5 1 5\n0\n3 3 3 3 3\n",
"output": "-1\n"
},
{
"input": "4 3 4\n1 2 3\n1 10 100 1000\n",
"output": "1000\n"
},
{
"input": "7 4 3\n2 4 5 6\n3 14 15\n",
"output": "-1\n"
},
{
"input": "6 2 3\n1 3\n1 2 3\n",
"output": "6\n"
},
{
"input": "3 1 2\n2\n1 1\n",... | code_contests | python | 0 | da0767aaf952b30a8e07d9d301bd2179 |
At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector А:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
... | import math
def ok(xa, ya):
x, y = xb - xa, yb - ya
d = math.gcd(abs(xc), abs(yc))
if xc == 0 and yc == 0:
return x == 0 and y == 0
if xc == 0:
return x % yc == 0 and y % yc == 0
if yc == 0:
return x % xc == 0 and y % xc == 0
if (x % d != 0) or (y % d != 0):
retu... | python | code_algorithm | [
{
"input": "0 0\n1 1\n1 1\n",
"output": "YES\n"
},
{
"input": "0 0\n1 1\n0 1\n",
"output": "YES\n"
},
{
"input": "0 0\n1 1\n2 2\n",
"output": "NO\n"
},
{
"input": "3 1\n-2 3\n-2 -2\n",
"output": "NO\n"
},
{
"input": "-8916 9282\n2666 2344\n9109 -2730\n",
"outp... | code_contests | python | 0 | 38abe6c6854f1adfc90fbd5ef9e809b3 |
Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from t... | import math
n = int(input())
l= list(map(int,input().split()))
s = 2*sum(l)
z= s/n
p = max(l)
an = int(z+1)
print(max(p,an)) | python | code_algorithm | [
{
"input": "5\n2 2 3 2 2\n",
"output": "5\n"
},
{
"input": "5\n1 1 1 5 1\n",
"output": "5\n"
},
{
"input": "3\n1 2 6\n",
"output": "7\n"
},
{
"input": "10\n7 7 7 7 7 7 7 7 7 7\n",
"output": "15\n"
},
{
"input": "76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3... | code_contests | python | 0.8 | 6e253981a563942c19cbc4489a791381 |
At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to de... | import sys
import math
import bisect
from math import sqrt
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1e9)+7
n, m = ... | python | code_algorithm | [
{
"input": "5 2\n3 1 5 4 2\n5 2\n5 4\n",
"output": "1\n"
},
{
"input": "3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"output": "2\n"
},
{
"input": "2 1\n1 2\n1 2\n",
"output": "1\n"
},
{
"input": "10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1... | code_contests | python | 0 | e394c4bb4a3624ee6c6039c8cc801fcf |
You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from po... | '''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
def main():
n = input()
s = input()
for i in range(len(s)-1):
if s[i]>s[i+1]:
print('YES'... | python | code_algorithm | [
{
"input": "7\nabacaba\n",
"output": "YES\n2 3\n"
},
{
"input": "6\naabcfg\n",
"output": "NO\n"
},
{
"input": "6\nbabcdc\n",
"output": "YES\n1 2\n"
},
{
"input": "5\nbadec\n",
"output": "YES\n1 2\n"
},
{
"input": "3\naba\n",
"output": "YES\n2 3\n"
},
{
... | code_contests | python | 0.5 | e4135095723a249bea775a903cb8b6ff |
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the st... | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = [len(str(i)) for i in a]
c = Counter(l)
cl = [c[i] for i in range(1,11)]
M = 998244353
pad = lambda a, d: a%d + (a - a%d) * 10
#print(a, l, c, cl)
ans = 0
for i in a:
il = len(str(i)) # let's calculate it again to avoid zi... | python | code_algorithm | [
{
"input": "3\n12 3 45\n",
"output": "12330\n"
},
{
"input": "2\n123 456\n",
"output": "1115598\n"
},
{
"input": "20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"output": "2178920\n"
},
{
"input": "100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587... | code_contests | python | 0 | d138b941c27c8a78ddb1fa1b00dbc7a4 |
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (... | t = int(input())
while t>0:
x, y, z = [int(i) for i in input().split()]
s = 0
f = -1
z = z//2
if y >= z:
y = y - z
s = z*2 + z
else:
s = y*2 + y
f = 1
if f == -1:
y = y//2
if x >= y:
s = s + 2*y + y
else:
... | python | code_algorithm | [
{
"input": "3\n3 4 5\n1 0 5\n5 3 2\n",
"output": "9\n0\n6\n"
},
{
"input": "20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"output": "12\n12\n9\n15\n9\n3\n6\n0\n15\n3\n18\n6\n12\n15\n6\n0\n6\... | code_contests | python | 0.9 | 11bd5b095c7852d588f6352f2cde64f2 |
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | from math import ceil
a,b,c = map(int,input().split())
t = (a*c - c*b)/b
print(ceil(t)) | python | code_algorithm | [
{
"input": "10 3 2\n",
"output": "5\n"
},
{
"input": "13 12 1\n",
"output": "1\n"
},
{
"input": "4 1 1\n",
"output": "3\n"
},
{
"input": "993 992 991\n",
"output": "1\n"
},
{
"input": "100 1 10\n",
"output": "990\n"
},
{
"input": "960 935 994\n",
"... | code_contests | python | 0.7 | a679fcb59e19003680c14ad792349658 |
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | from collections import deque
x0,y0,x1,y1=list(map(int, input().split()))
n=int(input())
allowed={}
for i in range(n):
r,a,b=list(map(int,input().split()))
for j in range(a,b+1):
allowed[(r,j)]=True
visited={}
q=deque()
q.append((x0,y0))
visited[(x0,y0)]=0
dire=[(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1)... | python | code_algorithm | [
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"output": "6\n"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10\n",
"output": "-1\n"
},
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"output": "4\n"
},
{
"input": "1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000... | code_contests | python | 1 | 712836a1862e6156852adaf7f970e8f2 |
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | n=int(input())
mat=[]
for i in range(n):
mat.append(list(map(int, input().rstrip().split())))
b=0
for i in range (n):
for j in range (n):
if mat[i][0]==mat[j][1]:
b=b+1
print(b) | python | code_algorithm | [
{
"input": "2\n1 2\n1 2\n",
"output": "0\n"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5\n",
"output": "5\n"
},
{
"input": "3\n1 2\n2 4\n3 4\n",
"output": "1\n"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 ... | code_contests | python | 0.9 | 6856140f736c50ed7a74342275c56b8d |
In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native ... | def f(x, p):
q = []
while x:
q.append(x)
x = p[x]
return q
from collections import defaultdict
n, k = map(int, input().split())
t = list(map(int, input().split()))
p = [0] * (n + 1)
for i, j in enumerate(t, 1):
p[j] = i
p = [f(i, p) for i, j in enumerate(t, 1) if j == 0]
s = defaultdict(... | python | code_algorithm | [
{
"input": "6 2\n2 3 0 5 6 0\n",
"output": "2\n5\n"
},
{
"input": "6 2\n0 0 1 0 4 5\n",
"output": "1\n3\n4\n6\n"
},
{
"input": "6 1\n2 0 4 0 6 0\n",
"output": "2\n4\n6\n"
},
{
"input": "4 1\n0 0 0 0\n",
"output": "1\n2\n3\n4\n"
},
{
"input": "20 20\n0 0 0 0 0 0 0 ... | code_contests | python | 0 | 02fafef8bf2a5af20c16a627b3eaa6e9 |
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | x=input()
x=x.replace("+","")
x=sorted(x)
for i in range(1,2*len(x)-1,2):
x.insert(i,"+")
x=''.join(x)
print(x)
| python | code_algorithm | [
{
"input": "2\n",
"output": "2\n"
},
{
"input": "3+2+1\n",
"output": "1+2+3\n"
},
{
"input": "1+1+3+1+3\n",
"output": "1+1+1+3+3\n"
},
{
"input": "2+2+1+1+3\n",
"output": "1+1+2+2+3\n"
},
{
"input": "3+1\n",
"output": "1+3\n"
},
{
"input": "1+3\n",
... | code_contests | python | 0.6 | a79dbccfed6866ed698ccd69f6cce0cc |
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... |
n, c = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
d = l[i] - l[i + 1] - c
ans = max(ans, d)
print(ans) | python | code_algorithm | [
{
"input": "6 2\n100 1 10 40 10 40\n",
"output": "97\n"
},
{
"input": "5 1\n5 10 7 3 20\n",
"output": "3\n"
},
{
"input": "3 0\n1 2 3\n",
"output": "0\n"
},
{
"input": "89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 1... | code_contests | python | 0.8 | 77f77afcb1f43ea21beae7271f03f47f |
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n = int(input())
a = list(input().split(' '))
a = list(int(x) for x in a)
one, two = 0, 0
for i in range(n):
if a[i] == 100:
one += 1
else:
two += 1
flag = False
if one%2 == 0 and two%2 == 0 or one > two and two % 2 == 1 and one % 2 == 0 and one >= 2 \
or one < two and two%2 == 1 and one%2 ==... | python | code_algorithm | [
{
"input": "4\n100 100 100 200\n",
"output": "NO\n"
},
{
"input": "3\n100 200 100\n",
"output": "YES\n"
},
{
"input": "9\n100 100 100 200 100 100 200 100 200\n",
"output": "YES\n"
},
{
"input": "3\n100 100 100\n",
"output": "NO\n"
},
{
"input": "7\n200 200 200 100... | code_contests | python | 0 | 314f29852d5a15fbec1cdcd15647cf04 |
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | l=list(map(int,input().split()))
x=sum(l)
if(x%5==0 and x!=0):
print(int(x/5))
else:
print(-1)
| python | code_algorithm | [
{
"input": "2 5 4 0 4\n",
"output": "3\n"
},
{
"input": "4 5 9 2 1\n",
"output": "-1\n"
},
{
"input": "99 100 100 100 100\n",
"output": "-1\n"
},
{
"input": "57 83 11 4 93\n",
"output": "-1\n"
},
{
"input": "99 99 99 99 99\n",
"output": "99\n"
},
{
"in... | code_contests | python | 0 | 870b964652b72b721ea8c97fd7230880 |
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | n,m=map(int,input().split())
weight=[int(i) for i in input().split()]
order=[int(i) for i in input().split()]
stack=[]
for i in order:
if i-1 not in stack:
stack.append(i-1)
#print(stack)
ans=0
for i in order:
#i=i-1
currlift=sum(weight[i] for i in stack[0:stack.index(i-1)])
ans+=currlift
t... | python | code_algorithm | [
{
"input": "3 5\n1 2 3\n1 3 2 3 1\n",
"output": "12\n"
},
{
"input": "50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 1... | code_contests | python | 0 | 631785cd01d3f196e97c38f1c89c7e18 |
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | import sys
n=0
ans=0
while True:
i=sys.stdin.readline().strip()
if len(i)<=1:
break
if i[0]=="+":
n+=1
elif i[0]=="-":
n-=1
else:
ans+=(len(i.split(':')[1]))*n
print(ans) | python | code_algorithm | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"output": "9\n"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"output": "14\n"
},
{
"input": "+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",... | code_contests | python | 0.7 | d40d60fad065760457d67fe7900e621e |
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | from decimal import *
getcontext().prec = 700
x, y, z = map(Decimal, input().split())
a = []
a.append((y**z * x.ln(), -1, 'x^y^z'))
a.append((z**y * x.ln(), -2, 'x^z^y'))
a.append((y *z * x.ln(), -3, '(x^y)^z'))
a.append((x**z * y.ln(), -5, 'y^x^z'))
a.append((z**x * y.ln(), -6, 'y^z^x'))
a.append((x *z * y.ln(), -7... | python | code_algorithm | [
{
"input": "1.1 3.4 2.5\n",
"output": "z^y^x\n"
},
{
"input": "1.9 1.8 1.7\n",
"output": "(x^y)^z\n"
},
{
"input": "2.0 2.0 2.0\n",
"output": "x^y^z\n"
},
{
"input": "1.0 200.0 200.0\n",
"output": "y^z^x\n"
},
{
"input": "0.2 0.1 0.6\n",
"output": "(z^x)^y\n"
... | code_contests | python | 0 | d352bcb72cfc92d2a52cc8b9f27fca3c |
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | # Question B. Road to Cinema
import sys
def roadToCinema(V, S, T, stations): # O(M)
"""
V : volume of fuel tank
S : total distance
T : time limit
stations: fuel stations' locations
rtype : boolean, whether this aircraft can travel within the time limit
"""
m = len(s... | python | code_algorithm | [
{
"input": "3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"output": "10\n"
},
{
"input": "2 2 10 18\n10 4\n20 6\n5 3\n",
"output": "20\n"
},
{
"input": "1 1 2 2\n1000000000 1000000000\n1\n",
"output": "1000000000\n"
},
{
"input": "1 1 1000000000 1000000000\n100 1000000000\n1\n",
"outp... | code_contests | python | 0 | e39114b2595b4681b39de8ba822556e6 |
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.... | ax,ay,bx,by,cx,cy=map(int,input().split())
ab=(ax-bx)**2+(ay-by)**2
bc=(bx-cx)**2+(by-cy)**2
if ab==bc and (ay-by)*(bx-cx)!=(by-cy)*(ax-bx):
print("Yes")
else:
print("No")
| python | code_algorithm | [
{
"input": "0 1 1 1 1 0\n",
"output": "Yes\n"
},
{
"input": "1 1 0 0 1000 1000\n",
"output": "No\n"
},
{
"input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"output": "No\n"
},
{
"input": "-357531221 381512519 -761132895 -224448284 328888775 -23769256... | code_contests | python | 0 | 0c03fcbcee368ac977a7ce492572f050 |
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | n = int(input())
k = str(input())
Max = 0
for i in range(n-1):
t=k[i]+k[i+1]
z=0
for j in range(0,n-1):
s=k[j]+k[j+1]
if (s==t):
z=z+1
#print(z)
if (z>Max):
Max=z
res=t
print(res)
| python | code_algorithm | [
{
"input": "5\nZZZAA\n",
"output": "ZZ\n"
},
{
"input": "7\nABACABA\n",
"output": "AB\n"
},
{
"input": "15\nMIRZOYANOVECLOX\n",
"output": "MI\n"
},
{
"input": "23\nAABBBAAACCCCCAAADDDDDDD\n",
"output": "DD\n"
},
{
"input": "2\nQA\n",
"output": "QA\n"
},
{
... | code_contests | python | 0.8 | 34ebe58ccb7f677dc24053d7fed7d930 |
You are given an array a of n integers and an integer s. It is guaranteed that n is odd.
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s.
The median of the array with odd length is the ... |
# -*- coding: utf-8 -*-
# @Date : 2018-09-03 08:46:01
# @Author : raj lath (oorja.halt@gmail.com)
# @Link : http://codeforces.com/contest/1037/problem/B
# @Version : 1.0.0
import os
from sys import stdin
max_val=int(10e12)
min_val=int(-10e12)
def read_int() : return int(stdin.readline())
def read_ints() ... | python | code_algorithm | [
{
"input": "3 8\n6 5 8\n",
"output": "2\n"
},
{
"input": "7 20\n21 15 12 11 20 19 12\n",
"output": "6\n"
},
{
"input": "3 1\n1 2 5\n",
"output": "1\n"
},
{
"input": "1 1\n100000\n",
"output": "99999\n"
},
{
"input": "5 1\n2 2 4 6 1\n",
"output": "2\n"
},
{... | code_contests | python | 0.8 | 9b4125140c001e5e312fb9553932447c |
During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
The Word of Uni... | n, q = map(int, input().split())
s = '!' + input()
nxt = [[n + 1] * (n + 2) for _ in range(26)]
for i in range(n - 1, -1, -1):
c = ord(s[i + 1]) - 97
for j in range(26):
nxt[j][i] = nxt[j][i + 1]
nxt[c][i] = i + 1
w = [[-1], [-1], [-1]]
idx = lambda i, j, k: i * 65536 + j * 256 + k
dp = [0] * (256... | python | code_algorithm | [
{
"input": "6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n"
},
{
"input": "6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n",
"output": "YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\n"
},
{
"input": "1 1... | code_contests | python | 0.1 | f3c2e281794c84ed2e9de8c091552d81 |
Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) ⊕ f(n-2) when n > 1, where ⊕ de... | import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations ,product
def eprint(*args):
print(*args, file=sys.stderr... | python | code_algorithm | [
{
"input": "3\n3 4 2\n4 5 0\n325 265 1231232\n",
"output": "7\n4\n76\n"
},
{
"input": "10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 97427529... | code_contests | python | 1 | ead41a2101393248e3091fd80df4afcf |
Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], …, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l ≤ x ≤ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (inters... | t = int(input())
for i in range(t):
n = int(input())
x = []
y = []
for i in range(n):
a, b = map(int, input().split())
x.append(a)
y.append(b)
if n == 1:
print(0)
elif min(y) > max(x):
print(0)
else:
print(abs(max(x)-min(y)))
| python | code_algorithm | [
{
"input": "4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n",
"output": "2\n4\n0\n0\n"
},
{
"input": "1\n2\n999999997 999999998\n999999999 1000000000\n",
"output": "1\n"
},
{
"input": "4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888... | code_contests | python | 0 | 081e1bb10a3a6af36f767e0dd0993de2 |
Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional de... | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)]... | python | code_algorithm | [
{
"input": "3 3\n1 3\n2 3\n3 3\n",
"output": "1\n"
},
{
"input": "3 1\n1 1\n2 2\n3 3\n",
"output": "3\n"
},
{
"input": "7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"output": "9\n"
},
{
"input": "3 2\n1 1\n2 2\n3 3\n",
"output": "0\n"
},
{
"input": "5 2\n1 3\n2 4\n... | code_contests | python | 0 | 7a00a6a5817a072c86bce014cef6676d |
In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by... | def solve(a, b):
if a == 0:
return False
if solve(b % a, a):
b //= a
return not (b % (a + 1) & 1)
return True
n = int(input())
for _ in range(n):
a, b = [int(x) for x in input().split()]
if a > b:
a, b = b, a
if solve(a, b):
print("First")
else:
... | python | code_algorithm | [
{
"input": "4\n10 21\n31 10\n0 1\n10 30\n",
"output": "First\nSecond\nSecond\nFirst\n"
},
{
"input": "7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"output": "First\nSecond\nSecond\nFirst\nSecond\nSecond\nFirst\n"
},
{
"input": "1\n128817972817282999 32767241099463... | code_contests | python | 0 | 5e1110e6b5aed3daded7947d4dae6986 |
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find th... | import sys, math
input = sys.stdin.readline
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
import collections as col
import math
def s... | python | code_algorithm | [
{
"input": "7\n",
"output": "210\n"
},
{
"input": "9\n",
"output": "504\n"
},
{
"input": "447244\n",
"output": "89460162932862372\n"
},
{
"input": "958507\n",
"output": "880611813728059710\n"
},
{
"input": "816923\n",
"output": "545182335484592526\n"
},
{
... | code_contests | python | 0.2 | 1fb05147342d93ed108355cdf76a271b |
Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next n days. Polycarpus knows that he is in for w good events and b not-so-good events. At least one event is going to ta... | import sys
MOD = int(1e9) + 9
def inv(n):
return pow(n, MOD - 2, MOD)
def combo(n):
rv = [0 for __ in range(n + 1)]
rv[0] = 1
for k in range(n):
rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD
return rv
with sys.stdin as fin, sys.stdout as fout:
n, w, b = map(int, next(fin).spl... | python | code_algorithm | [
{
"input": "3 2 1\n",
"output": "2\n"
},
{
"input": "3 2 2\n",
"output": "4\n"
},
{
"input": "4 2 2\n",
"output": "4\n"
},
{
"input": "3 3 1\n",
"output": "12\n"
},
{
"input": "300 2 300\n",
"output": "775907030\n"
},
{
"input": "4000 4000 1\n",
"o... | code_contests | python | 0 | b88ed47235cb6bc5d32717d52efca784 |
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:
<image>
A swap operation is the following sequence of actions:
* choose two indexes i, j (i ≠ j);
* perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp.
What maximum value of function m(a) can Serej... | #!/usr/local/bin/python3
n, k = map(int, input().split())
a = list(map(int, input().split()))
r_sum = a[0]
for l in range(n):
for r in range(l, n):
inside = sorted(a[l:r+1])
outside = sorted(a[:l] + a[r+1:], reverse=True)
t_sum = sum(inside)
for i in range(min(k, len(inside), len(outside))):
if outside[i] >... | python | code_algorithm | [
{
"input": "5 10\n-1 -1 -1 -1 -1\n",
"output": "-1\n"
},
{
"input": "10 2\n10 -1 2 2 2 2 2 2 -1 10\n",
"output": "32\n"
},
{
"input": "1 10\n1\n",
"output": "1\n"
},
{
"input": "10 1\n-1 1 1 1 1 1 1 1 1 1\n",
"output": "9\n"
},
{
"input": "78 8\n-230 -757 673 -284... | code_contests | python | 0 | 4e28af37251e287e92d4187c7dcc5496 |
Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k.
Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and print this number modulo 1000000007 (109 + 7). Operation x & y deno... | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
# zeta mebius
def zeta_super(val, n):
# len(val)==2^n
out = val[:]
for i in rang... | python | code_algorithm | [
{
"input": "3\n2 3 3\n",
"output": "0\n"
},
{
"input": "4\n0 1 2 3\n",
"output": "10\n"
},
{
"input": "6\n5 2 0 5 2 1\n",
"output": "53\n"
},
{
"input": "2\n1 31\n",
"output": "0\n"
},
{
"input": "2\n1 0\n",
"output": "2\n"
},
{
"input": "10\n450661 12... | code_contests | python | 0 | 57537d17a127580feeea040c3aeb98c4 |
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the ... | #!/usr/bin/env python3
s = input()
count = 0
res = []
last = s.rfind("#")
for i, c in enumerate(s):
if c == '(':
count += 1
elif c == ')':
count -= 1
else:
if i < last:
res.append(1)
count -= 1
else:
num = max(1, 1 + s.count("(") - s.coun... | python | code_algorithm | [
{
"input": "(((#)((#)\n",
"output": "1\n2\n"
},
{
"input": "#\n",
"output": "-1\n"
},
{
"input": "()((#((#(#()\n",
"output": "1\n1\n3\n"
},
{
"input": "(#)\n",
"output": "-1\n"
},
{
"input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#... | code_contests | python | 0 | e6f6a82197f0cbe529b2ba93244ed8aa |
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.
You need to permute the array elements so that value
<image> became minimal possible. In particular, it is allowed not to change order of elements at all.
Input
The first line contains two integers n,... | f = lambda: map(int, input().split())
n, k = f()
p = sorted(f())
m, d = n // k, n % k
u, v = d + 1, k - d + 1
g = [0] * u * v
i = 0
for a in range(u):
j = a * m + a - 1
for b in range(v):
x = g[i - 1] + p[j] - p[j - m + 1] if b else 9e9
y = g[i - v] + p[j] - p[j - m] if a else 9e9
if i... | python | code_algorithm | [
{
"input": "5 2\n3 -5 3 -5 3\n",
"output": "0\n"
},
{
"input": "3 2\n1 2 4\n",
"output": "1\n"
},
{
"input": "6 3\n4 3 4 3 2 5\n",
"output": "3\n"
},
{
"input": "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -99999996... | code_contests | python | 0 | 7a67b08d4c68ca0e1543d429ce6e913c |
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collected n requests from clients. The requests are numbered from 1 to n in order... | t, p = 1, []
for i in range(int(input())):
l, d = map(int, input().split())
if t > l:
for i, q in enumerate(p, 1):
if q[0] <= l <= q[1] - d:
p.insert(i, [l + d, q[1]])
q[1] = l
break
else:
for q in p:
if q[0]... | python | code_algorithm | [
{
"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n",
"output": "1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000\n"
},
{
"input": "3\n9 2\n7 3\n2 4\n",
"output": "9 10\n1 3\n4 7\n"
},
{
"input": "1\n1 5000000\n",
"outp... | code_contests | python | 0.8 | fa2e923ed627edae953d5d8a390d09e2 |
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making... | from sys import exit
l1 = input()
l2 = input()
l3 = input()
l4 = input()
grid = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]
cross = 0
dots = []
for i in range(0, 4):
if l1[i] == ".":
dots += [[0+2, i+2]]
eli... | python | code_algorithm | [
{
"input": "o.x.\no...\n.x..\nooxx\n",
"output": "NO\n"
},
{
"input": "x.ox\nox..\nx.o.\noo.x\n",
"output": "NO\n"
},
{
"input": "xx..\n.oo.\nx...\noox.\n",
"output": "YES\n"
},
{
"input": "x..x\n..oo\no...\nx.xo\n",
"output": "YES\n"
},
{
"input": "xoox\n.xx.\no.... | code_contests | python | 0.2 | 33058d1f1164c23bc904e4e8a20ad093 |
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".
Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe... | import math
from sys import stdin, stdout
fin = stdin
fout = stdout
n = int(fin.readline().strip())
s = fin.readline().strip()
ans = []
gl = frozenset({'a', 'e', 'i', 'y', 'o', 'u'})
met = False
cdel = False
for i in range(n):
if i > 0:
if s[i] != s[i - 1]:
met = False
cdel = Fa... | python | code_algorithm | [
{
"input": "18\naeiouyaaeeiioouuyy\n",
"output": "aeiouyaeeioouy"
},
{
"input": "22\niiiimpleeemeentatiioon\n",
"output": "implemeentatioon"
},
{
"input": "13\npobeeeedaaaaa\n",
"output": "pobeda"
},
{
"input": "24\naaaoooiiiuuuyyyeeeggghhh\n",
"output": "aoiuyeggghhh"
... | code_contests | python | 0.9 | f2a784529a71cc9bfcd5341404f359b9 |
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second —... | c,v0,v1,a,l = list(map(int, input().split(" ")))
count=1
sum=v0
while sum<c:
sum+=min(v0+count*a-l,v1-l)
count+=1
print(count) | python | code_algorithm | [
{
"input": "5 5 10 5 4\n",
"output": "1\n"
},
{
"input": "12 4 12 4 1\n",
"output": "3\n"
},
{
"input": "15 1 100 0 0\n",
"output": "15\n"
},
{
"input": "10 1 4 10 0\n",
"output": "4\n"
},
{
"input": "100 1 2 1000 0\n",
"output": "51\n"
},
{
"input": "... | code_contests | python | 0.5 | 3fef77d667a50986a5920873c6b8832a |
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving s... | n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
res = 0
for x in range(min(m//sum(t),n)+1):
rem = m - x*sum(t)
r = x*(k+1)
for i in range(k):
div = min(rem//t[i], n-x)
rem -= div*t[i]
r += div
res = max(res, r)
print(res) | python | code_algorithm | [
{
"input": "5 5 10\n1 2 4 8 16\n",
"output": "7\n"
},
{
"input": "3 4 11\n1 2 3 4\n",
"output": "6\n"
},
{
"input": "1 3 0\n6 3 4\n",
"output": "0\n"
},
{
"input": "5 4 32\n4 2 1 1\n",
"output": "21\n"
},
{
"input": "32 6 635\n3 4 2 1 7 7\n",
"output": "195\n"... | code_contests | python | 0 | 1788295961ff6f78187ea302c9d62884 |
Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
... | num=int(input())
spectator=3
p1=1
p2=2
yes=True
for i in range(0,num):
winner=int(input())
if winner is spectator:
print("NO")
yes=False
break
if p1 is winner:
temp=spectator
spectator=p2
p2=temp
else:
temp=spectator
spectator=p1
p1... | python | code_algorithm | [
{
"input": "2\n1\n2\n",
"output": "NO\n"
},
{
"input": "3\n1\n1\n2\n",
"output": "YES\n"
},
{
"input": "99\n1\n3\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n1\n1\n3\n3\n3\n3\n1\n1\n3\n2\n1\n1\n1\n1\n1\n1\n1\n3\n2\n2\n2\n1\n3\n3\n1\n1\n3\n2\n1\n3\n3\n1\n2\n3\n3\n3\n1\n2\n2\n2\n3\n3\n3\n3\n3\n3\n2\n... | code_contests | python | 0.4 | 3ca8ffd72b460486dfec02ef38958088 |
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have n bacteria in the Petri dish and size of the i-th bacteria is a_i. Also you know intergalactic positive integer constan... | n, m = map(int, input().split())
l = sorted(map(int, input().split()))
t, b = l[::-1], -m
for a in l:
while b < a:
if a <= b + m:
n -= 1
b = t.pop()
print(n) | python | code_algorithm | [
{
"input": "6 5\n20 15 10 15 20 25\n",
"output": "1\n"
},
{
"input": "7 1\n101 53 42 102 101 55 54\n",
"output": "3\n"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1\n",
"output": "7\n"
},
{
"input": "2 1\n1 1\n",
"output": "2\n"
},
{
"input": "4 1\n2 2 1 1\n",
"outp... | code_contests | python | 0 | 578445173ad94b5b55293f965b87316e |
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10... | #Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threadi... | python | code_algorithm | [
{
"input": "4\n1 2 1 16\n",
"output": "4\n"
},
{
"input": "3\n6 7 14\n",
"output": "2\n"
},
{
"input": "5\n1000000000000000000 352839520853234088 175235832528365792 753467583475385837 895062156280564685\n",
"output": "3\n"
},
{
"input": "1\n15\n",
"output": "0\n"
},
{... | code_contests | python | 0 | f1e9d4d5f2555f6360641c1fbd2208ea |
Hasan loves playing games and has recently discovered a game called TopScore. In this soccer-like game there are p players doing penalty shoot-outs. Winner is the one who scores the most. In case of ties, one of the top-scorers will be declared as the winner randomly with equal probability.
They have just finished the... | base=998244353;
def power(x, y):
if(y==0):
return 1
t=power(x, y//2)
t=(t*t)%base
if(y%2):
t=(t*x)%base
return t;
def inverse(x):
return power(x, base-2)
f=[1]
iv=[1]
for i in range(1, 5555):
f.append((f[i-1]*i)%base)
iv.append(inverse(f[i]))
def C(n, k):
return (f[n]... | python | code_algorithm | [
{
"input": "10 30 10\n",
"output": "85932500\n"
},
{
"input": "2 6 3\n",
"output": "124780545\n"
},
{
"input": "5 20 11\n",
"output": "1\n"
},
{
"input": "1 5000 4999\n",
"output": "1\n"
},
{
"input": "2 1 0\n",
"output": "499122177\n"
},
{
"input": "8... | code_contests | python | 0 | a65e456f1ef25dec74b855200e2bc64a |
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its... | n=int(input())
arr=list(map(int,input().split()))
arr.sort()
even=[]
odd=[]
e=0
o=0
for i in arr:
if (i%2)==0:
even=even+[i]
e=e+1
else:
odd=odd+[i]
o=o+1
if (e>o) and (e-o)>1:
print(sum(even[:(e-o-1)]))
elif (o>e) and (o-e)>1:
print(sum(odd[:(o-e-1)]))
else:
print(0)
| python | code_algorithm | [
{
"input": "2\n1000000 1000000\n",
"output": "1000000\n"
},
{
"input": "6\n5 1 2 4 6 3\n",
"output": "0\n"
},
{
"input": "5\n1 5 7 8 2\n",
"output": "0\n"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "4\n"
},
{
"input": "5\n2 1 1 1 1\n",
"output": "2\n"
}
] | code_contests | python | 0 | 9e08daa2a0a67298f818aac46bd53156 |
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.
You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0... | n,x,y = map(int,input().split())
s = input()[-x:]
if(y == 0):
num = s[:-(y+1)].count('1')
else:
num = s[:-(y+1)].count('1') + s[-y:].count('1')
if(s[-(y+1)] == "0"):
num = num + 1
print(num) | python | code_algorithm | [
{
"input": "11 5 2\n11010100101\n",
"output": "1\n"
},
{
"input": "11 5 1\n11010100101\n",
"output": "3\n"
},
{
"input": "6 4 2\n100010\n",
"output": "2\n"
},
{
"input": "4 2 1\n1000\n",
"output": "1\n"
},
{
"input": "8 5 2\n10000100\n",
"output": "0\n"
},
... | code_contests | python | 0.6 | 0fbda6c6973f4d087722fc0d0046364d |
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ... | import sys
from sys import argv
def extendedEuclideanAlgorithm(old_r, r):
negative = False
s, old_t = 0, 0
old_s, t = 1, 1
if (r < 0):
r = abs(r)
negative = True
while r > 0:
q = old_r // r
#MCD:
r, old_r = old_r - q * r, r
#Coeficiente s:
... | python | code_algorithm | [
{
"input": "30 60 3 1\n",
"output": "20 0 10\n"
},
{
"input": "20 0 15 5\n",
"output": "0 0 20\n"
},
{
"input": "10 51 5 4\n",
"output": "-1\n"
},
{
"input": "728961319347 33282698448966372 52437 42819\n",
"output": "634717821311 1235 94243496801\n"
},
{
"input": ... | code_contests | python | 0 | 366b7e5df64c01f0987bdd8decc6b07b |
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers.
LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6.
O... | def LMC(a, b):
n = a * b
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
nod = a + b
nok = n // nod
return nok
from math import sqrt, ceil
n = int(input())
dividers = []
for i in range(1, ceil(sqrt(n))):
if n % i == 0:
dividers.appe... | python | code_algorithm | [
{
"input": "1\n",
"output": "1 1\n"
},
{
"input": "4\n",
"output": "1 4\n"
},
{
"input": "6\n",
"output": "2 3\n"
},
{
"input": "2\n",
"output": "1 2\n"
},
{
"input": "205078485761\n",
"output": "185921 1103041\n"
},
{
"input": "873109054817\n",
"o... | code_contests | python | 0.2 | 9bb2088fd1bdf53d5f78466f91c0b497 |
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Consider a permutation p of length ... | n = int(input())
M = 10**9+7
fact = [1]*(n+2)
for i in range(2, n+1):
fact[i] = (i*fact[i-1])%M
print(((fact[n]-pow(2, n-1, M))+M)%M) | python | code_algorithm | [
{
"input": "4\n",
"output": "16\n"
},
{
"input": "583291\n",
"output": "135712853\n"
},
{
"input": "66\n",
"output": "257415584\n"
},
{
"input": "652615\n",
"output": "960319213\n"
},
{
"input": "482331\n",
"output": "722928541\n"
},
{
"input": "336161... | code_contests | python | 0.6 | d731152dbb21da1a61688b8d7db6de88 |
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner.
Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep... | def findmin(lcopy, toexceed):
toex = ord(toexceed) - 97
for each in lcopy[(toex+1):]:
if each > 0:
return True
return False
def arrange(lcopy, toexceed = None):
if toexceed is None:
ans = ""
for i in range(26):
ans += chr(i+97)*lcopy[i]
return ans... | python | code_algorithm | [
{
"input": "abc\ndefg\n",
"output": "-1\n"
},
{
"input": "czaaab\nabcdef\n",
"output": "abczaa\n"
},
{
"input": "aad\naac\n",
"output": "aad\n"
},
{
"input": "abad\nbob\n",
"output": "daab\n"
},
{
"input": "z\na\n",
"output": "z\n"
},
{
"input": "abc\n... | code_contests | python | 0 | 90f5cfc13cd3084cde9a471b1551f83d |
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ... | # mafia
N=int(input())
a=list(map(int,input().split()))
def isok(X):
sums=0
for num in a:
if X<num:
return False
sums+=max(0,X-num)
if sums>=X:
return True
return False
l=0
r=10**12
#l -- case_impossible
#r --case_possible
while r-l>1:
m=(l+r)//2
... | python | code_algorithm | [
{
"input": "3\n3 2 2\n",
"output": "4\n"
},
{
"input": "4\n2 2 2 2\n",
"output": "3\n"
},
{
"input": "3\n1000000000 1000000000 10000000\n",
"output": "1005000000\n"
},
{
"input": "3\n1 2 1\n",
"output": "2\n"
},
{
"input": "3\n4 10 11\n",
"output": "13\n"
},... | code_contests | python | 0.5 | 6a77d1086f7edd900b13137b7ec52c9e |
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox... | from math import pow
def take_input(s): #for integer inputs
if s == 1: return int(input())
return map(int, input().split())
def factor(n,k):
i = 0
while(n%k==0):
i += 1
n //= k
return i
a, b = take_input(2)
count = 0
if a == b:
print(0)
exit()
a_fac_2 = f... | python | code_algorithm | [
{
"input": "15 20\n",
"output": "3\n"
},
{
"input": "14 8\n",
"output": "-1\n"
},
{
"input": "6 6\n",
"output": "0\n"
},
{
"input": "919536000 993098880\n",
"output": "5\n"
},
{
"input": "691200 583200\n",
"output": "8\n"
},
{
"input": "5 1000000000\n"... | code_contests | python | 0.3 | be2cccaa9a99c8cc4735c73a4d714881 |
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:
1. They are equal.
2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2... | def equals(a, b):
if (a == b):
return True
len_a, len_b = len(a), len(b)
if (len_a & 1 or len_b & 1):
return False
if (len_a == 1):
return False
as1 = a[0:len_a//2]
as2 = a[len_a//2:(len_a//2)*2]
bs1 = b[:len_b//2]
bs2 = b[len_b//2:(len_b//2)*2]
return (equals(as1, bs2) and equals... | python | code_algorithm | [
{
"input": "aaba\nabaa\n",
"output": "YES\n"
},
{
"input": "aabb\nabab\n",
"output": "NO\n"
},
{
"input": "aabbaaaa\naaaaabab\n",
"output": "NO\n"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa\n",
"output": "NO\n"
},
{
"input": "abcddd\nbacddd\n",
"output": "NO\... | code_contests | python | 0.9 | 96aa8b635b79c4c7de25e2e50ee3fffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.