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
One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: a1, a2, ..., an → an, a1, a2, ..., an - 1. Help Twi...
def us_num(nums): where = None for idx, (a, na) in enumerate(zip(nums[:-1], nums[1:])): if a > na: if where is None: where = idx else: return -1 if where is None: return 0 elif nums[-1] > nums[0]: return -1 return len(nums) - 1 - where n = int(input()) nums = list(map(...
python
code_algorithm
[ { "input": "3\n1 3 2\n", "output": "-1\n" }, { "input": "2\n1 2\n", "output": "0\n" }, { "input": "2\n2 1\n", "output": "1\n" }, { "input": "6\n5 6 7 5 5 5\n", "output": "3\n" }, { "input": "5\n1 1 2 1 1\n", "output": "2\n" }, { "input": "7\n2 3 4 1 2 ...
code_contests
python
0.5
b26977e1cd9d8a4eae5daed81e8afdc4
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Bi...
x=int(input()) y=x-2 if y%2==0 and y!=0: print("YES") else : print("NO")
python
code_algorithm
[ { "input": "8\n", "output": "YES\n" }, { "input": "3\n", "output": "NO\n" }, { "input": "98\n", "output": "YES\n" }, { "input": "7\n", "output": "NO\n" }, { "input": "90\n", "output": "YES\n" }, { "input": "67\n", "output": "NO\n" }, { "inp...
code_contests
python
0.4
8203a469d9921ed6166cb8286ad286d6
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters. Output Print "YES" (without the quot...
a = input() b = a f1=0 f2=0 if(a.find('AB')!=-1): a = a.replace('AB', 'C', 1) if(a.find('BA')!=-1): f1=1 if(b.find('BA')!=-1): b = b.replace('BA', 'C', 1) if(b.find('AB')!=-1): f2=1 if(f1==0 and f2==0): print("NO") else: print("YES")
python
code_algorithm
[ { "input": "ABA\n", "output": "NO\n" }, { "input": "AXBYBXA\n", "output": "NO\n" }, { "input": "BACFAB\n", "output": "YES\n" }, { "input": "BAAA\n", "output": "NO\n" }, { "input": "BAA\n", "output": "NO\n" }, { "input": "ABABA\n", "output": "YES\n"...
code_contests
python
0.2
d2a64e9fa4cfd553fdd3b3f6ac1af7d6
You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m. Input The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and ...
n,x=map(int,input().split()) a=set() for i in input().split(): i=int(i) b=set() for j in a: b.add((i+j)%x) a|=b a.add(i%x) if 0 in a: print("YES") break else: print("NO")
python
code_algorithm
[ { "input": "4 6\n3 1 1 3\n", "output": "YES\n" }, { "input": "1 6\n5\n", "output": "NO\n" }, { "input": "6 6\n5 5 5 5 5 5\n", "output": "YES\n" }, { "input": "3 5\n1 2 3\n", "output": "YES\n" }, { "input": "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 ...
code_contests
python
0.1
570c8ac6b27439167d011cf567e22a78
Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger. But h...
n= int(input()) if(n<=127): print("byte") elif(n<=32767): print("short") elif(n<=2147483647): print("int") elif(n<=9223372036854775807): print("long") else: print("BigInteger")
python
code_algorithm
[ { "input": "123456789101112131415161718192021222324\n", "output": "BigInteger\n" }, { "input": "127\n", "output": "byte\n" }, { "input": "130\n", "output": "short\n" }, { "input": "73301058161399915972677875815320924081350034292596169552397613159508055212649940212428739793091...
code_contests
python
0.5
3af36abdfc5f69d1ce7bdf8c158640b2
Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (...
n = int(input()) a = [0]*(n+1) for _ in range(n-1): x, y = input().split(' ') x, y = [int(x), int(y)] a[x] += 1 a[y] += 1 too = 0 for x in a: too += (x * (x-1))//2 print(too)
python
code_algorithm
[ { "input": "4\n1 2\n1 3\n1 4\n", "output": "3\n" }, { "input": "5\n1 2\n2 3\n3 4\n3 5\n", "output": "4\n" }, { "input": "2\n1 2\n", "output": "0\n" }, { "input": "3\n2 1\n3 2\n", "output": "1\n" }, { "input": "10\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4\n", ...
code_contests
python
1
eb43966a8926282f134e5e2bf46c7150
Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no m...
def main(): n, k = map(int, input().split()) cnt = [[[0] * 21 for _ in (0, 1)] for _ in range(n + 1)] edges, mod = [[] for _ in range(n + 1)], 1000000007 for _ in range(n - 1): u, v = map(int, input().split()) edges[u].append(v) edges[v].append(u) def dfs(u, f): cnt[...
python
code_algorithm
[ { "input": "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "output": "91\n" }, { "input": "4 1\n1 2\n2 3\n3 4\n", "output": "9\n" }, { "input": "2 0\n1 2\n", "output": "1\n" }, { "input": "2 1\n1 2\n", "output": "3\n" }, { "input": "10 1\n6 3\n1 5\n10 7\n4 10\n2 4\n5 9\n8 ...
code_contests
python
0
90b79d03b24efa117cb5a7aff676dd2c
Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two wo...
from collections import defaultdict names = int(input()) inp = [input().split() for x in range(names)] choice = [] res = defaultdict(lambda: []) for x, word in enumerate(inp): choice.append(False) res[word[0][:3]].append(x) while True: changes = [] for key in res.keys(): if len(res[key]) > 1: ...
python
code_algorithm
[ { "input": "3\nABC DEF\nABC EFG\nABD OOO\n", "output": "YES\nABD\nABE\nABO\n" }, { "input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW\n", "output": "YES\nDIN\nFOO\n" }, { "input": "3\nPLAYFOOTBALL MOSCOW\nPLAYVOLLEYBALL SPB\nGOGO TECHNOCUP\n", "output": "YES\nPLM\nPLS\nGOG\n" }, { ...
code_contests
python
0
bb8e12eacea1677f579848f9d1c2afc4
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j co...
n = int(input()) print(int((n + 1) / 2) - 1)
python
code_algorithm
[ { "input": "10\n", "output": "4\n" }, { "input": "2\n", "output": "0\n" }, { "input": "60397\n", "output": "30198\n" }, { "input": "53022\n", "output": "26510\n" }, { "input": "32866\n", "output": "16432\n" }, { "input": "40873\n", "output": "20436...
code_contests
python
0.5
cc3d4c932cfcff678a133c260e7a65ee
Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and anno...
import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int...
python
code_algorithm
[ { "input": "8192\n", "output": "8191\n" }, { "input": "20\n", "output": "15\n" }, { "input": "14\n", "output": "6\n" }, { "input": "12\n", "output": "6\n" }, { "input": "908209\n", "output": "453632\n" }, { "input": "999958\n", "output": "250008\n"...
code_contests
python
0
31635fa6c218bad54a657ac09cedf17c
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e...
import sys n,m,k=map(int,input().split()) if(k<n): print(k+1,1) sys.exit() k-=n x=n-(k)//(m-1) if(x%2==0): y=k%(m-1)+2 else: y=m-k%(m-1) print(x,y)
python
code_algorithm
[ { "input": "4 3 0\n", "output": "1 1\n" }, { "input": "4 3 7\n", "output": "3 2\n" }, { "input": "4 3 11\n", "output": "1 2\n" }, { "input": "9213788 21936127 8761236\n", "output": "8761237 1\n" }, { "input": "2182 23967 52288026\n", "output": "1 7969\n" }, ...
code_contests
python
0
4adf07184def5795c5d8632ce76140b5
Recently Vasya found a golden ticket — a sequence which consists of n digits a_1a_2... a_n. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 is lucky since it can be divided into three segments 350, 17 and 8: 3+5+0=1+7=8. No...
n = int(input()) s = input() arr = list() arr.append(int(s[0])) summ = arr[0] bigflg = False for i in range(1,len(s)): arr.append(int(s[i])) summ+=arr[i] for i in range(2,len(s)+1): if summ % i == 0: amount = summ / i sm = 0 flg = True for j in range(len(arr)): sm...
python
code_algorithm
[ { "input": "4\n1248\n", "output": "NO\n" }, { "input": "5\n73452\n", "output": "YES\n" }, { "input": "7\n5541514\n", "output": "YES\n" }, { "input": "20\n69325921242281090228\n", "output": "NO\n" }, { "input": "3\n222\n", "output": "YES\n" }, { "input"...
code_contests
python
0.4
db2f3897a9a3d45bbb9591cfab740099
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x = 0. Mezo starts sending n commands to Zoma. There are two possible commands: * 'L' (Left) sets the position x: =x - 1; * 'R' (Right) sets the position x: =x + 1. Unfortunately, Mezo's controller malfunctions sometimes. ...
def func(n): x = input() ans = 0 l_counter = x.count('L') r_counter = x.count('R') y = 0 - l_counter z = 0 + r_counter for i in range(y,z+1): ans += 1 print(ans) n = int(input()) func(n)
python
code_algorithm
[ { "input": "4\nLRLR\n", "output": "5\n" }, { "input": "12\nLLLLLLLLLLLL\n", "output": "13\n" }, { "input": "2\nLR\n", "output": "3\n" }, { "input": "1\nR\n", "output": "2\n" }, { "input": "13\nLRLLLLRRLLRLR\n", "output": "14\n" }, { "input": "1\nL\n", ...
code_contests
python
0.9
9aa45e0939896c25d8f257c8ad842659
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). For a positive integer n, we call a...
import sys input = sys.stdin.readline from collections import * for _ in range(int(input())): n = int(input()) print(*[i for i in range(1, n+1)])
python
code_algorithm
[ { "input": "3\n1\n3\n7\n", "output": "1\n1 2 3\n1 2 3 4 5 6 7\n" }, { "input": "1\n77\n", "output": "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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 ...
code_contests
python
0
662b50e8191597219b6fd97f824fbc5a
One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, ...
mod=10**9+7 n,m=map(int,input().split()) mat=[] for _ in range(n): s=input() mat.append(s) b=ord("A") s=[False]*255 res=1 for j in range(m): for i in range(b,b+26): s[i]=False for i in range(n): s[ord(mat[i][j])]=True r=0 for i in range(b,b+26): if(s[i]):r+=1 res*=r print(res%mod)
python
code_algorithm
[ { "input": "2 3\nAAB\nBAA\n", "output": "4\n" }, { "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n", "output": "216\n" }, { "input": "100 1\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI\nJ\nK\nL\nM\nN\nA\nB\nC\nD\nE\nF\nG\nH\nI...
code_contests
python
0.9
9a208a9dd693293a689761984dd56b0c
Vasya studies divisibility rules at school. Here are some of them: * Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even. * Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3. * Divisibility by ...
b, d = map(int, input().split()) for i in range(1, 10): if (b**i) % d == 0: print("2-type") print(i) exit() if (b-1) % d == 0: print("3-type") exit() if (b+1) % d == 0: print("11-type") exit() for i in range(2, d+1): if d % i == 0: x = 1 while d % i == 0: ...
python
code_algorithm
[ { "input": "2 3\n", "output": "11-type\n" }, { "input": "10 10\n", "output": "2-type\n1\n" }, { "input": "5 2\n", "output": "3-type\n" }, { "input": "2 5\n", "output": "7-type\n" }, { "input": "8 5\n", "output": "7-type\n" }, { "input": "2 32\n", "...
code_contests
python
0
8f1900ffd6f27935606c7ef9a0987a4c
The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the pu...
def play(price, n): # dp[i][j][k] - naimen'shaya stoimost' peremeshcheniya i blinov so sterzhnya j => k # U nas vsegda est' dva varianta dejstviya: # 1. Peremeshchaem i - 1 blin na mesto 2. Dalee, peremeshchaem i - yj blin na mesto 3. I nakonec peremeshchaem i - 1 blin na mesto 3. # 2. Peremeshchaem i ...
python
code_algorithm
[ { "input": "0 2 1\n1 0 100\n1 2 0\n5\n", "output": "87\n" }, { "input": "0 2 2\n1 0 100\n1 2 0\n3\n", "output": "19\n" }, { "input": "0 1 1\n1 0 1\n1 1 0\n3\n", "output": "7\n" }, { "input": "0 9628 4599\n6755 0 5302\n5753 1995 0\n39\n", "output": "2894220024221629\n" }...
code_contests
python
0
9ca324b2007c64df718e0a5ed76f16ed
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards excep...
input() p = {(1 << 'RGBYW'.index(c)) + (1 << int(k) + 4) for c, k in input().split()} print(min(bin(t).count('1') for t in range(1024) if len({t & q for q in p}) == len(p))) # Made By Mostafa_Khaled
python
code_algorithm
[ { "input": "5\nB1 Y1 W1 G1 R1\n", "output": "4\n" }, { "input": "4\nG4 R4 R3 B3\n", "output": "2\n" }, { "input": "2\nG3 G3\n", "output": "0\n" }, { "input": "35\nG2 Y1 Y1 R4 G5 B5 R2 G4 G2 G3 W4 W1 B3 W5 R2 Y5 R4 R4 B5 Y2 B4 B1 R3 G4 Y3 G2 R4 G3 B2 G2 R3 B2 R1 W2 B4\n", ...
code_contests
python
0
972efc7a67f582cef3f13f245266eab7
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed t...
n = int(input())+1 nword = str(n) count = 1 while("8" not in nword): n+=1 nword = str(n) count += 1 print(count)
python
code_algorithm
[ { "input": "18\n", "output": "10\n" }, { "input": "179\n", "output": "1\n" }, { "input": "-1\n", "output": "9\n" }, { "input": "-1000000000\n", "output": "2\n" }, { "input": "-19\n", "output": "1\n" }, { "input": "-8\n", "output": "16\n" }, { ...
code_contests
python
0.9
fb6d96e504e68a38a2491ded72add9aa
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. <image> Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is ...
#------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w')...
python
code_algorithm
[ { "input": "1 5 2\n1 5 10\n2 7 4\n", "output": "1\n2\n" }, { "input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n", "output": "4\n-1\n8\n-1\n" }, { "input": "1 5000 1\n1 1000000 1000000\n", "output": "200\n" }, { "input": "999999 1000000 1\n1 1000000 1000000\n", "output": "1\n...
code_contests
python
0
120c9b7e35abe69616928f61424f9fe6
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side. One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2...
def prefix(s): v = [0]*len(s) for i in range(1,len(s)): k = v[i-1] while k > 0 and s[k] != s[i]: k = v[k-1] if s[k] == s[i]: k = k + 1 v[i] = k return v n = int(input()) n-=1 s1 = input() s2 = input() opos = {'W':'E', 'E':'W', 'N':'S', 'S':'N'} s3 = '...
python
code_algorithm
[ { "input": "3\nNN\nSS\n", "output": "NO\n" }, { "input": "7\nNNESWW\nSWSWSW\n", "output": "YES\n" }, { "input": "200\nNESENEESEESWWWNWWSWSWNWNNWNNESWSWNNWNWNENESENNESSWSESWWSSSEEEESSENNNESSWWSSSSESWSWWNNEESSWWNNWSWSSWWNWNNEENNENWWNESSSENWNESWNESWNESEESSWNESSSSSESESSWNNENENESSWWNNWWSWWNES...
code_contests
python
0
21deffc5f5fd580a54515d8931b0b684
<image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character o...
s = input() alpha = "abcdefghijklmnopqrstuvwxyz.0123456789" res = 0 for c in s: x1 = int('@' < c and '[' > c) x2 = alpha.index(c.lower()) + 1 x3 = int('`' < c and '{' > c) x4 = x1 * x2 x5 = x2 * x3 x6 = x4 - x5 res += x6 print(res)
python
code_algorithm
[ { "input": "APRIL.1st\n", "output": "17\n" }, { "input": "Codeforces\n", "output": "-87\n" }, { "input": "K3n5JwuWoJdFUVq8H5QldFqDD2B9yCUDFY1TTMN10\n", "output": "118\n" }, { "input": "F646Pj3RlX5iZ9ei8oCh.IDjGCcvPQofAPCpNRwkBa6uido8w\n", "output": "-44\n" }, { "i...
code_contests
python
0
ea5962a9630636afe6e7bd9ff5f5916b
You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from t...
import bisect import sys EPS = sys.float_info.epsilon LENGTH = 10 matrix = [[] for i in range(LENGTH)] array = [0] * LENGTH if __name__ == "__main__": n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) b = list(map(int, sys.stdin.readline().split())) answe...
python
code_algorithm
[ { "input": "3 2\n-2 2 4\n-3 0\n", "output": "4\n" }, { "input": "5 3\n1 5 10 14 17\n4 11 15\n", "output": "3\n" }, { "input": "10 10\n2 52 280 401 416 499 721 791 841 943\n246 348 447 486 507 566 568 633 953 986\n", "output": "244\n" }, { "input": "2 1\n4 8\n-1\n", "outpu...
code_contests
python
0.1
1691b5d985b071cdacae8313becbe8c4
Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black. Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing...
n,k,a,b = [int(i) for i in input().split()] check = False if (a>b): a,b = b,a check = True res = "" cr = 1 cA = True while (a > 0 or b > 0): if (a==b): break #print(a,b) if (cr==1): if a <= b: u = min(k, b - a) b -= u res += u * '1' else:...
python
code_algorithm
[ { "input": "5 1 3 2\n", "output": "GBGBG" }, { "input": "7 2 2 5\n", "output": "BBGBBGB" }, { "input": "4 3 4 0\n", "output": "NO\n" }, { "input": "99999 3580 66665 33334\n", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...
code_contests
python
0
a157ccb403f288b1f59e69aaf1d86219
Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs ...
from collections import defaultdict n, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] A_dict = defaultdict(int) for i in A: A_dict[i] += 1 def bitCount(x): cur = 0 while x > 0: if x % 2: cur += 1 x //= 2 return cur mask = [] for i in range(2**1...
python
code_algorithm
[ { "input": "6 0\n200 100 100 100 200 200\n", "output": "6\n" }, { "input": "4 1\n0 3 2 1\n", "output": "4\n" }, { "input": "2 1\n0 1\n", "output": "1\n" }, { "input": "2 0\n1 1\n", "output": "1\n" }, { "input": "3 2\n0 3 3\n", "output": "2\n" }, { "inp...
code_contests
python
0.5
37973198e1286cc4a05223081702826f
Bankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office. The crossroads are connected with m oriented bicycle lanes (the i-th lane goes from crossroad ui to crossroad vi), the difficulty of each of the lan...
import sys from functools import lru_cache input = sys.stdin.readline # sys.setrecursionlimit(2 * 10**6) def inpl(): return list(map(int, input().split())) @lru_cache(maxsize=None) def recur(v, s, e, k): """ vから初めて[s, e]の都市をk個まわる最小値は? """ if k == 0: return 0 elif k > e - s + 1: ...
python
code_algorithm
[ { "input": "7 4\n4\n1 6 2\n6 2 2\n2 4 2\n2 7 1\n", "output": "6\n" }, { "input": "4 3\n4\n2 1 2\n1 3 2\n3 4 2\n4 1 1\n", "output": "3\n" }, { "input": "5 5\n10\n2 4 420\n4 5 974\n5 1 910\n1 3 726\n1 2 471\n5 2 94\n3 2 307\n2 5 982\n5 4 848\n3 5 404\n", "output": "-1\n" }, { "...
code_contests
python
0
9f26bd6070ab9b9b8a68b01180cbf2f2
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. Valera absolutel...
from collections import defaultdict n = int(input()) arr = list(map(int,input().split())) cur = arr[0] cnt = 1 d = defaultdict(int) for i in range(1,n): if arr[i]==cur: cnt+=1 else: d[cnt]+=1 cur = arr[i] cnt = 1 if cnt!=0: d[cnt]+=1 ans = 0 for i in d: freq = d[i] cnt = (i*(i+1))//2 cnt = cnt*freq ans+=...
python
code_algorithm
[ { "input": "5\n-2 -2 -2 0 1\n", "output": "8\n" }, { "input": "4\n2 1 1 4\n", "output": "5\n" }, { "input": "1\n10\n", "output": "1\n" }, { "input": "100\n0 -18 -9 -15 3 16 -28 0 -28 0 28 -20 -9 9 -11 0 18 -15 -18 -26 0 -27 -25 -22 6 -5 8 14 -17 24 20 3 -6 24 -27 1 -23 0 4 12...
code_contests
python
0.5
a20eda1216c79ff3280f2a05e1d890c7
Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes h...
from sys import stdin as fin # fin = open("tc173b.in", "r") n = int(fin.readline()) # n, k = map(int, fin.readline().split()) arr = list(map(int, fin.readline().split())) # s = fin.readline().rstrip() s = dict() for i in range(n): x = arr[i] s[x] = (i, x) # print(tuple(s.items())) print(min(s.items(), key=lam...
python
code_algorithm
[ { "input": "6\n2 1 2 2 4 1\n", "output": "2\n" }, { "input": "5\n1 3 2 1 2\n", "output": "3\n" }, { "input": "2\n2018 2017\n", "output": "2018\n" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "1\n" }, { "input": "5\n100 1000 1000 1000 1000\n", "output...
code_contests
python
1
432ae70ad8b0bffa92cce53a9d7e4487
You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be <image> of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endp...
n=int(input()) print(((n//2)+1)*(n-(n//2)))
python
code_algorithm
[ { "input": "3\n", "output": "4\n" }, { "input": "2\n", "output": "2\n" }, { "input": "4\n", "output": "6\n" }, { "input": "31\n", "output": "256\n" }, { "input": "68\n", "output": "1190\n" }, { "input": "75\n", "output": "1444\n" }, { "inpu...
code_contests
python
0
785c90506a381cfffa93ab4193600c4d
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed tha...
s=input() h1=int(s[:2]) m1=int(s[3:]) s=input() h2=int(s[:2]) m2=int(s[3:]) #print(h1,m1,h2,m2) m=(m2-m1)+(h2-h1)*60; ma=(m1+m/2)%60; ha=(h1+(m1+m/2)/60); print('0'*(2-len(str(int(ha))))+str(int(ha))+':'+'0'*(2-len(str(int(ma))))+str(int(ma)))
python
code_algorithm
[ { "input": "01:02\n03:02\n", "output": "02:02\n" }, { "input": "11:10\n11:12\n", "output": "11:11\n" }, { "input": "10:00\n11:00\n", "output": "10:30\n" }, { "input": "09:10\n09:12\n", "output": "09:11\n" }, { "input": "00:01\n23:59\n", "output": "12:00\n" }...
code_contests
python
0.7
59182cbdf2dc625f1a5c42299ca10699
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of cust...
c=[0]*50 n=int(input()) a=[0]*2000001 a=[int(i) for i in input().split()] for i in range(n): c[int(a[i]+10)]+=1; r=0 for i in range(10): r+=int(c[int(i)]*c[int(20-i)]) r+=(c[10]*(c[10]-1))//2; r=int(r) print(r)
python
code_algorithm
[ { "input": "5\n-3 3 0 0 3\n", "output": "3\n" }, { "input": "3\n0 0 0\n", "output": "3\n" }, { "input": "2\n0 0\n", "output": "1\n" }, { "input": "10\n1 -1 2 -2 3 -3 4 -4 0 0\n", "output": "5\n" }, { "input": "4\n1 -1 1 -1\n", "output": "4\n" }, { "inp...
code_contests
python
0.1
c9ab0e4eca7e72b1c6ec1e367ece822c
You have a tree of n vertices. You are going to convert this tree into n rubber bands on infinitely large plane. Conversion rule follows: * For every pair of vertices a and b, rubber bands a and b should intersect if and only if there is an edge exists between a and b in the tree. * Shape of rubber bands must be ...
import os import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(int(3e5)) from collections import deque from queue import PriorityQueue import math import copy # list(map(int, input().split())) ##################################################################################### class CF(object): ...
python
code_algorithm
[ { "input": "6\n1 3\n2 3\n3 4\n4 5\n4 6\n", "output": "4\n" }, { "input": "4\n1 2\n2 3\n3 4\n", "output": "2\n" }, { "input": "28\n2 24\n2 4\n2 3\n1 2\n1 17\n1 21\n1 22\n10 22\n22 23\n22 26\n25 26\n16 25\n7 26\n5 7\n5 8\n5 15\n5 14\n5 12\n5 20\n11 25\n9 25\n6 9\n9 19\n9 28\n13 28\n18 28\n...
code_contests
python
0
64e98588da9e4eb9c29d7b201acf69bf
There are n warriors in a row. The power of the i-th warrior is a_i. All powers are pairwise distinct. You have two types of spells which you may cast: 1. Fireball: you spend x mana and destroy exactly k consecutive warriors; 2. Berserk: you spend y mana, choose two consecutive warriors, and the warrior with gr...
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.wr...
python
code_algorithm
[ { "input": "5 2\n5 2 3\n3 1 4 5 2\n3 5\n", "output": "8\n" }, { "input": "4 4\n2 1 11\n1 3 2 4\n1 3 2 4\n", "output": "0\n" }, { "input": "4 4\n5 1 4\n4 3 1 2\n2 4 3 1\n", "output": "-1\n" }, { "input": "4 4\n10 1 5\n1 2 3 4\n1 3 2 4\n", "output": "-1\n" }, { "inp...
code_contests
python
0
f1d85476039ebc552d227f426d0a6922
You've gotten an n × m sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as A. Set A is connected. Your task is to find the minimum number of squares that we can delete from set A to make it not connected. A set of painted squares is called connected, if for every two s...
def add(vertex,neighbour): if vertex in graph: graph[vertex].append(neighbour) else: graph[vertex]=[neighbour] if neighbour in graph: #####for undirected part remove to get directed graph[neighbour].append(vertex) else: graph[neighbour]=[vertex] def dfs(graph,n,currn...
python
code_algorithm
[ { "input": "5 4\n####\n#..#\n#..#\n#..#\n####\n", "output": "2\n" }, { "input": "5 5\n#####\n#...#\n#####\n#...#\n#####\n", "output": "2\n" }, { "input": "10 10\n..........\n.#####....\n.#........\n.#.###....\n.#.###....\n.#.###....\n.#..##....\n.#####....\n..........\n..........\n", ...
code_contests
python
0.3
3e90f0389d26a4d04aea0a6b5a173bbf
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
n = int(input()) g = [] for i in range(n): t = input().split() g.append([ int(t[0]), int(t[1]), False ]) def visita(i): g[i][2] = True for j in range(n): if g[j][2] == False and (g[i][0] == g[j][0] or g[i][1] == g[j][1]): visita(j) cnt = -1 for i in range(n): if g[i][2] == Fals...
python
code_algorithm
[ { "input": "2\n2 1\n1 2\n", "output": "1\n" }, { "input": "2\n2 1\n4 1\n", "output": "0\n" }, { "input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n1...
code_contests
python
0.4
25ad2fdbe8dee1f207928b04c60170e3
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good. Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions: * The sequence is strictly increasing, i.e. xi < xi + 1 f...
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import Counter def seieve_prime_factorisation(n): p, i = [1] * (n + 1), 2 while i * i <= n: if p[i] == 1: for j in range(i * i, n + 1, i): p[j]...
python
code_algorithm
[ { "input": "9\n1 2 3 5 6 7 8 9 10\n", "output": "4\n" }, { "input": "5\n2 3 4 6 9\n", "output": "4\n" }, { "input": "2\n1009 2018\n", "output": "2\n" }, { "input": "7\n1 2 3 4 7 9 10\n", "output": "3\n" }, { "input": "2\n601 1202\n", "output": "2\n" }, { ...
code_contests
python
0.6
30d2aa766fea0453a9b6a9d4d6400b23
Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a hou...
MOD = 10 ** 9 + 7 n, k = map(int, input().split()) ans = pow(n - k, n - k, MOD) * pow(k, k - 1, MOD) print(ans % MOD)
python
code_algorithm
[ { "input": "5 2\n", "output": "54\n" }, { "input": "7 4\n", "output": "1728\n" }, { "input": "475 5\n", "output": "449471303\n" }, { "input": "10 7\n", "output": "3176523\n" }, { "input": "685 7\n", "output": "840866481\n" }, { "input": "8 5\n", "o...
code_contests
python
0.2
63d97818e4ccb7b4ec88b37e8bca0d47
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddl...
n,m = map(int,input().split()) f = list(map(int,input().split())) f.sort() a = [] for i in range(m-n+1): a.append(f[i+n-1]-f[i]) print(min(a))
python
code_algorithm
[ { "input": "4 6\n10 12 10 7 5 22\n", "output": "5\n" }, { "input": "2 2\n1000 4\n", "output": "996\n" }, { "input": "2 3\n4 502 1000\n", "output": "498\n" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 ...
code_contests
python
0.8
63f54f44e840190e13f26d990bd024b6
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of mi...
#! usr/bin/env python3 # coding:UTF-8 # wdnmd UKE # wcnm UKE ans = 0 cnt = 0 N = input() t = input().split() for i in t: if(int(i) == 1): cnt += 1 else: ans += cnt print(ans)
python
code_algorithm
[ { "input": "5\n1 0 1 0 1\n", "output": "3\n" }, { "input": "4\n0 0 1 0\n", "output": "1\n" }, { "input": "4\n1 1 1 1\n", "output": "0\n" }, { "input": "1\n0\n", "output": "0\n" }, { "input": "2\n1 0\n", "output": "1\n" }, { "input": "2\n0 0\n", "ou...
code_contests
python
0.3
d337837decce25296e2788db031d814b
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone. In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o...
#!/usr/bin/env python3 a=list(map(int,input().split())) s=input() print(a[0]*s.count('1') + a[1]*s.count('2') + a[2]*s.count('3') + a[3]*s.count('4'))
python
code_algorithm
[ { "input": "1 2 3 4\n123214\n", "output": "13\n" }, { "input": "1 5 3 2\n11221\n", "output": "13\n" }, { "input": "1 2 3 4\n11111111111111111111111111111111111111111111111111\n", "output": "50\n" }, { "input": "5651 6882 6954 4733\n2442313421\n", "output": "60055\n" }, ...
code_contests
python
1
781d3442ff7c817e7fc2db550e2a9941
Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer m. What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? Input The single line contains two space separated i...
n,m = map(int, input().split()) if n < m: print(-1) else: if n % 2 == 0: b = n//2 else: b = (n//2)+1 while b % m != 0: b = b + 1 print(b)
python
code_algorithm
[ { "input": "10 2\n", "output": "6\n" }, { "input": "3 5\n", "output": "-1\n" }, { "input": "3979 2\n", "output": "1990\n" }, { "input": "18 10\n", "output": "10\n" }, { "input": "3832 6\n", "output": "1920\n" }, { "input": "8 2\n", "output": "4\n" ...
code_contests
python
0.4
bdbe1f78c9c50bdc7572ddbde98ef252
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base p and regard the expressio...
a,b=list(map(int,input().split())) k=int(max(str(a)+str(b)))+1 carry=0 l=max(len(str(a)),len(str(b))) for itr in range(l): if a%10+b%10+carry<k: carry=0 else: carry=1 a//=10 b//=10 #print(a,b) if carry: print(l+1) else: print(l)
python
code_algorithm
[ { "input": "78 87\n", "output": "3\n" }, { "input": "1 1\n", "output": "2\n" }, { "input": "208 997\n", "output": "4\n" }, { "input": "12 34\n", "output": "3\n" }, { "input": "104 938\n", "output": "4\n" }, { "input": "1000 539\n", "output": "4\n" ...
code_contests
python
0
4a55d6843fe826a04913e23095194da4
A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social network. We know that each server takes one second to recompress a one ...
import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) def main(): import heapq n, k = [int(i) for i in i...
python
code_algorithm
[ { "input": "6 1\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n6 3\n", "output": "1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n5000000004\n" }, { "input": "3 2\n1 5\n2 5\n3 5\n", "output": "6\n7\n11\n" }, { "input": "10 2\n1 5650\n2 4753\n3 7632\n4 ...
code_contests
python
0.7
2e966bc7462a3ee7d5118ea4e4a81ed8
The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one. Soon the Hedgehog came up with a brilliant idea: ins...
def rotate(puzzle): n_puzzle = [] for y in range(len(puzzle) - 1, -1, -1): n_puzzle.append(puzzle[y]) result = [] for x in range(len(puzzle[0])): col = [] for y in range(len(puzzle)): col.append(n_puzzle[y][x]) result.append(col) return result def puzzle...
python
code_algorithm
[ { "input": "2 4\nABDC\nABDC\n", "output": "3\n2 1\n" }, { "input": "2 6\nABCCBA\nABCCBA\n", "output": "1\n2 6\n" }, { "input": "12 18\nCBBCAACABACCACABBC\nABCAACABAABCBCBCCC\nBCAACCCBBBABBACBBA\nACCBCBBBAABACCACCC\nCAABCCCACACCBACACC\nBBBCBCACCABCCBCBBB\nBAABBCACAAAAACCBCB\nBAABAABACBCAB...
code_contests
python
0
024816636e966647a2b153b0644927de
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length ...
d=list(map(int,input().split())) d.sort() print(min(d[0]*2+d[1]*2,d[0]+d[1]+d[2]))
python
code_algorithm
[ { "input": "10 20 30\n", "output": "60\n" }, { "input": "1 1 5\n", "output": "4\n" }, { "input": "318476 318476 318476\n", "output": "955428\n" }, { "input": "1 100000000 1\n", "output": "4\n" }, { "input": "12 34 56\n", "output": "92\n" }, { "input": ...
code_contests
python
0
45cc667036dff65b6bce42ed7214c64b
Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter: How to build a wall: 1. Take a set of bricks. 2. Select one of the possibl...
result=0 mod=10**6 +3 n,C=map(int,input().split()) #recibimos la entrada #calc n! def fact(n): fact=1 for i in range(1,n+1): #1*2*3*...*n = n*(n-1)*(n-2)...*1 fact=(fact*i)%mod # return fact def pow(a,b): #Algoritmo de Exponenciacion binaria exp=1 # Caso base a^1=a x=a % mod b=b%(mod-1...
python
code_algorithm
[ { "input": "37 63\n", "output": "230574\n" }, { "input": "11 5\n", "output": "4367\n" }, { "input": "3 2\n", "output": "9\n" }, { "input": "2 2\n", "output": "5\n" }, { "input": "5 1\n", "output": "5\n" }, { "input": "350000 180000\n", "output": "7...
code_contests
python
0.1
0f0deb8b8f8c9ef4eef4f0448eb07fe3
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gras...
n,k=[int(x) for x in input().split()] s=input() if s.index('G')>s.index('T'):s=s[::-1] x=s.index('G') for i in range(x,n): x+=k if x>n-1 or s[x]=='#':print("NO");break elif s[x]=='T':print("YES");break
python
code_algorithm
[ { "input": "6 1\nT....G\n", "output": "YES\n" }, { "input": "6 2\n..GT..\n", "output": "NO\n" }, { "input": "7 3\nT..#..G\n", "output": "NO\n" }, { "input": "5 2\n#G#T#\n", "output": "YES\n" }, { "input": "100 1\nG.....................................................
code_contests
python
0.3
452671b47ee966055d5f920b120974b9
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a + b = c, where a and b are positive integers, and c is the sum of a...
a = input () b = input () c = str (int (a) + int (b)) a = a.replace ("0", "") b = b.replace ("0", "") c = c.replace ("0", "") if int (a) + int (b) == int (c): print ("YES") else: print ("NO")
python
code_algorithm
[ { "input": "105\n106\n", "output": "NO\n" }, { "input": "101\n102\n", "output": "YES\n" }, { "input": "5\n4\n", "output": "YES\n" }, { "input": "341781108\n784147010\n", "output": "NO\n" }, { "input": "501871728\n725074574\n", "output": "NO\n" }, { "in...
code_contests
python
0.9
dec21533d4cad8a1fda365c14e959da7
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate as possible...
#!/usr/bin/env python3 def solve(R,r,k): # Thanks to Numberphile's "Epic circles" video # Use the formula for radii of circles in Pappus chain r = r / R n = k answer = ((1-r)*r)/(2*((n**2)*((1-r)**2)+r)) # Note that in a Pappus chain the diameter of the circle is 1, so we need to scale up: answer = 2*R *...
python
code_algorithm
[ { "input": "2\n4 3 1\n4 2 2\n", "output": "0.9230769231\n0.6666666667\n" }, { "input": "1\n4 2 2\n", "output": "0.6666666667\n" }, { "input": "1\n1000 999 1\n", "output": "0.9999989990\n" }, { "input": "1\n7 2 1\n", "output": "1.7948717949\n" }, { "input": "1\n100...
code_contests
python
0
4e73c84b4ed43f4931fd026d34418dd6
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
def f(r): prev, ofs = -1, -1 s = list() while True: try: ofs = r.index(' ', ofs + 1) except ValueError: s.append(len(r) - 1 - prev) return s s.append(ofs - prev) prev = ofs n = int(input()) s = f(input().replace('-', ' ')) def can(w): c...
python
code_algorithm
[ { "input": "4\nEdu-ca-tion-al Ro-unds are so fun\n", "output": "10\n" }, { "input": "4\ngarage for sa-le\n", "output": "7\n" }, { "input": "4\nasd asd asd asdf\n", "output": "4\n" }, { "input": "1\nrHPBSGKzxoSLerxkDVxJG PfUqVrdSdOgJBySsRHYryfLKOvIcU\n", "output": "51\n" ...
code_contests
python
0
e490c21f104e68747ad4b16b37183829
Ann and Borya have n piles with candies and n is even number. There are ai candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new ...
n=int(input()) p=[] m=list(map(int,input().split())) from math import floor,ceil for i in m: if i**0.5%1==0: p.append(0) else: p.append(min(i-floor(i**0.5)**2,ceil(i**0.5)**2-i)) a=p.count(0) am=m.count(0) if n//2<=a: x=a-n//2 dif=a-am if dif >= x: print(x) else: ...
python
code_algorithm
[ { "input": "6\n0 0 0 0 0 0\n", "output": "6\n" }, { "input": "6\n120 110 23 34 25 45\n", "output": "3\n" }, { "input": "10\n121 56 78 81 45 100 1 0 54 78\n", "output": "0\n" }, { "input": "4\n12 14 30 4\n", "output": "2\n" }, { "input": "2\n2 0\n", "output": "...
code_contests
python
0
b92ae049a71ed7424acdc17e994b4cdd
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has n warriors, he places them on a straight line in front of the main gate, in a way that the i-th warrior stands right after (i-1)-th warrior. The fir...
import bisect n,q=map(int,input().split()) a=list(map(int,input().split())) s=[0,] for i in a: s.append(s[-1]+i) k=list(map(int,input().split())) tb=0 for i in range(q): tb+=k[i] if tb>=s[-1]: tb=0 print(n) else: ans=bisect.bisect_right(s,tb) print(n-ans+1)
python
code_algorithm
[ { "input": "4 4\n1 2 3 4\n9 1 10 6\n", "output": "1\n4\n4\n1\n" }, { "input": "5 5\n1 2 1 2 1\n3 10 1 1 1\n", "output": "3\n5\n4\n4\n3\n" }, { "input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5\n", "output": "10\n10\n5\n" }, { "input": "1 1\n56563128\n897699770\n", "output": "1...
code_contests
python
0.1
cce84143a4d595e0f70cc338799a40ec
Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture m...
input() a=list(map(int,input().split())) cnt=0 while a: i=a.index(a.pop(0)) cnt+=i a.pop(i) print(cnt)
python
code_algorithm
[ { "input": "4\n1 1 2 3 3 2 4 4\n", "output": "2\n" }, { "input": "3\n1 1 2 2 3 3\n", "output": "0\n" }, { "input": "3\n3 1 2 3 1 2\n", "output": "3\n" }, { "input": "1\n1 1\n", "output": "0\n" }, { "input": "19\n15 19 18 8 12 2 11 7 5 2 1 1 9 9 3 3 16 6 15 17 13 1...
code_contests
python
0
cedfab60d30656c830b86b9675070267
The king's birthday dinner was attended by k guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils. All types of utensils in the kingdom are numbered from 1 to 100....
import math n, k = map(int, input().split()) a = [int(t) for t in input().split()] d = {} for i in a: if d.get(i) is None: d[i] = 0 d[i] += 1 print(math.ceil(max(d.values()) / k) * len(d.keys()) * k - n)
python
code_algorithm
[ { "input": "10 3\n1 3 3 1 3 5 5 5 5 100\n", "output": "14\n" }, { "input": "5 2\n1 2 2 1 3\n", "output": "1\n" }, { "input": "100 1\n17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17...
code_contests
python
0.3
6525f66e507e4da2f77b308ad56e21b8
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as r...
n = int(input()) a = list(map(int, input().split())) print(2+(min(a)^a[2]))
python
code_algorithm
[ { "input": "5\n1 2 3 4 5\n", "output": "4\n" }, { "input": "7\n24 10 8 26 25 5 16\n", "output": "15\n" }, { "input": "7\n18 29 23 23 1 14 5\n", "output": "24\n" }, { "input": "9\n23 1 2 26 9 11 23 10 26\n", "output": "5\n" }, { "input": "7\n4 13 8 20 31 17 3\n", ...
code_contests
python
0
9fa83559efbeb87252229e9110e2fc38
The legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points |x| and |y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at poin...
num = int(input()) data = [abs(int(i)) for i in input().split()] data.sort() def bins(a, b, n): if a == b: if data[a] <= n: return a+1 else: return a else: m = (a+b)//2 if data[m] <= n: return bins(m+1,b,n) else: return bi...
python
code_algorithm
[ { "input": "2\n3 6\n", "output": "1\n" }, { "input": "3\n2 5 -3\n", "output": "2\n" }, { "input": "3\n0 1000000000 -1000000000\n", "output": "1\n" }, { "input": "10\n9 1 2 3 5 7 4 10 6 8\n", "output": "25\n" }, { "input": "20\n55 -14 -28 13 -67 -23 58 2 -87 92 -80...
code_contests
python
0.7
2d9c6c6b4a9a63d53bbd3ba63aff3e7d
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad. The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions a, b and c respectively. At the end of the performa...
a, b, c, d = map(int, input().split()) a, b, c = sorted([a, b, c]) def solve1(a, b, c): r1 = max(0, d-(b-a)) b += r1 r2 = max(0, d-(c-b)) return r1+r2 def solve2(a, b, c): r1 = max(0, d-(c-b)) r2 = max(0, d-(b-a)) return r1+r2 def solve3(a, b, c): r1 = max(0, d-(c-b)) b -= r1 r2...
python
code_algorithm
[ { "input": "5 2 6 3\n", "output": "2\n" }, { "input": "2 3 10 4\n", "output": "3\n" }, { "input": "3 1 5 6\n", "output": "8\n" }, { "input": "8 3 3 2\n", "output": "2\n" }, { "input": "1 1 1 1\n", "output": "2\n" }, { "input": "1 2 1 1\n", "output"...
code_contests
python
0.8
0d80cfb2a887fb99c2d2355dfd5018c2
There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number o...
N = int(input()) A = sorted([int(a) for a in input().split()]) k = 0 ans = 0 for i in range(N): if k > A[i]: pass elif k >= A[i] - 1: ans += 1 k += 1 else: ans += 1 k = A[i] - 1 print(ans)
python
code_algorithm
[ { "input": "6\n1 1 1 4 4 4\n", "output": "5\n" }, { "input": "4\n3 2 4 1\n", "output": "4\n" }, { "input": "10\n8 9 4 9 6 10 8 2 7 1\n", "output": "10\n" }, { "input": "125\n8 85 125 177 140 158 2 152 67 102 9 61 29 188 102 193 112 194 15 7 133 134 145 7 89 193 130 149 134 51...
code_contests
python
0.1
a5d72153fc2fb0b78c6987a17865dc79
Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string s and a number k (0 ≤ k < |s|). At the beginning of the game, players are given a substring of s with left border l and right border r, both equal to k ...
s = input().rstrip() minimum = "z" for ch in s: if ch > minimum: print("Ann") else: print("Mike") minimum = ch
python
code_algorithm
[ { "input": "abba\n", "output": "Mike\nAnn\nAnn\nMike\n" }, { "input": "cba\n", "output": "Mike\nMike\nMike\n" }, { "input": "dyqyq\n", "output": "Mike\nAnn\nAnn\nAnn\nAnn\n" }, { "input": "pefrpnmnlfxihesbjxybgvxdvvbliljvqoxxzvhlpfxcucqurvzeygbnpghxkgaethtkgjvlctneuuqzfwypkaj...
code_contests
python
0
49930fbd91b9597c7a3b03740cc77369
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.wri...
python
code_algorithm
[ { "input": "1 4 100 10 30 5\n6\n101 104 105 110 130 200\n", "output": "0\n" }, { "input": "1 1 2 2 3 3\n7\n13 4 11 12 11 13 12\n", "output": "7\n" }, { "input": "5 4 7 6 4 1\n10\n19 16 18 12 16 15 16 20 16 14\n", "output": "2\n" }, { "input": "158260522 877914575 602436426 24...
code_contests
python
0.2
e1a2016d31f8c679f0f5275adc45466d
The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks...
def solve(): n = int(input()) cards = [] cnt = {} for i in range(n): card = tuple(map(int, input().split(' '))) cards.append(card) cnt[card[0]] = [0, 0] cnt[card[1]] = [0, 0] for card in cards: if card[0] != card[1]: cnt[card[0]][0] += 1 ...
python
code_algorithm
[ { "input": "3\n4 7\n4 7\n7 4\n", "output": "0\n" }, { "input": "5\n4 7\n7 4\n2 11\n9 7\n1 1\n", "output": "2\n" }, { "input": "1\n1 2\n", "output": "0\n" }, { "input": "2\n1 1\n1 1\n", "output": "0\n" }, { "input": "5\n1 2\n1 3\n4 1\n5 1\n6 7\n", "output": "1\...
code_contests
python
0
1a5cd31e7a2181d660972ec20c037372
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the s...
from sys import stdin,stdout import bisect as bs nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): s=input() n=len(s) x=s.count('x') y=n-x if y>=x: for i in range(y-x): stdout.write('y') else: for i ...
python
code_algorithm
[ { "input": "x\n", "output": "x" }, { "input": "yxyxy\n", "output": "y" }, { "input": "xxxxxy\n", "output": "xxxx" }, { "input": "xxxyx\n", "output": "xxx" }, { "input": "xxxxxxxxxxxyxyyxxxxyxxxxxyxxxxxyxxxxxxxxyx\n", "output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" ...
code_contests
python
0.1
faf4423cf67113f73432ffeff56db744
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the ...
import bisect n,t=list(map(int,input().split())) a=list(map(int,input().rstrip().split())) b=[0] sol=0 for i in range(n): b.append(b[-1]+a[i]) b.pop(0) for i in range(n): sol=max(sol,bisect.bisect_right(b,t)-i) t+=a[i] print(sol)
python
code_algorithm
[ { "input": "4 5\n3 1 2 1\n", "output": "3\n" }, { "input": "3 3\n2 2 3\n", "output": "1\n" }, { "input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4\n", "output": "6\n" }, { "input": "2 10\n6 4\n", "output": "2\n" }, { "input": "100 100\n75 92 18 6 81 67 7 92...
code_contests
python
1
91e72be95de90b2f38066ce61eced907
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements c...
#!/usr/bin/python3 n = int(input()) data = list(map(int, input().split())) negative, zero, positive = 0, 0, 0 for element in data: if element < 0: negative += 1 elif element == 0: zero += 1 else: positive += 1 seen = {} min_negative = negative def go(negative, positive): glob...
python
code_algorithm
[ { "input": "2\n-1 -100 -1\n", "output": "100\n" }, { "input": "2\n50 50 50\n", "output": "150\n" }, { "input": "5\n270 -181 957 -509 -6 937 -175 434 -625\n", "output": "4094\n" }, { "input": "6\n-403 901 -847 -708 -624 413 -293 709 886 445 716\n", "output": "6359\n" }, ...
code_contests
python
0.1
4aef6d73638c6af34100d25cc69e0b5f
Cucumber boy is fan of Kyubeat, a famous music game. Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel. Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his...
n = int(input()) memo = {} for _ in range(4): s = input() for i in s: if i != '.': if i not in memo: memo[i] = 1 else: memo[i] += 1 res = True for k, v in memo.items(): if v > n*2: res = False if res: print("YES") else: pri...
python
code_algorithm
[ { "input": "5\n..1.\n1111\n..1.\n..1.\n", "output": "YES\n" }, { "input": "1\n.135\n1247\n3468\n5789\n", "output": "YES\n" }, { "input": "1\n....\n12.1\n.2..\n.2..\n", "output": "NO\n" }, { "input": "4\n7777\n..7.\n.7..\n7...\n", "output": "YES\n" }, { "input": "2...
code_contests
python
1
f7e08186392f3ba38877233c8d35a58d
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>...
def NoW(xs): if sum(xs) % 3 != 0: return 0 else: part = sum(xs) // 3 ci = ret = 0 acum = xs[0] for i, x in enumerate(xs[1:]): if acum == 2*part: # print("2. x=",x) ret += ci if acum == part: # print("...
python
code_algorithm
[ { "input": "2\n4 1\n", "output": "0\n" }, { "input": "4\n0 1 -1 0\n", "output": "1\n" }, { "input": "5\n1 2 3 0 3\n", "output": "2\n" }, { "input": "5\n1 1 1 1 1\n", "output": "0\n" }, { "input": "4\n0 2 -1 2\n", "output": "0\n" }, { "input": "9\n0 0 0...
code_contests
python
0.2
ae35b7bd5c7a0bab2f4f217350ae5713
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio...
I = lambda: int(input()) IL = lambda: list(map(int, input().split())) L = [input()[0] for i in '123'] gt = {'r': 'rp', 'p': 'ps', 's': 'sr'} print('F' if L[1] not in gt[L[0]] and L[2] not in gt[L[0]] else 'M' if L[0] not in gt[L[1]] and L[2] not in gt[L[1]] else 'S' if L[0] not in gt[L[2]] and L[1] not in...
python
code_algorithm
[ { "input": "scissors\nrock\nrock\n", "output": "?\n" }, { "input": "scissors\npaper\nrock\n", "output": "?\n" }, { "input": "rock\nrock\nrock\n", "output": "?\n" }, { "input": "paper\nrock\nrock\n", "output": "F\n" }, { "input": "rock\npaper\nrock\n", "output"...
code_contests
python
0.6
f3d88af07986145b5eb78ff60e6a0336
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (bec...
n = int(input()) a = [int(i) for i in input().split()] for i in range(n): print(min(abs(a[i]-a[(i+1)%n]), abs(a[i]-a[i-1])), max(abs(a[i]-a[0]), abs(a[i]-a[-1])))
python
code_algorithm
[ { "input": "2\n-1 1\n", "output": "2 2\n2 2\n" }, { "input": "4\n-5 -2 2 7\n", "output": "3 12\n3 9\n4 7\n5 12\n" }, { "input": "3\n-1000000000 0 1000000000\n", "output": "1000000000 2000000000\n1000000000 1000000000\n1000000000 2000000000\n" }, { "input": "5\n-2 -1 0 1 2\n",...
code_contests
python
0.8
6363bae5d8be0f9b3928910084fedecc
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimi...
from collections import * import sys import math from functools import reduce def factors(n): return set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) def li():return [int(i) for i in input().rstrip('\n').split(' ')] def st():return input().rstrip('\n') def val():return i...
python
code_algorithm
[ { "input": "5\n1 1 2 3 3\n", "output": "2\n" }, { "input": "4\n0 1 2 3\n", "output": "4\n" }, { "input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599\n", "output": "11\n" }, { "input": "1\n120287\n", "output": "1\n" }, { "input": "35\n130212 3176 7...
code_contests
python
0.1
91916225290388c310f56a118427d7b1
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n. Each man has at most one father but may have arbitrary number of sons. Man number A is considered to b...
# [https://codeforces.com/contest/681/submission/37694242 <- https://codeforces.com/contest/681/status/D <- https://codeforces.com/contest/681 <- https://codeforces.com/blog/entry/45425 <- https://codeforces.com/problemset/problem/681/D <- https://algoprog.ru/material/pc681pD] (n, m) = map(int, input().split()) adj = ...
python
code_algorithm
[ { "input": "3 2\n1 2\n2 3\n1 2 1\n", "output": "-1\n" }, { "input": "4 2\n1 2\n3 4\n1 2 3 3\n", "output": "3\n2\n1\n3\n" }, { "input": "1 0\n1\n", "output": "1\n1\n" }, { "input": "4 3\n4 3\n3 2\n2 1\n3 4 4 4\n", "output": "-1\n" }, { "input": "4 3\n1 2\n2 3\n3 4\...
code_contests
python
0
c84be37da7ab107286c63d32ca17cbb4
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that membe...
n,m = map(int,input().split()) dic = {} edges = [] from collections import Counter def find(node): tmp = node while node!=dic[node]: node = dic[node] while tmp!=dic[tmp]: dic[tmp],tmp=node,dic[tmp] return node for _ in range(m): p1,p2 = map(int,input().split()) dic.setdefault(p1,...
python
code_algorithm
[ { "input": "10 4\n4 3\n5 10\n8 9\n1 2\n", "output": "YES\n" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2\n", "output": "NO\n" }, { "input": "3 2\n1 2\n2 3\n", "output": "NO\n" }, { "input": "4 3\n1 3\n3 4\n1 4\n", "output": "YES\n" }, { "input": "4 5\n1 2\n1 3\n1 4\n2 3...
code_contests
python
0.9
0f9fbb7c21b25ff919ad665d9dd330ff
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a...
input() for t in input().split(): if int(t) % 2: print("First") break else: print("Second")
python
code_algorithm
[ { "input": "4\n1 3 2 3\n", "output": "First\n" }, { "input": "2\n2 2\n", "output": "Second\n" }, { "input": "6\n2 2 1 1 4 2\n", "output": "First\n" }, { "input": "3\n1 2 2\n", "output": "First\n" }, { "input": "5\n1 1 1 1 1\n", "output": "First\n" }, { ...
code_contests
python
0.5
d885c80ab15a677595e25b1f9e63d990
You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have ...
n = int(input()) arr = [int(x) for x in input().split()] cnt = 0 for i in range(1,n-1): if arr[i]< arr[i-1] and arr[i] < arr[i+1]:cnt += 1 else: if arr[i]> arr[i-1] and arr[i] > arr[i+ 1]: cnt += 1 print(cnt)
python
code_algorithm
[ { "input": "3\n1 2 3\n", "output": "0\n" }, { "input": "4\n1 5 2 5\n", "output": "2\n" }, { "input": "3\n3 2 3\n", "output": "1\n" }, { "input": "1\n548\n", "output": "0\n" }, { "input": "3\n1 2 1\n", "output": "1\n" }, { "input": "1\n1\n", "output...
code_contests
python
1
c155081cf67ccab72bad513836a90af1
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is t...
import math n = int(input()) ans = 0 cur = 1 while cur < n: cnt = math.ceil((n-cur)/(cur << 1)) ans += cnt*cur cur <<= 1 print(ans)
python
code_algorithm
[ { "input": "4\n", "output": "4\n" }, { "input": "2\n", "output": "1\n" }, { "input": "7\n", "output": "11\n" }, { "input": "536870913\n", "output": "8321499136\n" }, { "input": "1048576\n", "output": "10485760\n" }, { "input": "1024\n", "output": "...
code_contests
python
0.2
48ad452f827841985d183e07fc90f0d5
You are given a set of size m with integer elements between 0 and 2^{n}-1 inclusive. Let's build an undirected graph on these integers in the following way: connect two integers x and y with an edge if and only if x \& y = 0. Here \& is the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). C...
n, m = map(int, input().split()) a = set(map(int, input().split())) y = 2 ** n mk = [0] * (2 * y) cur = 0 for x in a: if mk[x]: continue mk[x] = 1 st = [x] def push(v): if not mk[v]: mk[v] = 1; st.append(v) while st: u = st.pop() if u < y: push(y + u) els...
python
code_algorithm
[ { "input": "2 3\n1 2 3\n", "output": "2\n" }, { "input": "5 5\n5 19 10 20 12\n", "output": "2\n" }, { "input": "6 19\n15 23 27 29 30 31 43 46 47 51 53 55 57 58 59 60 61 62 63\n", "output": "19\n" }, { "input": "3 5\n3 5 0 6 7\n", "output": "1\n" }, { "input": "0 1...
code_contests
python
1
9a0a458ae9e8984522dd9c75cfb33ac7
There is a rectangular grid of size n × m. Each cell has a number written on it; the number on the cell (i, j) is a_{i, j}. Your task is to calculate the number of paths from the upper-left cell (1, 1) to the bottom-right cell (n, m) meeting the following constraints: * You can move to the right or to the bottom onl...
from collections import* n, m, k = map(int, input().split()) b = [[int(v) for v in input().split()] for _ in range(n)] if m < n: a = [[b[j][i] for j in range(n)] for i in range(m)] b = a m, n = n, m cntrs = [Counter() for _ in range(n)] d = (n + m-1) // 2 for i in range(1<<d): ones = bin(i).count('1') ...
python
code_algorithm
[ { "input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n", "output": "0\n" }, { "input": "3 3 11\n2 1 5\n7 10 0\n12 6 4\n", "output": "3\n" }, { "input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n", "output": "5\n" }, { "input": "1 1 982347923479\n1\n", "output": "0\n" ...
code_contests
python
0.4
1fe1d3c01ae05cf05fa5310fb3ab14a1
You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices x and y is a_x + a_y coins. There are...
n, m = map(int, input().split()) a = list(map(int, input().split())) e = [] for _ in range(m) : u, v, w = map(int, input().split()) e.append((u-1, v-1, w)) a = sorted(zip(a, range(n)), key = lambda x : x[0]) for i in range(1, n) : e.append((a[0][1], a[i][1], a[0][0] + a[i][0])) fa = list(range(n)) rk = [...
python
code_algorithm
[ { "input": "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15\n", "output": "18\n" }, { "input": "3 2\n1 3 3\n2 3 5\n2 1 1\n", "output": "5\n" }, { "input": "4 0\n1 3 3 7\n", "output": "16\n" }, { "input": "1 0\n4\n", "output": "0\n" }, { "input": "10 0\n9 9 5 2 2 5 8 ...
code_contests
python
0.9
16a5c3e6386ee0b44dd180f6525a8556
You are given array a_1, a_2, ..., a_n. Find the subsegment a_l, a_{l+1}, ..., a_r (1 ≤ l ≤ r ≤ n) with maximum arithmetic mean (1)/(r - l + 1)∑_{i=l}^{r}{a_i} (in floating-point numbers, i.e. without any rounding). If there are many such subsegments find the longest one. Input The first line contains single integer...
n=int(input()) s=[int(x) for x in input().split()] el=max(s) pos1=-1 pos2=-1 c=0 ans=0 for i in range(0,len(s)): if(s[i]==el): c=c+1 else: ans=max(ans,c) c=0 ans=max(ans,c) print(ans)
python
code_algorithm
[ { "input": "5\n6 1 6 6 0\n", "output": "2\n" }, { "input": "2\n1 5\n", "output": "1\n" }, { "input": "5\n1 0 0 0 0\n", "output": "1\n" }, { "input": "15\n2 2 1 2 2 2 2 1 2 2 2 1 2 2 3\n", "output": "1\n" }, { "input": "2\n1 2\n", "output": "1\n" }, { "...
code_contests
python
0.3
d2080d820e558ff117f19aa3e5a24682
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system cons...
import sys import collections import math import heapq from operator import itemgetter def getint(): return int(input()) def getints(): return [int(x) for x in input().split(' ')] n = getint() points = [tuple(getints()) for _ in range(n)] result = 0 slopes = collections.defaultdict(set) for i in range(n - 1...
python
code_algorithm
[ { "input": "4\n0 0\n1 1\n0 3\n1 2\n", "output": "14\n" }, { "input": "4\n0 0\n0 2\n0 4\n2 0\n", "output": "6\n" }, { "input": "3\n-1 -1\n1 0\n3 1\n", "output": "0\n" }, { "input": "2\n10000 10000\n-10000 -10000\n", "output": "0\n" }, { "input": "5\n-8893 8986\n-36...
code_contests
python
0.1
9e2cb5b99abe2a30b0aea5e914e4f148
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a...
from math import sqrt def get_int(): from sys import stdin return int(stdin.readline().replace('\n', '')) def is_even(n): return n%2 == 0 def heidi_hash(r): k = r-1 rt = int(sqrt(k)) for x in range(1, rt+2): if k % x == 0: temp = k/x -x -1 if temp > 0 and is_e...
python
code_algorithm
[ { "input": "19\n", "output": "1 8\n" }, { "input": "16\n", "output": "NO\n" }, { "input": "768407398177\n", "output": "1 384203699087\n" }, { "input": "7\n", "output": "1 2\n" }, { "input": "156231653273\n", "output": "1 78115826635\n" }, { "input": "4...
code_contests
python
0.5
0aa25f9c504d68aa3d283d3679e3de0f
You are on the island which can be represented as a n × m table. The rows are numbered from 1 to n and the columns are numbered from 1 to m. There are k treasures on the island, the i-th of them is located at the position (r_i, c_i). Initially you stand at the lower left corner of the island, at the position (1, 1). I...
from sys import stdin from bisect import bisect_left input=stdin.readline n,m,k,q=map(int,input().split(' ')) x=sorted(list(map(int,input().split(' ')))for i in range(k)) y=sorted(list(map(int,input().split(' ')))) def rr(c0,c1,c2): return abs(c2-c0)+abs(c1-c2) def tm(c0,c1): t=bisect_left(y,c0) tt=[] ...
python
code_algorithm
[ { "input": "3 6 3 2\n1 6\n2 2\n3 4\n1 6\n", "output": "15\n" }, { "input": "3 3 3 2\n1 1\n2 1\n3 1\n2 3\n", "output": "6\n" }, { "input": "3 5 3 2\n1 2\n2 3\n3 1\n1 5\n", "output": "8\n" }, { "input": "2 11 7 6\n1 1\n1 5\n1 2\n1 4\n1 11\n1 8\n1 3\n3 6 5 10 2 7\n", "output...
code_contests
python
0
36022c7f8e498e8adffe4a043bb10a7f
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit...
def prime_factor(n): ass = [] for i in range(2,int(n**0.5)+1): while n % i==0: ass.append(i) n = n//i if n != 1: ass.append(n) return ass n = int(input()) p = list(set(prime_factor(n))) if len(p) == 1: print(p[0]) else: print(1)
python
code_algorithm
[ { "input": "5\n", "output": "5\n" }, { "input": "4\n", "output": "2\n" }, { "input": "2\n", "output": "2\n" }, { "input": "54241012609\n", "output": "1\n" }, { "input": "4294967318\n", "output": "1\n" }, { "input": "370758709373\n", "output": "1\n"...
code_contests
python
0
0d82584d023ddedece665ba1d1e04255
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test c...
t=int(input()) for i in range(0,t): a,b=input().split() a=int(a) b=int(b) print((b-a%b)%b)
python
code_algorithm
[ { "input": "5\n10 4\n13 9\n100 13\n123 456\n92 46\n", "output": "2\n5\n4\n333\n0\n" }, { "input": "1\n515151 2\n", "output": "1\n" }, { "input": "21\n1 3218\n28 10924\n908802 141084\n82149 9274\n893257 10248\n2750048 802705\n2857 142\n980 209385\n1 3218\n28 10924\n908802 141084\n82149 92...
code_contests
python
1
cb9263badd242860dea59f687ae071cb
Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weigh...
t=eval(input()) for j in range(t): n=eval(input()) if n==2 : print(2) else: sum=2 for i in range(1,n//2): sum=sum+2**(i+1) print(sum)
python
code_algorithm
[ { "input": "2\n2\n4\n", "output": "2\n6\n" }, { "input": "100\n2\n4\n6\n8\n10\n12\n14\n16\n18\n20\n22\n24\n26\n28\n30\n30\n30\n30\n20\n30\n30\n18\n14\n16\n30\n24\n30\n30\n10\n20\n30\n10\n2\n18\n30\n30\n12\n24\n30\n24\n18\n28\n30\n16\n30\n30\n30\n30\n22\n26\n30\n30\n30\n10\n14\n6\n18\n30\n16\n30\n30\...
code_contests
python
0
9f92cfc23ad3afccdf1708eac56effd2
Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you that a ticket is lucky if the sum of digits in its first half matches th...
number_of_testcases = 1 #int(input()) for _ in range(number_of_testcases): number_of_digits = int(input()) ticket_number = input() ticket_number = list(ticket_number) first_half = ticket_number[:number_of_digits] second_half = ticket_number[number_of_digits:] #print(first_half) first_half....
python
code_algorithm
[ { "input": "2\n3754\n", "output": "NO\n" }, { "input": "2\n0135\n", "output": "YES\n" }, { "input": "2\n2421\n", "output": "YES\n" }, { "input": "20\n7405800505032736115894335199688161431589\n", "output": "YES\n" }, { "input": "100\n0200210221001101010012012020022...
code_contests
python
1
f0b5da292109218123e3de893db45021
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you. During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of...
n = int(input()) stones = list(map(lambda t : int(t), input().split())) q = int(input()) queries = list(map(lambda t : int(t), input().split())) stones.sort() added_stones = [] added_stones.append(stones[0]) for i in range(1, n, 1): added_stones.append(stones[i] + added_stones[i - 1]) computed_queries = {} for ...
python
code_algorithm
[ { "input": "5\n2 3 4 1 1\n2\n2 3\n", "output": "9 8\n" }, { "input": "3\n1 6 8\n1\n6\n", "output": "7\n" }, { "input": "1\n10\n5\n5 3 7 7 1\n", "output": "0 0 0 0 0\n" }, { "input": "4\n7 4 1 7\n3\n6 8 3\n", "output": "12 12 12\n" }, { "input": "1\n1\n3\n2 1 10\n"...
code_contests
python
0
bbfcc7bffc0c697a5172c70c83db4793
Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha...
n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) b=list(map(int,input().strip().split())) ups = [[i+1 for i in range(n)]] downs = [[i+1 for i in range(n)]] def apply(arr): out = [0]*n for i in range(n): out[i] = arr[a[i]-1] return out def unapply(arr): out = [0]*n ...
python
code_algorithm
[ { "input": "4 1\n4 3 1 2\n3 4 2 1\n", "output": "YES\n" }, { "input": "4 1\n4 3 1 2\n2 1 4 3\n", "output": "NO\n" }, { "input": "4 3\n4 3 1 2\n3 4 2 1\n", "output": "YES\n" }, { "input": "4 1\n2 3 4 1\n1 2 3 4\n", "output": "NO\n" }, { "input": "4 2\n4 3 1 2\n2 1 ...
code_contests
python
0
07e833a312366f0558dffebf48ede084
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined by a pair of integers l_i, r_i (1 ≤ l_i ≤ r_i ≤ n). You need to f...
n,m = map(int,input().split()) a = list(map(int,input().split())) l = [0]*(n+2) for i in range(m): x,y=map(int,input().split()) l[x] += 1 l[y+1] -= 1 for i in range(2, n+2): l[i] += l[i-1] l.sort(reverse=True) a.sort(reverse=True) # print(l, a) ans=0 for i in range(n): ans += l[i]*a[i] print(ans)
python
code_algorithm
[ { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n", "output": "33\n" }, { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "output": "25\n" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n1...
code_contests
python
0.8
4a905d242c7ea515049ee7acc043ddc9
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: * 'U': go up, (x, y) → (x, y+1); * 'D': go down, (x, y) → (x, y-1); * 'L': go left...
target = tuple(map(int, input().split())) s = input() #print(target) #print(s) ok = False pos = (0, 0) for c in s: if c == 'L': pos = (pos[0]-1, pos[1]) if c == 'R': pos = (pos[0]+1, pos[1]) if c == 'U': pos = (pos[0], pos[1]+1) if c == 'D': pos = (pos[0], pos[1]-1) if pos == target: ok = True if...
python
code_algorithm
[ { "input": "0 0\nD\n", "output": "Yes\n" }, { "input": "-1 1000000000\nLRRLU\n", "output": "Yes\n" }, { "input": "2 2\nRU\n", "output": "Yes\n" }, { "input": "1 2\nRU\n", "output": "No\n" }, { "input": "999999999 -999999999\nRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDD...
code_contests
python
0
e00d702d3d0e3904e2c8e47e6c0181c8
You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The ...
# t=int(input()) # import math # for _ in range(t): # n,k=list(map(int,input().split())) # s=input() # a=[] # summer=0 # for i in range(len(s)): # if(s[i]=='1'): # a.append(i) # i=0 # while(i<len(a)-1): # dist=a[i+1]-k-1-(a[i]+k+1)+1 # # print(a,dist) # ...
python
code_algorithm
[ { "input": "5\n100 -100 50 0 -50\n", "output": "100 -50 0 50 -100\n" }, { "input": "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -...
code_contests
python
0
023f4a03feb28558dd65db88f92645fc
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this: <image> Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors. The key of this game is to find a cycle that contain d...
''' Zijian He 1429876 ''' # Import from sys import setrecursionlimit setrecursionlimit(10**6) # Function from class class Graph: def __init__ (self): self._alist = {} def add_vertex (self, vertex): if vertex not in self._alist: self._alist[vertex] = set() def add_edge (self, ...
python
code_algorithm
[ { "input": "2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n", "output": "No\n" }, { "input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n", "output": "Yes\n" }, { "input": "3 4\nAAAA\nABCA\nAAAA\n", "output": "Yes\n" }, { "input": "3 4\nAAAA\nABCA\nAADA\n", "output...
code_contests
python
0.8
cfbefff03bc55f8686ad940b0127d814
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. <image> Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is ...
a,b,n=map(int,input().split()) for _ in range(n): l,t,m=map(int,input().split()) lo=l hi=100000000 while lo<hi: mid=(lo+hi)//2 count=(mid-l)+1 first=a+(l-1)*b last=a+(mid-1)*b if last<=t and (count*(first+last))//2<=m*t: lo=mid+1 else: ...
python
code_algorithm
[ { "input": "1 5 2\n1 5 10\n2 7 4\n", "output": "1\n2\n" }, { "input": "2 1 4\n1 5 3\n3 3 10\n7 10 2\n6 4 8\n", "output": "4\n-1\n8\n-1\n" }, { "input": "1 1 1\n1 1000000 1000000\n", "output": "1000000\n" }, { "input": "447 74474 4\n47 777474 747\n74 744744 74477\n477 477447 7...
code_contests
python
0
120c9b7e35abe69616928f61424f9fe6
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it...
n = int(input()) a = list(map(int, input().split())) + [0] home = True ans = 0 for i in range(n): if a[i]: ans += 1 home = False elif not a[i + 1] and not home: home = True elif not home: ans += 1 print(ans)
python
code_algorithm
[ { "input": "5\n0 1 0 1 1\n", "output": "4\n" }, { "input": "7\n1 0 1 0 0 1 0\n", "output": "4\n" }, { "input": "1\n0\n", "output": "0\n" }, { "input": "95\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
code_contests
python
0
88c08865e1188a3451597a0ab0d807c4
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as <image>, where si is the i-th character of s and ti is the i-th character of t. For example, the Hamming ...
from sys import stdin input=stdin.readline ''' if i+k ''' def getcnt(a): cnt=[[0,0] for i in range(len(a)+1)] for i in range(len(a)): # if i==0: # cnt[i][a[i]]+=1 # else: cnt[i+1][0]=cnt[i][0] cnt[i+1][1]=cnt[i][1] cnt[i+1][a[i]]+=1 return cnt def f(a,b):...
python
code_algorithm
[ { "input": "01\n00111\n", "output": "3\n" }, { "input": "0011\n0110\n", "output": "2\n" }, { "input": "1001101001101110101101000\n01111000010011111111110010001101000100011110101111\n", "output": "321\n" }, { "input": "1\n0\n", "output": "1\n" }, { "input": "0\n1\n...
code_contests
python
0
7ccca6f982f9ed722cdccd534f0d6bb0
You are given names of two days of the week. Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t...
a = str(input()) b = str(input()) k = {'monday':1,'tuesday':2,'wednesday':3,'thursday':4,'friday':5,'saturday':6,'sunday':7} a=k[a]-1 b=k[b]-1 res = False res = res or ((a+2)%7+1)%7==b res = res or ((a+1)%7+1)%7==b res = res or ((a+6)%7+1)%7==b if res: print("YES") else: print("NO")
python
code_algorithm
[ { "input": "monday\ntuesday\n", "output": "NO\n" }, { "input": "saturday\ntuesday\n", "output": "YES\n" }, { "input": "sunday\nsunday\n", "output": "YES\n" }, { "input": "friday\ntuesday\n", "output": "NO\n" }, { "input": "thursday\nmonday\n", "output": "NO\n"...
code_contests
python
0.7
2150aa584d740238b4f56afb7ceb07fa
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
n = int(input()) a = list(map(int, input().split())) a.sort() if n % 2: print(a[n//2])
python
code_algorithm
[ { "input": "1\n2050\n", "output": "2050\n" }, { "input": "3\n2014 2016 2015\n", "output": "2015\n" }, { "input": "5\n2099 2096 2095 2097 2098\n", "output": "2097\n" }, { "input": "3\n2011 2010 2012\n", "output": "2011\n" }, { "input": "5\n2097 2099 2100 2098 2096\...
code_contests
python
0.8
1cc179af8c6980635ae9bf5db9646f55
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
n,k=map(int,input().split()) l=list(map(int,input().split())) K=min(l) for i in range(n): if (l[i]-K)%k!=0: print(-1) exit() Sum=sum(l) K=K*n Sum=Sum-K print(Sum//k)
python
code_algorithm
[ { "input": "2 2\n10 9\n", "output": "-1\n" }, { "input": "3 3\n12 9 15\n", "output": "3\n" }, { "input": "4 1\n1 1000000000 1000000000 1000000000\n", "output": "2999999997\n" }, { "input": "3 3\n1 3 5\n", "output": "-1\n" }, { "input": "10 2\n2 1000000000 10000000...
code_contests
python
0.8
80b759423c59680c366433a2e628775b
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time! Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal. ...
import sys n = int(input()) + 1 a = [0] + list(map(int, input().split())) mod7 = [x % 7 for x in a] dp = [[0]*n for _ in range(n)] maxnum = [0]*(10**5+10) ans = 0 for i in range(n): maxmod = [0]*7 for j in range(n): maxnum[a[j]] = 0 for j in range(i): maxnum[a[j]] = max(maxnum[a[j]], dp...
python
code_algorithm
[ { "input": "6\n62 22 60 61 48 49\n", "output": "5\n" }, { "input": "4\n1 2 4 5\n", "output": "4\n" }, { "input": "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333\n", "output": "6\n" }, { "input": "6\n7 20 21 22 23 28\n", "output": "6\n" }, { "input": ...
code_contests
python
0
f18ba2bbc2dc133c378a1022edb0fc1c
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch...
from collections import defaultdict,Counter,deque as dq from sys import stdin input=stdin.readline n=int(input()) g=defaultdict(list) w=list(map(int,input().strip().split())) for i in range(len(w)): g[w[i]-1].append(i+1) g[i+1].append(w[i]-1) # print(g) q=dq([0]) d=[-1]*(n) d[0]=1 cnt=defaultdict(int) cnt[1]+=1 wh...
python
code_algorithm
[ { "input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n", "output": "4\n" }, { "input": "3\n1 1\n", "output": "1\n" }, { "input": "5\n1 2 2 2\n", "output": "3\n" }, { "input": "3\n1 2\n", "output": "3\n" }, { "input": "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 ...
code_contests
python
0.1
4c80cfadc39cfe987ac73cab3bdf8822
Two players play a game. Initially there are n integers a_1, a_2, …, a_n written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n - 1 turns are made. The first player makes the first move, then players alternate t...
x = int(input()) l = [int(n) for n in input().split()] l.sort() i = 0 while len(l) > 1: if i % 2 == 0: l = l[0:len(l) - 1] else: l = l[1:len(l)] i = i + 1 print(l[0])
python
code_algorithm
[ { "input": "3\n2 2 2\n", "output": "2\n" }, { "input": "3\n2 1 3\n", "output": "2\n" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86\n", "output": "60\n" }, { "input": "9\n44 53 51 80 5 27 74 79 94\n", "output": "53\n" }, { "input": "3\n9 92 12\n", "output": "...
code_contests
python
0.8
c4d124f595a44772df2544f04300dda0