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
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text by the following rules: * if there is no punctuation mark between two wor...
import re s = input()+"a" s = re.sub('\s+', ' ', s) r = '.,?!' for i in r: t = s.split(i) s = "" for j in t: s += j.strip() + i + " " s = s[:-2] print(s[:-1])
python
code_algorithm
[ { "input": "galileo was born in pisa\n", "output": "galileo was born in pisa\n" }, { "input": "galileo galilei was an italian physicist ,mathematician,astronomer\n", "output": "galileo galilei was an italian physicist, mathematician, astronomer\n" }, { "input": "mck . gq dauqmi...
code_contests
python
0.2
efe1f42605c6e83bc9c1d0454352f067
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of n people. Each soldier registered himse...
n, m, x, y = map(int, input().split()) a_n = [i for i in map(int, input().split())] b_m = [i for i in map(int, input().split())] count = 0 result = [] i = 0 j = 0 while j < m and i < n: if b_m[j] > a_n[i] + y: i += 1 elif b_m[j] < a_n[i] - x: j += 1 else: count += 1 resu...
python
code_algorithm
[ { "input": "5 3 0 0\n1 2 3 3 4\n1 3 5\n", "output": "2\n1 1\n3 2\n" }, { "input": "3 3 2 2\n1 5 9\n3 5 7\n", "output": "3\n1 1\n2 2\n3 3\n" }, { "input": "33 23 17 2\n1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5\n10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 ...
code_contests
python
0.4
07f1324761331aa1f76c9599d3ca6e11
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to...
import os import sys from io import BytesIO, IOBase def main(): import bisect import math # import itertools # import heapq # from queue import PriorityQueue, LifoQueue, SimpleQueue # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' ALPHA = '...
python
code_algorithm
[ { "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "output": "0\n" }, { "input": "helloworld\n", "output": "0\n" }, { "input": "PRuvetSTAaYA\n", "output": "5\n" }, { "input": "yysxwlyqboatikfnpxczmpijziiojbvadlfozjqldssffcxdegyxfrvohoxvgsrvlzjlkcuffoeisrpvagxtbkapkpzcafadzzjd...
code_contests
python
0
59f91d32d3c3c7b300a58c09e237a56e
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that. The ...
import itertools import functools def allSubArrays(xs): n = len(xs) indices = list(range(n+1)) for i,j in itertools.combinations(indices,2): yield xs[i:j] n=int(input()) my_list=list(map(int,input().split(" "))) list_=list(allSubArrays(my_list)) for i in range(len(list_)): list_[i]=functools.red...
python
code_algorithm
[ { "input": "5\n1 2 1 1 2\n", "output": "3\n" }, { "input": "3\n1 2 7\n", "output": "7\n" }, { "input": "4\n4 2 4 8\n", "output": "14\n" }, { "input": "20\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10\n", "output": "15\n" }, { "input": "99\n3511 2076 9314 3598 7737 27...
code_contests
python
0.9
010d24ee45afa21e4d76f133e8007ac1
Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions...
import os import sys from io import BytesIO, IOBase 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.write if self.writabl...
python
code_algorithm
[ { "input": "6 2\nioi\n1 3\n", "output": "26\n" }, { "input": "5 2\nioi\n1 2\n", "output": "0\n" }, { "input": "10 4\ne\n1 2 9 10\n", "output": "308915776\n" }, { "input": "1 1\na\n1\n", "output": "1\n" }, { "input": "10 0\naaa\n", "output": "94665207\n" }, ...
code_contests
python
0
40b3142e9c5dfe0d6f545bd19d62e5db
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. ...
a,b,c,d,e,f=map(int,input().split()) print((a+b+c)**2-a**2-c**2-e**2)
python
code_algorithm
[ { "input": "1 2 1 2 1 2\n", "output": "13\n" }, { "input": "1 1 1 1 1 1\n", "output": "6\n" }, { "input": "30 36 36 32 34 38\n", "output": "7052\n" }, { "input": "125 7 128 8 124 11\n", "output": "20215\n" }, { "input": "7 1 7 3 5 3\n", "output": "102\n" }, ...
code_contests
python
0
d6837f09f003477ca83a1fa40db709d8
Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. Input The first line contai...
n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) a.sort(reverse=True) for i in range(n): m -= a[i] if m <= 0: print(i+1) exit()
python
code_algorithm
[ { "input": "3\n5\n2\n1\n3\n", "output": "2\n" }, { "input": "3\n6\n2\n3\n2\n", "output": "3\n" }, { "input": "2\n5\n5\n10\n", "output": "1\n" }, { "input": "70\n149\n5\n3\n3\n4\n6\n1\n2\n9\n8\n3\n1\n8\n4\n4\n3\n6\n10\n7\n1\n10\n8\n4\n9\n3\n8\n3\n2\n5\n1\n8\n6\n9\n10\n4\n8\n6\...
code_contests
python
0.8
aa5090af5fe027d61da1638b030ea16e
++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+ ++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>+++++++ +++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>.<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<< <<<<<>>>>>>>>>>>>>+.-<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<...
n=eval(input()) cnt=0 while n: a=n%8 n=n//8 if a==1: cnt+=1 print(cnt)
python
code_algorithm
[ { "input": "129\n", "output": "1\n" }, { "input": "398929\n", "output": "4\n" }, { "input": "23982\n", "output": "0\n" }, { "input": "262144\n", "output": "1\n" }, { "input": "299593\n", "output": "7\n" }, { "input": "9852\n", "output": "1\n" }, ...
code_contests
python
0
ec59cb4594a08e6096d06a2acc5d8143
Professor Phunsuk Wangdu has performed some experiments on rays. The setup for n rays is as follows. There is a rectangular box having exactly n holes on the opposite faces. All rays enter from the holes of the first side and exit from the holes of the other side of the box. Exactly one ray can enter or exit from each...
from bisect import bisect_left as bl I=10000000 n=int(input())+1 c=[0]*n for i,x in enumerate(map(int,input().split())): c[x]=i d = [n-c[int(x)] for x in input().split()] c=[I]*n for i in d: c[bl(c,i)]=i print( c.index(I))
python
code_algorithm
[ { "input": "3\n3 1 2\n2 3 1\n", "output": "2\n" }, { "input": "5\n1 4 5 2 3\n3 4 2 1 5\n", "output": "3\n" }, { "input": "3\n1 2 3\n1 3 2\n", "output": "2\n" }, { "input": "5\n1 2 4 5 3\n1 5 4 2 3\n", "output": "3\n" }, { "input": "5\n1 2 4 5 3\n1 2 5 4 3\n", ...
code_contests
python
0
6f1bc239117cb6ff9b4e4fc80539c416
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ...
c = int(input()) a = list(map(int, input().split())) res = 0 b = [] for i in range(len(a)): b.append(False) for i in range(len(a)): k = len(a) - i - 1 m = 0 while b[k] == False: b[k] = True k = a[k] - 1 m = 1 if (k == -1): break if m == 1: res...
python
code_algorithm
[ { "input": "2\n0 0\n", "output": "2\n" }, { "input": "5\n0 1 0 1 3\n", "output": "3\n" }, { "input": "1\n0\n", "output": "1\n" }, { "input": "14\n0 0 1 1 2 2 3 3 4 4 5 5 6 6\n", "output": "8\n" }, { "input": "2\n0 1\n", "output": "1\n" }, { "input": "1...
code_contests
python
0
16b76be7c75a5d0088f8ed8b99d73157
You are given two strings s and t, both consisting only of lowercase Latin letters. The substring s[l..r] is the string which is obtained by taking characters s_l, s_{l + 1}, ..., s_r without changing the order. Each of the occurrences of string a in a string b is a position i (1 ≤ i ≤ |b| - |a| + 1) such that b[i..i...
ch=input() l=list(map(int,ch.split())) m=l[0] n=l[1] p=l[2] s=input() t=input() l1=[] for i in range(p): ch=input() l1.append(ch) res=0 l2=[0] for i in range (len(t)-1): l2.append(0) for i in range ((len(t)-1),len(s)): if s[(i-len(t)+1):(i+1)]==t: res+=1 l2.append(re...
python
code_algorithm
[ { "input": "15 2 3\nabacabadabacaba\nba\n1 15\n3 4\n2 14\n", "output": "4\n0\n3\n" }, { "input": "10 3 4\ncodeforces\nfor\n1 3\n3 10\n5 6\n5 7\n", "output": "0\n1\n0\n1\n" }, { "input": "3 5 2\naaa\nbaaab\n1 3\n1 1\n", "output": "0\n0\n" }, { "input": "1 1 1\na\nb\n1 1\n", ...
code_contests
python
0.4
b3e00aee550d2ae8ebf0e743c95b89ce
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
inp = input().split() n = int(inp[0]) m = int(inp[1]) def dfs(x): visited.add(x) for y in e[x]: if not y in visited: dfs(y) if n >= 3 and n == m: visited = set() e = [[] for i in range(n + 1)] for i in range(m): x, y = map(int, input().split()) ...
python
code_algorithm
[ { "input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n", "output": "NO\n" }, { "input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n", "output": "FHTAGN!\n" }, { "input": "100 66\n41 14\n19 13\n70 43\n79 62\n9 62\n71 40\n53 86\n80 4\n34 33\n72 68\n40 96\n84 59\n36 77\n55 50\n40 3\n79 81\n3 43\n33 47\n22 98\...
code_contests
python
0
39afaa84fce342330771175ca06ceb8c
The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by s liters of kvass. But ...
x,y=map(int,input().split()) s=list(map(int,input().split())) if sum(s)<y: print(-1) else: j=sum(s)-y if j<x: print(0) elif x==j: print(1) else: print(min(min(s),j//x))
python
code_algorithm
[ { "input": "3 4\n5 3 4\n", "output": "2\n" }, { "input": "3 3\n4 3 5\n", "output": "3\n" }, { "input": "3 7\n1 2 3\n", "output": "-1\n" }, { "input": "5 1\n1 1 1 1 1000\n", "output": "1\n" }, { "input": "4 2\n5 7 8 9\n", "output": "5\n" }, { "input": "...
code_contests
python
0.1
4335f30cc6d1531192a3636f805be321
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens: * Two numbers i and...
N, T = map(int, input().split()) A = [int(a) for a in input().split()] if sum(A) > N//2: A = [1-a for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9+7 inv = pow(N*(N-1)//2, P-2, P) X = [[0]*M for _ in range(M)] for i in range(M): if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P if i < M-1: X[i+1][i] =...
python
code_algorithm
[ { "input": "3 2\n0 1 0\n", "output": "333333336\n" }, { "input": "5 1\n1 1 1 0 0\n", "output": "0\n" }, { "input": "6 4\n1 0 0 1 1 0\n", "output": "968493834\n" }, { "input": "39 67\n1 0 1 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 0 1\n", "output...
code_contests
python
0
3363689c25073cb930caf9634bc42ceb
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In this problem, we use one digit and one lowercase letter, which is the first c...
string = input().split() first = string[0] second = string[1] third = string[2] string.sort(key=lambda x: int(x[0])) if first == second == third or first[1] == second[1] == third[1] and all(int(string[i][0]) == int(string[i - 1][0]) + 1 for i in range(1, 3)): print(0) elif (first == second or second == third or thi...
python
code_algorithm
[ { "input": "3p 9m 2p\n", "output": "1\n" }, { "input": "9m 9m 9m\n", "output": "0\n" }, { "input": "1s 2s 3s\n", "output": "0\n" }, { "input": "2m 9s 1m\n", "output": "1\n" }, { "input": "1m 1m 2m\n", "output": "1\n" }, { "input": "3p 9p 4m\n", "ou...
code_contests
python
0
0da5f016c85a3325f30de96fa6f682d8
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100)...
for _ in range(int(input())): n=int(input()) i=1 c=2 l=[] y=n while(i<=2): if n%c==0: n=n//c i=i+1 l.append(c) if c>=y**0.5: break c=c+1 if l==[] or len(l)==1: print("NO") elif y%(l[0]*l[1])==0: x=y//...
python
code_algorithm
[ { "input": "5\n64\n32\n97\n2\n12345\n", "output": "YES\n2 4 8\nNO\nNO\nNO\nYES\n3 5 823\n" }, { "input": "6\n10\n10\n10\n10\n10\n10\n", "output": "NO\nNO\nNO\nNO\nNO\nNO\n" }, { "input": "1\n1112\n", "output": "YES\n2 4 139\n" }, { "input": "100\n121\n122\n123\n124\n125\n126\...
code_contests
python
1
d19cf17ed1cc18f9e3f6cafc5d39ca42
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
#------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUF...
python
code_algorithm
[ { "input": "2 1\na\na\na\na\na\na\ne\ne\n", "output": "aabb\n" }, { "input": "1 1\nday\nmay\ngray\nway\n", "output": "aaaa\n" }, { "input": "1 1\nday\nmay\nsun\nfun\n", "output": "aabb\n" }, { "input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill\n", "output": "NO\n...
code_contests
python
0
11caca3ce4f969da1aa2eccb0f7d1d0f
<image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 Write Python code to solve the problem. Present the code in the code block: ```python Your code ``` Write Python code to solve the problem. Present the ...
def star(n): a, b = 1, 12 for i in range(2, n + 1): a += b b += 12 return a print(star(int(input())))
python
code_algorithm
[ { "input": "2\n", "output": "13\n" }, { "input": "3823\n", "output": "87669037\n" }, { "input": "3994\n", "output": "95688253\n" }, { "input": "8543\n", "output": "437845837\n" }, { "input": "12504\n", "output": "938025073\n" }, { "input": "3202\n", ...
code_contests
python
0
01e44cd1c82f33dccf7426e416695f9c
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the follows. Given n points in the plane, find a pair of points between...
n,k = map(int,input().split()) if n*(n-1) <= k*2: print('no solution') else: for i in range(n): print(0,i)
python
code_algorithm
[ { "input": "2 100\n", "output": "no solution\n" }, { "input": "4 3\n", "output": "0 0\n0 1\n0 2\n0 3\n" }, { "input": "1657 1371995\n", "output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n0 10\n0 11\n0 12\n0 13\n0 14\n0 15\n0 16\n0 17\n0 18\n0 19\n0 20\n0 21\n0 22\n0 23\n0 2...
code_contests
python
0
ee2bb13aa12624a3bcf0d01b01fa2ca6
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them...
n = int(input()) lst = list(map(int,input().split())) a = list(zip(lst,lst[1:])) record = [] for x in a: s,e = min(x[0],x[1]),max(x[0],x[1]) for y in record: if y[0]<s<y[1]<e or s<y[0]<e<y[1]: exit(print("yes")) record.append((s,e)) print("no")
python
code_algorithm
[ { "input": "4\n0 10 5 15\n", "output": "yes\n" }, { "input": "4\n0 15 5 10\n", "output": "no\n" }, { "input": "4\n3 1 4 2\n", "output": "yes\n" }, { "input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8\n", "output": "no\n" }, { "input": "10\n3 2 4 5 1 6 9 7 8 10\n", ...
code_contests
python
0
ae28009a4eb061ed087438b02f734fff
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po...
x1,y1 = [int(i) for i in input().split()] x2,y2 = [int(i) for i in input().split()] n = int(input()) m = 0 for i in range(n): x,y,c = [int(g) for g in input().split()] if(x1*x+y1*y+c>0): l = 1 else: l = -1 if(l==-1)and(x2*x+y2*y+c>0): m+=1 elif(l==1)and(x2*x+y2*y+c<0): ...
python
code_algorithm
[ { "input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3\n", "output": "2\n" }, { "input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0\n", "output": "2\n" }, { "input": "0 1\n2 2\n1\n1 1 2\n", "output": "0\n" }, { "input": "1 1\n-1 -1\n1\n1 1 0\n", "output": "1\n" }, { "input": "1 1\n3 3...
code_contests
python
0.5
8c24eebaacb34b7beb354cb0c97be0be
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is directed upwards. Each cube is associated with the coordinates of its lower le...
import heapq def coor_neighbor(coor, dxs, dys): x, y = coor for dx in dxs: for dy in dys: yield x + dx, y + dy def coor_bottoms(coor): return coor_neighbor(coor, (-1, 0, 1), (-1, )) def coor_tops(coor): return coor_neighbor(coor, (-1, 0, 1), (1, )) def coor_sibs(coor): ret...
python
code_algorithm
[ { "input": "3\n2 1\n1 0\n0 1\n", "output": "19\n" }, { "input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "output": "2930\n" }, { "input": "2\n72098079 0\n72098078 1\n", "output": "2\n" }, { "input": "2\n-32566075 1\n-32566075 0\n", "output": "1\n" }, { "input": "15\n-49118...
code_contests
python
0
5fce9995ff32649453539fd8f3b0633e
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. <image> A group of bears is a non-empty contiguous segment of the line. The size of ...
from sys import stdin, stdout def input(): return stdin.readline().strip() def print(x, end='\n'): stdout.write(str(x) + end) n, lst = int(input()), list(map(int, input().split())) nse, pse, stk, ans = [n for i in range(n)], [-1 for i in range(n)], [], [0 for i in range(n+1)] for i in range(n): while stk and lst[s...
python
code_algorithm
[ { "input": "10\n1 2 3 4 5 4 3 2 1 6\n", "output": "6 4 4 3 3 2 2 1 1 1\n" }, { "input": "19\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759\n", "output":...
code_contests
python
0
d539599c3cc6d8cfbceea8e03839610e
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know l...
from sys import * setrecursionlimit(200000) d = {} t = set() s = input() + ' ' def gen(l, ll): if (l, ll) in t: return t.add((l, ll)) if l > 6: d[s[l - 2 : l]] = 1 if s[l - 2 : l] != s[l : ll]: gen(l - 2, l) if l > 7: d[s[l - 3 : l]] = 1 if s[l - 3 : l] != s[l : ll]: gen(...
python
code_algorithm
[ { "input": "abaca\n", "output": "0\n" }, { "input": "abacabaca\n", "output": "3\naca\nba\nca\n" }, { "input": "hzobjysjhbebobkoror\n", "output": "20\nbe\nbeb\nbko\nbo\nbob\neb\nebo\nhb\nhbe\njh\njhb\nko\nkor\nob\nor\nror\nsj\nsjh\nys\nysj\n" }, { "input": "bbbbbccaaaaaa\n", ...
code_contests
python
0
97015a420a4d674687c585e41a42a722
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such th...
x, y = map(int, input().split()) a, b, c = y, y, y cnt = 0 while True: if a >= x and b >= x and c >= x: break cnt += 1 if cnt % 3 == 0: a = b+c - 1 elif cnt % 3 == 1: b = c + a - 1 elif cnt % 3 == 2: c = b+a - 1 print(cnt)
python
code_algorithm
[ { "input": "8 5\n", "output": "3\n" }, { "input": "22 4\n", "output": "6\n" }, { "input": "6 3\n", "output": "4\n" }, { "input": "75749 55910\n", "output": "3\n" }, { "input": "70434 39286\n", "output": "3\n" }, { "input": "15332 5489\n", "output":...
code_contests
python
0
3b87ec764bde97fcf2f2172cd765277d
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
n = int(input()) L, R = 0, 0 D = [] for i in range(n): l, r = map(int, input().split()) L += l R += r D.append((l, r)) ans = abs(L - R) num = 0 for i in range(n): l, r = D[i] L1 = L - l + r R1 = R - r + l if ans < abs(L1 - R1): ans = abs(L1 - R1) num = i + 1 print(num)
python
code_algorithm
[ { "input": "2\n6 5\n5 6\n", "output": "1\n" }, { "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n", "output": "0\n" }, { "input": "3\n5 6\n8 9\n10 3\n", "output": "3\n" }, { "input": "10\n18 18\n71 471\n121 362\n467 107\n138 254\n13 337\n499 373\n337 387\n147 417\n76 417\n", ...
code_contests
python
1
97be6800e90bf372f6f988200e513e6b
It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in t...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict,Counter from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10...
python
code_algorithm
[ { "input": "1 3\n3 1 2 3\n", "output": "6\n" }, { "input": "2 3\n2 1 2\n2 2 3\n", "output": "1\n" }, { "input": "2 2\n3 2 2 1\n2 1 2\n", "output": "1\n" }, { "input": "3 7\n2 1 2\n2 3 4\n3 5 6 7\n", "output": "24\n" }, { "input": "2 4\n2 1 2\n3 2 3 4\n", "outp...
code_contests
python
0
80b046026c542d8fb01256941a236cb4
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
import sys def main(): n, w, h = map(int, sys.stdin.readline().split()) gv = {} gh = {} for i in range(n): g, p, t = map(int, sys.stdin.readline().split()) c = p - t t = (g, p, -t, i) if g == 1: if c in gv: gv[c].append(t) else: ...
python
code_algorithm
[ { "input": "3 2 3\n1 1 2\n2 1 1\n1 1 5\n", "output": "1 3\n2 1\n1 3\n" }, { "input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n", "output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n" }, { "input": "5 20 20\n1 15 3\n2 15 3\n2 3 1\n2 1 0\n1 16 4\n", "outpu...
code_contests
python
0
63e1c04cd419f51d113f454ed9b2a513
In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along the corridor, and all sections with equal numbers on different floors are l...
import bisect as bs import sys inp = sys.stdin.readlines() n, m, ladders, elevators, v = [int(x) for x in inp[0].strip().split()] ladders = [int(x) for x in inp[1].strip().split()] elevators = [int(x) for x in inp[2].strip().split()] q = int(inp[3].strip()) qs = [] for i in range(q): qs.append([int(x) for x in in...
python
code_algorithm
[ { "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n", "output": "7\n5\n4\n" }, { "input": "1000 1000 1 1 10\n1\n2\n1\n1 900 1 1000\n", "output": "100\n" }, { "input": "2 4 1 1 1\n1\n4\n1\n1 2 1 3\n", "output": "1\n" }, { "input": "10 10 1 8 4\n10\n2 3 4 5 6 7 8 9\n10\...
code_contests
python
0.1
dc6ab0680aaba2dcc60202f47422f4ee
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array [10, 20, 30, 40], we can pe...
n = int(input().strip()) a = list(map(int, input().strip().split())) a.sort() cnt = 0 que = [] l = 0 for i in a: if l == 0: que.append(i) l += 1 else: if i != que[0]: que.append(i) del que[0] cnt += 1 else: que.append(i) l += 1 print(cnt)
python
code_algorithm
[ { "input": "7\n10 1 1 1 5 5 3\n", "output": "4\n" }, { "input": "5\n1 1 1 1 1\n", "output": "0\n" }, { "input": "5\n1 5 4 2 3\n", "output": "4\n" }, { "input": "1\n1\n", "output": "0\n" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000...
code_contests
python
0.3
534c2426509e0736533739c30ea2893e
You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into w× h cells. There should be k gilded rings, the first one should go along the edge of the plate, the second one — 2 cells away from the edge and so on. Each ring has a width of 1 cell. Formally, the i-th of these rings ...
w, h, k = input().split() w = int(w) h = int(h) k = int(k) s = 0 for i in range(k): k = 2*w + 2*h - 4 - 16*i s = s + k print(s)
python
code_algorithm
[ { "input": "7 9 2\n", "output": "40\n" }, { "input": "7 9 1\n", "output": "28\n" }, { "input": "3 3 1\n", "output": "8\n" }, { "input": "4 3 1\n", "output": "10\n" }, { "input": "8 100 2\n", "output": "408\n" }, { "input": "63 34 8\n", "output": "1...
code_contests
python
0.9
27218d3bc23bec0f122c307d5804d3d3
Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor x, Egor on the floor y (not on the same floor with Masha). The house has a staircase and an elevator. If Masha u...
x,y,z,tuno,tdos,ttres=map(int,input().split()) var1=(x-y) stair=abs(var1)*tuno var2=(x-z) eleva=(3*ttres)+((abs(var2))*tdos)+((abs(var1))*tdos) if stair >= eleva: print("YES") else: print("NO")
python
code_algorithm
[ { "input": "1 6 6 2 1 1\n", "output": "NO\n" }, { "input": "5 1 4 4 2 1\n", "output": "YES\n" }, { "input": "4 1 7 4 1 2\n", "output": "YES\n" }, { "input": "437 169 136 492 353 94\n", "output": "NO\n" }, { "input": "188 288 112 595 331 414\n", "output": "YES\...
code_contests
python
0.1
c8f717e8324d558e73dc7f2393db7de2
You are given a string s consisting of n lowercase Latin letters. You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation. String s = s_1 s_2 ... s_n is lexicograp...
import sys, threading sys.setrecursionlimit(10 ** 6) scan = lambda: map(int, input().split()) n = int(input()) string = input() ans = string for i in range(n-1): if string[i] > string[i+1]: print(string[0:i]+string[i+1:n]) exit(0) print(string[0:n-1])
python
code_algorithm
[ { "input": "5\nabcda\n", "output": "abca\n" }, { "input": "3\naaa\n", "output": "aa\n" }, { "input": "3\nabc\n", "output": "ab\n" }, { "input": "2\ncq\n", "output": "c\n" }, { "input": "5\naaccd\n", "output": "aacc\n" }, { "input": "5\nbbbbd\n", "o...
code_contests
python
0.9
b9f04077edf8c29115ce70dcb79ff08d
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau". To play Mau-Mau, you need a pack of 52 cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or ...
n = str(input()) alist = input().split(' ') for i in alist: if i[0] == n[0]: print('YES') exit(0) elif i[-1] == n[-1]: print('YES') exit(0) print('NO')
python
code_algorithm
[ { "input": "AS\n2H 4C TH JH AD\n", "output": "YES\n" }, { "input": "2H\n3D 4C AC KD AS\n", "output": "NO\n" }, { "input": "4D\nAS AC AD AH 5H\n", "output": "YES\n" }, { "input": "KH\n3C QD 9S KS 8D\n", "output": "YES\n" }, { "input": "2S\n2D 3D 4D 5D 6D\n", "o...
code_contests
python
0.7
392056341b8fce8a67649fe51c589b1f
Tanya has n candies numbered from 1 to n. The i-th candy has the weight a_i. She plans to eat exactly n-1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day. Your task is to find the number of such candies i (let's call these candies goo...
N , vals= int(input()),list(map(int, input().split())) odds, evens = 0,0 for i in range(N): if i % 2 == 0: odds += vals[i] else: evens += vals[i] odds, evens, num_good = evens, odds-vals[0],0 if odds == evens: num_good+=1 for i in range(1,N): if i % 2 == 1: odds = odds - vals[i] + vals[i-1] else: ...
python
code_algorithm
[ { "input": "7\n5 5 4 5 5 5 6\n", "output": "2\n" }, { "input": "9\n2 3 4 2 2 3 2 2 4\n", "output": "3\n" }, { "input": "8\n4 8 8 7 8 4 4 5\n", "output": "2\n" }, { "input": "1\n6575\n", "output": "1\n" }, { "input": "1\n100\n", "output": "1\n" }, { "in...
code_contests
python
0.8
fbf4f2a26257f22fe338db4657182ef8
We guessed some integer number x. You are given a list of almost all its divisors. Almost all means that there are all divisors except 1 and x in the list. Your task is to find the minimum possible integer x that can be the guessed number, or say that the input data is contradictory and it is impossible to find such n...
def divisors(num): """ 約数全列挙 """ divisors = [] for i in range(1, int(num ** 0.5) + 1): if num % i == 0: divisors.append(i) if i != num // i: divisors.append(num // i) return divisors T = int(input()) for t in range(T): N = int(input()) d...
python
code_algorithm
[ { "input": "2\n8\n8 2 12 6 4 24 16 3\n1\n2\n", "output": "48\n4\n" }, { "input": "25\n1\n19\n1\n2\n1\n4\n2\n2 4\n1\n5\n2\n2 5\n2\n4 5\n3\n5 2 4\n1\n10\n2\n2 10\n2\n10 4\n3\n2 10 4\n2\n10 5\n3\n2 5 10\n3\n10 4 5\n4\n2 5 10 4\n1\n20\n2\n20 2\n2\n4 20\n3\n4 2 20\n2\n5 20\n3\n2 20 5\n3\n5 20 4\n4\n4 2 5...
code_contests
python
0.1
39cc1ab97beddbb73948c3b2b284486b
You are given a uppercase Latin letters 'A' and b letters 'B'. The period of the string is the smallest such positive integer k that s_i = s_{i~mod~k} (0-indexed) for each i. Note that this implies that k won't always divide a+b = |s|. For example, the period of string "ABAABAA" is 3, the period of "AAAA" is 1, and t...
import math a,b= map(int,input().split()) n=a+b ans,l=0,1 while l<=n: g= n//l if a<g or b<g: l= (n//g) +1 continue r= n//g a_low = (a+g)//(g+1) a_high = a//g b_low=(b+g)//(g+1) b_high = b//g if (a_low <= a_high and b_low <= b_high): ans += max(0,min(r,a_high+b_hig...
python
code_algorithm
[ { "input": "5 3\n", "output": "5\n" }, { "input": "2 4\n", "output": "4\n" }, { "input": "1 1\n", "output": "1\n" }, { "input": "943610806 943610807\n", "output": "1887160182\n" }, { "input": "49464524 956817411\n", "output": "1006177186\n" }, { "input...
code_contests
python
0
4b3e37e35ea64121ab8ea9ec4804609b
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of n digits without leading zeroes. He represented it as an array of d...
import sys input=sys.stdin.readline from math import * n,m=map(int,input().split()) s=list(input().rstrip()) for i in range(n-1): if m==0: break if i>0: if s[i-1]=='4' and s[i]=='4' and s[i+1]=='7' and i%2==1: if m%2==1: s[i]='7' break if s[i]=='4' a...
python
code_algorithm
[ { "input": "7 4\n4727447\n", "output": "4427477\n" }, { "input": "4 2\n4478\n", "output": "4478\n" }, { "input": "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773\n", "output": "44437850490316923506619313449771062875964157742919669484484624083960118773...
code_contests
python
0.1
13b7bb3a2fa26c6b74e81fb469268d50
Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with n rows and m columns. Each cell is either black or white. For each iteration of the game (the initial iteration is 0), the color of...
import sys input = sys.stdin.readline n,m,t=map(int,input().split()) MAP=[input().strip() for i in range(n)] COUNT=[[-1]*m for i in range(n)] from collections import deque Q=deque() for i in range(n): for j in range(m): for z,w in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]: if 0<=z<n and 0<=w<m and MA...
python
code_algorithm
[ { "input": "1 1 3\n0\n1 1 1\n1 1 2\n1 1 3\n", "output": "0\n0\n0\n" }, { "input": "3 3 3\n000\n111\n000\n1 1 1\n2 2 2\n3 3 3\n", "output": "1\n1\n1\n" }, { "input": "5 5 3\n01011\n10110\n01101\n11010\n10101\n1 1 4\n1 2 3\n5 5 3\n", "output": "1\n0\n1\n" }, { "input": "5 2 2\n...
code_contests
python
0
19f27dd7f5d6fdfa28be73c521fe8655
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret! A password is an array a of n positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them ...
for _ in range(int(input())): n = int(input()) s = list(map(int,input().split())) #a,b = map(int,input().split()) k = set(s) if len(list(k)) == 1: print(n) else: print(1)
python
code_algorithm
[ { "input": "2\n4\n2 1 3 1\n2\n420 420\n", "output": "1\n2\n" }, { "input": "1\n4\n1 2 2 1\n", "output": "1\n" }, { "input": "1\n7\n529035968 529035968 529035968 529035968 529035968 529035968 529035968\n", "output": "7\n" }, { "input": "80\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n...
code_contests
python
0.6
054b66e06494c4fd0c2e8475cd37d7f1
You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). An inversion i...
n=int(input()) l=input().split() li=[int(i) for i in l] xori=0 ans=0 mul=1 for i in range(32): hashi1=dict() hashi0=dict() inv1=0 inv2=0 for j in li: if(j//2 in hashi1 and j%2==0): inv1+=hashi1[j//2] if(j//2 in hashi0 and j%2==1): inv2+=hashi0[j//2] if...
python
code_algorithm
[ { "input": "3\n8 10 3\n", "output": "0 8\n" }, { "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n" }, { "input": "4\n0 1 3 2\n", "output": "1 0\n" }, { "input": "96\n79 50 37 49 30 58 90 41 77 73 31 10 8 57 73 90 86 73 72 5 43 15 11 2 59 31 38 66 19 63 33 17 14 16 44 3 ...
code_contests
python
0
0397ebc1ab65f42db1823feeb1bc7e7a
The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: * d1 is the distance between the 1-st and the 2-nd station; * d2 is the distance between the 2-nd and the 3-rd station; ... * dn - 1 is the distance between the n - 1-th and the n-th station; ...
n = int(input()) a = list(map(int, input().split())) s, t = sorted(map(int, input().split())) print(min(sum(a[s-1:t-1]), sum(a[:s-1])+sum(a[t-1:])))
python
code_algorithm
[ { "input": "3\n31 41 59\n1 1\n", "output": "0\n" }, { "input": "4\n5 8 2 100\n4 1\n", "output": "15\n" }, { "input": "4\n2 3 4 9\n1 3\n", "output": "5\n" }, { "input": "3\n1 1 1\n3 1\n", "output": "1\n" }, { "input": "3\n4 37 33\n3 3\n", "output": "0\n" }, ...
code_contests
python
1
d09662757a1ae6b30ae2d45235447fbd
Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are n types of monsters, each with an ID between 1 and n. If you feed a pie to a monster, the monster will split into some number of monsters (possibly zero), and at least one colorful diamond. Monster...
import sys, heapq _BLANCO, _GRIS, _NEGRO = 0, 1, 2 _OO = int(1e18) class Regla: def __init__(self, id, diamantes, deMonstruo, monstruos): self.id = id self.diamantes = diamantes self.deMonstruo = deMonstruo self.monstruos = monstruos def clonar(self): return Regla(sel...
python
code_algorithm
[ { "input": "3 2\n1 2 1 -1\n2 2 -1 -1\n2 3 2 1 -1\n", "output": "-1 -1\n2 2\n" }, { "input": "6 4\n1 3 -1 1 -1\n1 2 -1 -1\n2 3 -1 3 -1\n2 3 -1 -1 -1\n3 2 -1 -1\n4 2 4 -1\n", "output": "2 -2\n3 4\n2 2\n-1 -1\n" }, { "input": "4 1\n1 3 -1 -1 -1\n1 2 -1 -1\n1 4 -1 -1 -1 -1\n1 3 -1 -1 -1\n", ...
code_contests
python
0
d4fe29f90a9de0513828e7a544e372d0
Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter! The President of Berland was forced to leave only k of the currently existing n subway stations. The subway stations are located on a straight lin...
from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x],str(x+1)) for x in range(n)]) k = int(stdin.readline()) sums = [0] for x in a: sums.append(sums[-1]+x[0]) total = 0 s = 0 for x in range(k): total += a[x][0]*x-s s += a[x][0] low = total low...
python
code_algorithm
[ { "input": "3\n1 100 101\n2\n", "output": "2 3\n" }, { "input": "5\n-4 -2 10 -9 -10\n2\n", "output": "5 4\n" }, { "input": "4\n5 -7 8 1\n2\n", "output": "1 3\n" }, { "input": "100\n-608 705 341 641 -64 309 -990 319 -240 -350 -570 813 537 -296 -388 131 187 98 573 -572 484 -774...
code_contests
python
0.4
f04703ca4ab3f937139c645474346141
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to ti...
ls=list(input()) d=list(dict.fromkeys(ls)) if(len(d)==2): print(0) elif(len(d)==3): print(1) else: print(len(d)-4)
python
code_algorithm
[ { "input": "{a, b, c}\n", "output": "3\n" }, { "input": "{b, a, b, a}\n", "output": "2\n" }, { "input": "{}\n", "output": "0\n" }, { "input": "{a, b, z}\n", "output": "3\n" }, { "input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, ...
code_contests
python
0
bf1317f7dbc4a671689de82aad0b3b44
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows...
n=int(input()) z=list(map(int,input().split())) ##y=[] ##for i in z : ## y.append(i) ##y.reverse() ##kevin=y.index(1) count=0 for i in range(n) : if z[i]==1 : count+=1 if i+1!=n : if z[i+1]==0 : count+=1 else : counti=1 if ...
python
code_algorithm
[ { "input": "2\n0 0\n", "output": "0\n" }, { "input": "5\n1 1 0 0 1\n", "output": "4\n" }, { "input": "5\n0 1 0 1 0\n", "output": "3\n" }, { "input": "5\n1 1 1 1 1\n", "output": "5\n" }, { "input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ...
code_contests
python
0
ecb756a4cf85bac2100403c21787f2a8
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number of sw...
n = int(input()) arr = list(map(int,input().split())) ans = [] for i in range(n): k = i for j in range(i+1,n): if arr[j]<arr[k]: k=j if k!=i: arr[k],arr[i]=arr[i],arr[k] ans.append([i,k]) print(len(ans)) if len(ans)>0: for i in ans: print(*i)
python
code_algorithm
[ { "input": "2\n101 100\n", "output": "1\n0 1\n" }, { "input": "6\n10 20 20 40 60 60\n", "output": "0\n" }, { "input": "5\n5 2 5 1 4\n", "output": "2\n0 3\n2 4\n" }, { "input": "5\n10 30 20 50 40\n", "output": "2\n1 2\n3 4\n" }, { "input": "5\n1000000000 -10000000 ...
code_contests
python
0.2
0b3940e44de16afac0a72589b97dfdbd
After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-based fights of big squadrons of enemies on infinite fields where every cel...
n = int(input()) n += 1 print(1 + 6 * n * (n-1) // 2)
python
code_algorithm
[ { "input": "2\n", "output": "19\n" }, { "input": "748629743\n", "output": "1681339478558627377\n" }, { "input": "3\n", "output": "37\n" }, { "input": "999999999\n", "output": "2999999997000000001\n" }, { "input": "900000000\n", "output": "2430000002700000001\n...
code_contests
python
1
ea4e0c069e3422a3fe6399f396ef821e
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty — it'...
n,c = map(int,input().split()) p=input().split() t=input().split() sl=0 sr=0 ti=0 for i in range(n): ti+=int(t[i]) if int(p[i])-c*ti>=0: sl+=int(p[i])-c*ti ti=0 for i in range(n): ti+=int(t[n-i-1]) if int(p[n-i-1])-c*ti>=0: sr+=int(p[n-i-1])-c*ti if sl == sr: print('Tie') elif sl>sr:...
python
code_algorithm
[ { "input": "3 2\n50 85 250\n10 15 25\n", "output": "Limak\n" }, { "input": "3 6\n50 85 250\n10 15 25\n", "output": "Radewoosh\n" }, { "input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n", "output": "Tie\n" }, { "input": "1 36\n312\n42\n", "output": "Tie\n" ...
code_contests
python
0.9
f2517c14bd4d66a1f18358bd6b23425a
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of n cities, k of whose (just imagine!) are capital cities. 2. All of cities ...
from collections import * import os, sys from io import BytesIO, IOBase def main(): n, k = rints() a, b = rints(), set(rints()) su, ans, su2 = sum(a), 0, 0 for i in b: ans += a[i - 1] * (su - a[i - 1]) su2 += a[i - 1] for i in range(n): if i + 1 not in b: x, y...
python
code_algorithm
[ { "input": "4 1\n2 3 1 2\n3\n", "output": "17\n" }, { "input": "5 2\n3 5 2 2 4\n1 4\n", "output": "71\n" }, { "input": "7 7\n6 9 2 7 4 8 7\n1 2 3 4 5 6 7\n", "output": "775\n" }, { "input": "73 27\n651 944 104 639 369 961 338 573 516 690 889 227 480 160 299 783 270 331 793 79...
code_contests
python
0
e0cb3c5125bc5c75f2490c68c43db220
There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for whi...
n = int(input()) s, p = {}, [''] * n for k in range(n): p[k] = t = input() for q in [t[i: j] for i in range(9) for j in range(i + 1, 10)]: s[q] = -1 if q in s and s[q] != k else k for q, k in s.items(): if k >= 0 and len(p[k]) > len(q): p[k] = q print('\n'.join(p)) # Made By Mostafa_Khale...
python
code_algorithm
[ { "input": "3\n123456789\n100000000\n100123456\n", "output": "7\n000\n01\n" }, { "input": "4\n123456789\n193456789\n134567819\n934567891\n", "output": "2\n193\n13\n91\n" }, { "input": "5\n774610315\n325796798\n989859836\n707706423\n310546337\n", "output": "74\n32\n89\n70\n05\n" }, ...
code_contests
python
0.2
28dfb36924bedfc16b4b37838be15468
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi...
n=list(input()) m=len(n) e=0 s=1 if n.count('1')==0: s=0 for i in range(0,m): if n[i]=='1': e=i break k=n[e:] if s==1: if k.count('0')>=6: print('yes') else: print('no') else: print('no')
python
code_algorithm
[ { "input": "100\n", "output": "no\n" }, { "input": "100010001\n", "output": "yes\n" }, { "input": "0000000010\n", "output": "no\n" }, { "input": "000000000000001\n", "output": "no\n" }, { "input": "0000000000000000010\n", "output": "no\n" }, { "input":...
code_contests
python
0.2
cda0d0097dc470af87164bf246b2cdbe
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 Counter tree = [] class Node: def __init__(self, num=None): self.length = 0 if num is None else tree[num-1].length + 1 def main(): n = int(input()) global tree tree = [Node()] for x in input().split(): tree.append(Node(int(x))) print(sum([value & 1 ...
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": "10\n1 2 3 4 5 5 5 7 9\n", "output": "8\n" }, { "input": "50\n1 1 3 3 4 5 5 2 4 3 9 9 1 5...
code_contests
python
0.1
4c80cfadc39cfe987ac73cab3bdf8822
You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through infinity from left to right. Obviously, there is not enough sand o...
from math import ceil, sqrt n, H = map(int, input().split(' ')) k = ceil(0.5*(sqrt(8*n+1)-1)) while k*k+k >= 2*n: k -= 1 while k*k+k < 2*n: k += 1 if k <= H: print(k) else: k = ceil(sqrt(2*H*H-2*H+4*n)-H) if (k - H) % 2 == 1: k += 1 a = (k-H)//2 while (H+a)*(H+a+1) + (H+a-1)*(H...
python
code_algorithm
[ { "input": "5 2\n", "output": "3\n" }, { "input": "6 8\n", "output": "3\n" }, { "input": "1000000000000000000 1000000000000000000\n", "output": "1414213562\n" }, { "input": "1000000000000000000 1\n", "output": "1999999999\n" }, { "input": "6 100\n", "output": ...
code_contests
python
0
bd787dc185b51dde30bcb1ff0535c41a
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2, where (x_1, y_1) and (x...
n = int(input()) a = [int(x) for x in input().split()] a.sort() top = [a[0], a[-1]] right = [a[n - 1], a[n]] case2 = abs((top[0] - right[0])*(top[1] - right[1])) case1 = top[-1] - top[0] mny = 10000000000 for i in range(1, n): mny = min(mny, abs(a[i] - a[i + n-1])) #print(mny) case1 *= mny print(min(abs(cas...
python
code_algorithm
[ { "input": "4\n4 1 3 2 3 2 1 3\n", "output": "1\n" }, { "input": "3\n5 8 5 5 7 5\n", "output": "0\n" }, { "input": "2\n100000001 95312501 97600001 1\n", "output": "228750000000000\n" }, { "input": "1\n1000000000 1000000000\n", "output": "0\n" }, { "input": "2\n814...
code_contests
python
0
9fe8524e15b5290ece20dd721fcd8da3
You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase. A subsequence of string s is a string that can be derived from s by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD...
n,k = list(map(int,input().strip().split())) s = input() letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] L = letters[:k] counts = {} for x in L: counts[x] = s.count(x) print(min([counts[j] for j in L])*k)
python
code_algorithm
[ { "input": "9 4\nABCABCABC\n", "output": "0\n" }, { "input": "9 3\nACAABCCAB\n", "output": "6\n" }, { "input": "3 2\nBBB\n", "output": "0\n" }, { "input": "1 4\nD\n", "output": "0\n" }, { "input": "6 3\nABBCCC\n", "output": "3\n" }, { "input": "3 5\nAB...
code_contests
python
0.9
91c7d27d6875d8ddef9a9de2365611fd
Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvements he can think of during the day (he now prefers to sleep at nigh...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def main(): n = int(input()) path = [[] for _ in range(n)] for _ in range(n-1): a1,b1 = map(lambda xx:int(xx)-1,input().split()) path[a1].append(b1) path[b1].append(a1) st,poi...
python
code_algorithm
[ { "input": "4\n1 2\n1 3\n1 4\n", "output": "6\n" }, { "input": "4\n1 2\n2 3\n3 4\n", "output": "7\n" }, { "input": "10\n2 3\n3 9\n6 3\n9 8\n9 10\n4 8\n3 1\n3 5\n7 1\n", "output": "67\n" }, { "input": "3\n2 1\n3 2\n", "output": "3\n" }, { "input": "2\n2 1\n", "...
code_contests
python
0.1
69cbfe651a78dbf6d01bd751ec7260cc
A multi-subject competition is coming! The competition has m different subjects participants can choose from. That's why Alex (the coach) should form a competition delegation among his students. He has n candidates. For the i-th person he knows subject s_i the candidate specializes in and r_i — a skill level in his s...
import sys input=sys.stdin.readline n, m = map(int, input().split()) s = [[] for _ in range(m)] size = [0]*m for _ in range(n): si, ri = map(int, input().split()) s[si-1].append(ri) size[si-1] += 1 # print(s) # print(size) sa = max(size) # print(sa) i = 0 ans = [0]*sa # print("ans",ans) for i in range(m)...
python
code_algorithm
[ { "input": "5 2\n1 -1\n1 -5\n2 -1\n2 -1\n1 -10\n", "output": "0\n" }, { "input": "6 3\n2 6\n3 6\n2 5\n3 5\n1 9\n3 1\n", "output": "22\n" }, { "input": "5 3\n2 6\n3 6\n2 5\n3 5\n1 11\n", "output": "23\n" }, { "input": "15 9\n9 0\n5 3\n2 -1\n2 -1\n6 -1\n9 -2\n6 0\n6 2\n1 -2\n1 ...
code_contests
python
0.2
73b25cec0abad5d3c18be1feff41ace4
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ... + an ≤ y Input The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106). Please d...
n, x, y = input().split() n=int(n) x=int(x) y=int(y) a = y-n+1 if a<=0: print(-1) else: if a**2 + n - 1 >= x: print(a) for i in range(n-1): print(1) else: print(-1)
python
code_algorithm
[ { "input": "5 15 15\n", "output": "11\n1\n1\n1\n1\n" }, { "input": "1 99 11\n", "output": "11\n" }, { "input": "2 3 2\n", "output": "-1\n" }, { "input": "2 912219830404 955103\n", "output": "955102\n1\n" }, { "input": "100000 1 1\n", "output": "-1\n" }, { ...
code_contests
python
0
1320a84b66111947ad501d0abf1642fe
Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1 ≤ n ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. The problem is to finish n one-choice-questions. Eac...
from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import...
python
code_algorithm
[ { "input": "6 2\n1 1 2 2 1 1\n", "output": "16\n" }, { "input": "3 3\n1 3 1\n", "output": "9\n" }, { "input": "5 5\n1 1 4 2 2\n", "output": "1000\n" }, { "input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16...
code_contests
python
0
894743fa8aeb3485a77999a819b1d1c5
[INSPION FullBand Master - INSPION](https://www.youtube.com/watch?v=kwsciXm_7sA) [INSPION - IOLITE-SUNSTONE](https://www.youtube.com/watch?v=kwsciXm_7sA) On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free ti...
import sys # Read input and build the graph inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 coupl = [[] for _ in range(n)] for _ in range(n - 1): u = inp[ii] - 1; ii += 1 v = inp[ii] - 1; ii += 1 coupl[u].append(v) coupl[v].append(u) # Relable to speed up n^2 operations...
python
code_algorithm
[ { "input": "3\n1 2\n2 3\n", "output": "3\n" }, { "input": "5\n1 2\n1 3\n1 4\n3 5\n", "output": "10\n" }, { "input": "10\n9 5\n9 3\n8 1\n4 5\n8 2\n7 2\n7 5\n3 6\n10 5\n", "output": "67\n" }, { "input": "10\n4 5\n9 7\n1 6\n2 5\n7 4\n6 10\n8 3\n4 3\n6 7\n", "output": "50\n" ...
code_contests
python
0
75fac0c7212ca76150d32a901781af24
Your task is to calculate the number of arrays such that: * each array contains n elements; * each element is an integer from 1 to m; * for each array, there is exactly one pair of equal elements; * for each array a, there exists an index i such that the array is strictly ascending before the i-th element a...
MOD = 998244353 def add(x, y): x += y while(x >= MOD): x -= MOD while(x < 0): x += MOD return x def mul(x, y): return (x * y) % MOD def binpow(x, y): z = 1 while(y): if(y & 1): z = mul(z, x) x = mul(x, x) y >>= 1 return z def in...
python
code_algorithm
[ { "input": "100000 200000\n", "output": "707899035\n" }, { "input": "3 4\n", "output": "6\n" }, { "input": "3 5\n", "output": "10\n" }, { "input": "42 1337\n", "output": "806066790\n" }, { "input": "3 3\n", "output": "3\n" }, { "input": "20 20\n", ...
code_contests
python
0
5aa688bcdb90e351184e9deb8f74b8d7
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that: * Alice will get a (a > 0) candies; * Betty will get b (b > 0) candies; * each sister will get some integer number of candies; * Alice will get a greater amount of candie...
test = int(input()) for t in range(test): c = int(input()) if c == 0 or c == 1 or c == 2: print(0) elif c % 2 == 0: print((c//2)-1) else: print(c//2)
python
code_algorithm
[ { "input": "6\n7\n1\n2\n3\n2000000000\n763243547\n", "output": "3\n0\n0\n1\n999999999\n381621773\n" }, { "input": "39\n2\n3\n5\n7\n9\n8\n6\n5\n4\n4\n9\n4\n5\n6\n8\n1\n5\n4\n3\n10\n7\n1\n1\n4\n3\n5\n6\n2\n5\n9\n9\n6\n6\n4\n5\n3\n10\n10\n1\n", "output": "0\n1\n2\n3\n4\n3\n2\n2\n1\n1\n4\n1\n2\n2\n3...
code_contests
python
0.7
bcf9e795cd14a4dcc82b28331da84a51
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...
from math import * n, ans = int(input()), 0 if n < 3: ans = n elif n % 2: ans = n * (n - 1) * (n - 2) else: a = 0 if gcd(n, n - 3) == 1: a = n * (n - 1) * (n - 3) n -= 1 ans = max(n * (n - 1) * (n - 2), a) print(ans)
python
code_algorithm
[ { "input": "9\n", "output": "504\n" }, { "input": "7\n", "output": "210\n" }, { "input": "862795\n", "output": "642275489615199390\n" }, { "input": "116\n", "output": "1507420\n" }, { "input": "763116\n", "output": "444394078546562430\n" }, { "input": ...
code_contests
python
0.2
1fb05147342d93ed108355cdf76a271b
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...
read_line = lambda: [int(i) for i in input().split()] n, k = read_line() x = read_line() print(max(sum(sorted(x[l:r] + sorted(x[:l] + x[r:])[-k:])[l-r:]) for l in range(n) for r in range(l + 1, n + 1))) # Made By Mostafa_Khaled
python
code_algorithm
[ { "input": "10 2\n10 -1 2 2 2 2 2 2 -1 10\n", "output": "32\n" }, { "input": "5 10\n-1 -1 -1 -1 -1\n", "output": "-1\n" }, { "input": "35 5\n151 -160 -292 -31 -131 174 359 42 438 413 164 91 118 393 76 435 371 -76 145 605 292 578 623 405 664 330 455 329 66 168 179 -76 996 163 531\n", ...
code_contests
python
0
4e28af37251e287e92d4187c7dcc5496
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 ...
s = input() n = s.rfind("#") error = 0 s1 = 0 s2 = 0 s3 = 0 s4 = s.count("(") s5 = s.count(")") s6 = 0 for num in range(n): if s[num]=="(" : s2 += 1 elif s[num]==")": s3 += 1 if s[num]=="#" : s1 += 1 s3 += 1 if s3 > s2: error=1 if s1+s5 < s4: s6 = s4-s5-s1 s3 ...
python
code_algorithm
[ { "input": "#\n", "output": "-1\n" }, { "input": "()((#((#(#()\n", "output": "1\n1\n3\n" }, { "input": "(#)\n", "output": "-1\n" }, { "input": "(((#)((#)\n", "output": "1\n2\n" }, { "input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#(...
code_contests
python
0
e6f6a82197f0cbe529b2ba93244ed8aa
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu...
nro_amu = int(input()) amu = [] for i in range(nro_amu): fila1 = list(input()) fila2 = list(input()) fila1.extend(fila2) amu.append(fila1) if i+1 != nro_amu: _ = input() pilas = [] nro_pilas = 0 for a in amu: existe = False for i in range(nro_pilas): for j in rang...
python
code_algorithm
[ { "input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n", "output": "1\n" }, { "input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n", "output": "2\n" }, { "input": "4\n36\n44\n**\n32\n46\n**\n66\n41\n**\n64\n34\n", "output": "3\n" }, { "input": "3\n14\n54\n**\n45\n41...
code_contests
python
0.1
ba3b20463e4ffe142b094d723052b745
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the secon...
n=int(input());k=0 if n==1:print(0);exit() a=list(map(int,input().split()));b=[];c=[] for i in range(n*n):b.append(0) for i in range(n): if b[a[i]]==0:b[a[i]]=a[i] else:c.append(a[i]) for i in range(len(c)): for j in range(c[i],len(b)): if b[j]==0:k+=b[j-1]-c[i]+1;b[j]=j;break print(k)
python
code_algorithm
[ { "input": "5\n1 2 3 2 5\n", "output": "2\n" }, { "input": "4\n1 3 1 4\n", "output": "1\n" }, { "input": "5\n1 5 3 2 4\n", "output": "0\n" }, { "input": "50\n49 37 30 2 18 48 14 48 50 27 1 43 46 5 21 28 44 2 24 17 41 38 25 18 43 28 25 21 28 23 26 27 4 31 50 18 23 11 13 28 44 ...
code_contests
python
0.7
a5a20abb9506bad651194280a8958ecf
Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count ...
import io import sys import time import random #~ start = time.clock() #~ test = '''2 2 1 1 #~ 1 2''' #~ test = '''3 2 3 3 #~ 1 1 #~ 3 1 #~ 2 2''' #~ test = '''3 2 3 2 #~ 1 1 #~ 3 1 #~ 2 2''' #~ sys.stdin = io.StringIO(test) r,c,n,k = map(int,input().split()) # row column number-of-violists data = [ [0 for i in range...
python
code_algorithm
[ { "input": "3 2 3 3\n1 1\n3 1\n2 2\n", "output": "1\n" }, { "input": "2 2 1 1\n1 2\n", "output": "4\n" }, { "input": "3 2 3 2\n1 1\n3 1\n2 2\n", "output": "4\n" }, { "input": "7 5 3 1\n5 5\n4 5\n1 4\n", "output": "135\n" }, { "input": "10 10 10 1\n1 10\n10 8\n7 4\...
code_contests
python
1
e81201065bfee7d30e5a5951fec0a1f4
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line. The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n ...
n=int(input()) q=sorted(list(map(int,input().split()))) print(q[(n-1)//2])
python
code_algorithm
[ { "input": "4\n1 2 3 4\n", "output": "2\n" }, { "input": "1\n1\n", "output": "1\n" }, { "input": "10\n1 1 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "1\n" }, { "input": "2\n-1 2\n", "output": "-1\n" }, { "input": "4\n-1 -1 0 1\n", ...
code_contests
python
0.9
989e9060a0b525cff756919ccbaa28c9
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
n = int(input()) l = list(map(int, input().split())) carrier = 0 for i in range(n): if l[i] == 0 and carrier == 1: print("NO") exit() if l[i] % 2 == 1: if carrier == 0: carrier = 1 else: carrier = 0 if carrier == 0: print("YES") else: ...
python
code_algorithm
[ { "input": "3\n1 0 1\n", "output": "NO\n" }, { "input": "4\n1 2 1 2\n", "output": "YES\n" }, { "input": "100\n37 92 14 95 3 37 0 0 0 84 27 33 0 0 0 74 74 0 35 72 46 29 8 92 1 76 47 0 38 82 0 81 54 7 61 46 91 0 86 0 80 0 0 98 88 0 4 0 0 52 0 0 82 0 33 35 0 36 58 52 1 50 29 0 0 24 0 69 97 ...
code_contests
python
0.2
c3b192e77a0c340fc152966911196f9a
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu...
a = input() b = [a.count('VK')] + [0] * len(a) s = a[:] for i in range(len(a)): if a[i] == 'V': if i != len(a) - 1: s = s[:i] + 'K' + s[i + 1:] else: s = s[:i] + 'K' else: if i != len(a) - 1: s = s[:i] + 'V' + s[i + 1:] else: s = s[...
python
code_algorithm
[ { "input": "VK\n", "output": "1\n" }, { "input": "V\n", "output": "0\n" }, { "input": "VKKKKKKKKKVVVVVVVVVK\n", "output": "3\n" }, { "input": "VV\n", "output": "1\n" }, { "input": "KVKV\n", "output": "1\n" }, { "input": "VKVK\n", "output": "2\n" ...
code_contests
python
0.3
bb7cd96f8d1b2a9243accc8d5450b7ec
Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n. For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1]. The following sequences aren't splits of 8: [1, 7], [5, 4], [11, -3], [1, 1, 4, 1, 1]. The weight of a split is t...
from collections import deque import math import os import random import re import sys #n=list(map(int, input().split())) #n=map(int, input().split()) def main(): n=int(input()) ans=n//2+1 print(ans) main()
python
code_algorithm
[ { "input": "7\n", "output": "4\n" }, { "input": "8\n", "output": "5\n" }, { "input": "9\n", "output": "5\n" }, { "input": "751453521\n", "output": "375726761\n" }, { "input": "13439\n", "output": "6720\n" }, { "input": "91840\n", "output": "45921\n...
code_contests
python
0
656725b68fd30dd8e9e149efb11c1fe4
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that...
#!/usr/bin/env python3 n = int(input().strip()) ais = list(map(int, input().strip().split())) ais.sort() cnt = 0 s = sum(ais) thrs = -((-9 * n) // 2) # ceil(4.5 * n) while s < thrs: s += 5 - ais[cnt] cnt += 1 print (cnt)
python
code_algorithm
[ { "input": "4\n5 3 3 5\n", "output": "1\n" }, { "input": "3\n4 4 4\n", "output": "2\n" }, { "input": "4\n5 4 5 5\n", "output": "0\n" }, { "input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 ...
code_contests
python
0
7a8c9ff31935004ebf06b89df64319b6
Alice has a lovely piece of cloth. It has the shape of a square with a side of length a centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b < a). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to ...
def check(n): i=2 while i*i<=n: if n%i==0: return 1 i+=1 return 0 for _ in range(int(input())): a,b=map(int,input().split()) if (a-b)!=1: print('NO') else: if check((a*a)-(b*b)):print('NO') else:print('YES')
python
code_algorithm
[ { "input": "4\n6 5\n16 13\n61690850361 24777622630\n34 33\n", "output": "YES\nNO\nNO\nYES\n" }, { "input": "1\n5484081721 5484081720\n", "output": "NO\n" }, { "input": "1\n5 4\n", "output": "NO\n" }, { "input": "5\n529 169\n232 231\n283 282\n217 216\n34310969148 14703433301\n...
code_contests
python
0.5
eb3ff32190943774cb6de34f1e0ca8d0
In this problem we consider a very simplified model of Barcelona city. Barcelona can be represented as a plane with streets of kind x = c and y = c for every integer c (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal...
a, b, c = map(int, input().split()) x1, y1, x2, y2 = map(int, input().split()) l = 0 xz1 = x1 if b != 0: yz1 = (-c - x1 * a) / b else: yz1 = 9999999999999999999 if a != 0: xz2 = (-c - y1 * b) / a else: xz2 = 9999999999999999999 yz2 = y1 xf1 = x2 if b != 0: yf1 = (-c - x2 * a) / b else: yf1 = 99...
python
code_algorithm
[ { "input": "3 1 -9\n0 3 3 -1\n", "output": "6.16227766016838\n" }, { "input": "1 1 -3\n0 3 3 0\n", "output": "4.242640687119285\n" }, { "input": "10 4 8\n2 8 -10 9\n", "output": "12.677032961426901\n" }, { "input": "3 0 -324925900\n-97093162 612988987 134443035 599513203\n", ...
code_contests
python
0
135762cccef5bf60e78e818e1957a086
Today's morning was exceptionally snowy. Meshanya decided to go outside and noticed a huge snowball rolling down the mountain! Luckily, there are two stones on that mountain. Initially, snowball is at height h and it has weight w. Each second the following sequence of events happens: snowball's weights increases by i,...
w , h = map(int , input().split()) u1 , d1 = map(int , input().split()) u2 , d2 = map(int , input().split()) while h > 0: if h == d1: w = w + h w = w - u1 h -= 1 elif h == d2: w = w + h w = w - u2 h -= 1 else: w = w + h h -= 1 if w < 0: ...
python
code_algorithm
[ { "input": "4 3\n9 2\n0 1\n", "output": "1\n" }, { "input": "4 3\n1 1\n1 2\n", "output": "8\n" }, { "input": "99 20\n87 7\n46 20\n", "output": "176\n" }, { "input": "1 30\n2 4\n99 28\n", "output": "376\n" }, { "input": "30 2\n88 1\n2 2\n", "output": "0\n" },...
code_contests
python
0.9
b02bf2913924b9ce8184084450b22a56
You are given an array consisting of n integers a_1, a_2, ... , a_n and an integer x. It is guaranteed that for every i, 1 ≤ a_i ≤ x. Let's denote a function f(l, r) which erases all values such that l ≤ a_i ≤ r from the array a and returns the resulting array. For example, if a = [4, 1, 1, 4, 5, 2, 4, 3], then f(2, 4...
n, x = map(int, input().split()) a = list(map(int, input().split())) fst, last, sm = [], [], [] for i in range(1000005): fst.append(0) last.append(0) sm.append(0) for i in range(n): if fst[a[i]] == 0: fst[a[i]] = i + 1 last[a[i]] = i + 1 for i in range(x + 2): if fst[i] == 0: fst...
python
code_algorithm
[ { "input": "7 4\n1 3 1 2 2 4 3\n", "output": "6\n" }, { "input": "3 3\n2 3 1\n", "output": "4\n" }, { "input": "8 8\n6 2 1 8 5 7 3 4\n", "output": "4\n" }, { "input": "4 7\n3 6 2 4\n", "output": "10\n" }, { "input": "3 3\n3 1 3\n", "output": "5\n" }, { ...
code_contests
python
0
b1bd759e5105a12a5d1513d2ea1ba86b
Natasha's favourite numbers are n and 1, and Sasha's favourite numbers are m and -1. One day Natasha and Sasha met and wrote down every possible array of length n+m such that some n of its elements are equal to 1 and another m elements are equal to -1. For each such array they counted its maximal prefix sum, probably a...
import sys import math MOD = 998244853 def prepare_c(n): result = [1] last = [1, 1] for i in range(2, n + 1): new = [1] for j in range(1, i): new.append((last[j - 1] + last[j]) % MOD) new.append(1) last = new return new def main(): (a, b) = tuple([int(x...
python
code_algorithm
[ { "input": "2 2\n", "output": "5\n" }, { "input": "2 0\n", "output": "2\n" }, { "input": "0 2\n", "output": "0\n" }, { "input": "2000 2000\n", "output": "674532367\n" }, { "input": "1994 1981\n", "output": "596939902\n" }, { "input": "2000 0\n", "o...
code_contests
python
0
99144776139bcdec3fee121a55a73bc8
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n types of resources, numbered 1 through n. Bob needs at least a_i pieces of the i-th resource to build the spaceship. The numbe...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def main(): n = int(input()) a = [0]+list(map(int,input().split())) su = sum(a) le = [0]*(n+1) dct = {} for _ in range(int(input())): s,t,u = map(int,input().split()) x = dct....
python
code_algorithm
[ { "input": "2\n2 3\n5\n2 1 1\n2 2 1\n1 1 1\n2 1 2\n2 2 0\n", "output": "4\n3\n3\n2\n3\n" }, { "input": "3\n3 1 1\n6\n1 1 1\n1 2 1\n1 2 2\n1 1 2\n1 1 3\n1 2 3\n", "output": "4\n3\n3\n4\n3\n4\n" }, { "input": "2\n2 2\n5\n1 1 2\n1 1 0\n1 1 1\n1 1 0\n1 1 2\n", "output": "3\n4\n3\n4\n3\n"...
code_contests
python
0
1412e8289cd5475a17a3b25302113af1
Bandits appeared in the city! One of them is trying to catch as many citizens as he can. The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square. After Sunday walk all the roads were changed to one-way ro...
n = int(input()) parent = [0] + [x-1 for x in list(map(int, input().split()))] citizen = list(map(int, input().split())) sz = [1] * n for i in range(1, n): sz[parent[i]] = 0 #print(sz) for i in range(n-1, 0, -1): citizen[parent[i]] += citizen[i] sz[parent[i]] += sz[i] #print(citizen) #print(sz) ans = 0 f...
python
code_algorithm
[ { "input": "3\n1 1\n3 1 2\n", "output": "3\n" }, { "input": "3\n1 1\n3 1 3\n", "output": "4\n" }, { "input": "2\n1\n293175439 964211398\n", "output": "1257386837\n" }, { "input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34...
code_contests
python
0
dc2978efb0b30424439c59975d85b5ea
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution....
n=int(input()) count=0 for _ in range(n): l=list(map(int,input().split())) if(sum(l)>=2): count+=1 print(count)
python
code_algorithm
[ { "input": "2\n1 0 0\n0 1 1\n", "output": "1\n" }, { "input": "3\n1 1 0\n1 1 1\n1 0 0\n", "output": "2\n" }, { "input": "1\n1 0 0\n", "output": "0\n" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 ...
code_contests
python
1
da27d8494bd94e1909859612e3a682ab
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 ce...
n=int(input()) d=[1]*100 a,b=map(int,input().split()) for i in range(n-1): l,r=map(int,input().split()) for i in range(l,r): d[i]=0 print(sum(d[a:b]))
python
code_algorithm
[ { "input": "3\n0 5\n2 8\n1 6\n", "output": "1\n" }, { "input": "3\n0 10\n1 5\n7 15\n", "output": "3\n" }, { "input": "2\n1 5\n1 2\n", "output": "3\n" }, { "input": "2\n1 9\n3 5\n", "output": "6\n" }, { "input": "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n2...
code_contests
python
1
a6f9c5a095352eb275a488a616f6ead9
One day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vasya has b bourles. He can buy a certain number of dollars and then sell it no more than once in n days. According to Mar...
I = lambda : map(int,input().split()) n,m = I() li = list(I()) ma = li[n-1] ans=m for i in range(n-2,-1,-1) : ma=max(ma,li[i]) ans = max(ans,m%li[i]+(m//li[i])*(ma)) print(ans)
python
code_algorithm
[ { "input": "2 4\n3 7\n", "output": "8\n" }, { "input": "4 10\n4 3 2 1\n", "output": "10\n" }, { "input": "4 10\n4 2 3 1\n", "output": "15\n" }, { "input": "5 1293\n1183 142 1356 889 134\n", "output": "12219\n" }, { "input": "1 1483\n1126\n", "output": "1483\n"...
code_contests
python
0.7
9496dd3cfeb2f4880b13c33bfba8a8e6
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: * ti = 1, if the i-th child is good at programming, *...
try: n = int(input()) nums = list(map(int, input().split())) def count(nums, x): cnt_ar = [] for idx, ele in enumerate(nums): if(ele == x): cnt_ar.append(idx+1) return cnt_ar def teams(nums): ones = count(nums, 1) twos = count(nums, ...
python
code_algorithm
[ { "input": "4\n2 1 1 2\n", "output": "0\n" }, { "input": "7\n1 3 1 3 2 1 2\n", "output": "2\n1 5 2\n3 7 4\n" }, { "input": "3\n2 1 2\n", "output": "0\n" }, { "input": "5\n1 2 2 3 3\n", "output": "1\n1 2 4\n" }, { "input": "220\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 ...
code_contests
python
0.8
03bd0bba342adff2a86712996ca3b8ed
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if...
s=input() s=s.lower() ss='hello' cnt=0 for i in range(len(s)): if s[i]==ss[cnt]: cnt+=1 if cnt==5: break if cnt==5: print("YES") else: print("NO")
python
code_algorithm
[ { "input": "ahhellllloou\n", "output": "YES\n" }, { "input": "hlelo\n", "output": "NO\n" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli\n", "output": "YES\n" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtr...
code_contests
python
0.9
5f30242f61e873fdf77791a580965e64
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Row...
from itertools import accumulate import math import bisect def list_sum(L1, L2): return [L1[i] + L2[i] for i in range(len(L1))] h, w = [int(x) for x in input().split()] M = [] for i in range(h): M.append([1 if c == '.' else 0 for c in input().rstrip()]) H = [[0]+list(accumulate(M[i][j] and M[i][j+1] for j i...
python
code_algorithm
[ { "input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 ...
code_contests
python
0
3e9d98099280987d59c3a6d37a106c8e
Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy ...
import math, sys def solve(): bx,by = map(int, input().split()) dist = lambda f1, f2, v: math.sqrt(f1*f1+f2*f2) / v n = int(input()) ans = sys.maxsize for _ in range(n): x,y,v = map(int, input().split()) ans = min(ans, dist(x-bx, y-by,v)) return ans print(solve())
python
code_algorithm
[ { "input": "1 3\n3\n3 3 2\n-2 3 6\n-2 7 10\n", "output": "0.5\n" }, { "input": "0 0\n2\n2 0 1\n0 2 2\n", "output": "1.0\n" }, { "input": "66 -82\n43\n27 -21 70\n-64 46 58\n-7 -20 41\n-42 60 57\n-93 -7 95\n26 -61 26\n-10 -72 25\n-78 -18 55\n-62 -64 69\n-33 95 50\n24 59 45\n4 72 37\n66 57 ...
code_contests
python
0
86fe8b1fa3b9d56922b866855ff0d8d9
There are n people taking part in auction today. The rules of auction are classical. There were n bids made, though it's not guaranteed they were from different people. It might happen that some people made no bids at all. Each bid is define by two integers (ai, bi), where ai is the index of the person, who made this ...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod...
python
code_algorithm
[ { "input": "6\n1 10\n2 100\n3 1000\n1 10000\n2 100000\n3 1000000\n3\n1 3\n2 2 3\n2 1 2\n", "output": "2 100000\n1 10\n3 1000\n" }, { "input": "3\n1 10\n2 100\n1 1000\n2\n2 1 2\n2 2 3\n", "output": "0 0\n1 10\n" }, { "input": "4\n2 8\n1 14\n3 24\n1 30\n15\n1 1\n1 2\n2 1 2\n1 3\n2 1 3\n2 2...
code_contests
python
0.5
dee42962be1effe48464c71212aece19
Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: * Extract the first character of s and append t with this character. * Extract the last character of t and append u with this ...
s = list(input()) t = [] u = [] letters = [[] for _ in range(ord('z') - ord('a') + 1)] for (index, letter) in enumerate(s): letters[ord(letter) - ord('a')] += [index] for indexes in letters: indexes.reverse() current = 0 while current < len(s): if len(t) == 0: t += s[current] letters[...
python
code_algorithm
[ { "input": "cab\n", "output": "abc\n" }, { "input": "acdb\n", "output": "abdc\n" }, { "input": "babcaaccb\n", "output": "aaabcccbb\n" }, { "input": "badbdc\n", "output": "abbcdd\n" }, { "input": "bbbb\n", "output": "bbbb\n" }, { "input": "aaaa\n", ...
code_contests
python
0.1
bc555da2665257401a5f3f2f96ba4a1d
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive. Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys #import threading from collections import defaultdict #threading.stack_size(10**8) m...
python
code_algorithm
[ { "input": "3\n1 3\n4 6\n1 7\n", "output": "1\n" }, { "input": "3\n1 2\n3 4\n6 8\n", "output": "-1\n" }, { "input": "3\n1 2\n2 3\n3 4\n", "output": "2\n" }, { "input": "2\n0 10\n0 10\n", "output": "1\n" }, { "input": "4\n63 63\n12 34\n17 29\n58 91\n", "output"...
code_contests
python
0
669565fe60fd85747d0fed4b36eec73c
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
import sys n = int(input()) a=[] for i in range(n): a.append([j for j in input()]) b=[] for i in range(n): b.append({}) for j in a[i]: if j in b[i]: print('NO') sys.exit() b[i][j]=1 c=[-1 for i in range(26)] d=[-1 for i in range(26)] e=[0 for i in range(26)] for word in a: l=ord(word[0])-97 e[l]=1 for...
python
code_algorithm
[ { "input": "3\nkek\npreceq\ncheburek\n", "output": "NO\n" }, { "input": "4\nmail\nai\nlru\ncf\n", "output": "cfmailru\n" }, { "input": "4\nab\nbc\nca\nd\n", "output": "NO\n" }, { "input": "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\njt\ntm\nmq\nqf\nfk\nkn\nny\nyz\nzr\nrg\ngv\nvc\...
code_contests
python
0
1f769214d0bc2fa254df8b5859aa4a0b
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined <image>. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum poss...
n, k1, k2 = map(int, input().split()) a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) e = [] for i in range(n): e.append(abs(a1[i]-a2[i])) #print(e) for k in range(k1+k2): e[e.index(max(e))] = abs(max(e) - 1) print(sum(i * i for i in e))
python
code_algorithm
[ { "input": "2 1 0\n1 2\n2 2\n", "output": "0\n" }, { "input": "2 0 0\n1 2\n2 3\n", "output": "2\n" }, { "input": "2 5 7\n3 4\n14 4\n", "output": "1\n" }, { "input": "1 5 7\n1\n2\n", "output": "1\n" }, { "input": "10 300 517\n-6 -2 6 5 -3 8 9 -10 8 6\n5 -9 -2 6 1 4...
code_contests
python
0.1
703da2ebfda5b1bac38d48aef569f98b
After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has n power sources, and the second one has m power sources. A power source can be described as a point (x_i, y_i) on a 2-D plan...
import sys # > 0 anti-clock, < 0 clockwise, == 0 same line def orientation(p1, p2, p3): return (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) def dot(p1, p2, p3, p4): return (p2[0]-p1[0])*(p4[0]-p3[0]) + (p2[1]-p1[1])*(p4[1]-p3[1]) def theta(p1, p2): dx = p2[0] - p1[0] dy = p2[1...
python
code_algorithm
[ { "input": "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n1 1\n", "output": "YES\n" }, { "input": "3 4\n0 0\n0 2\n2 0\n0 2\n2 2\n2 0\n0 0\n", "output": "NO\n" }, { "input": "3 3\n1 1\n2 2\n3 3\n1 1\n1 2\n1 3\n", "output": "NO\n" }, { "input": "5 5\n2 0\n0 4\n4 8\n8 4\n10 0\n0 2\n2 6\n6 ...
code_contests
python
0
f6551f590ed59a0b1c6b26d581ba3c32
Masha has three sticks of length a, b and c centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs to spend increasing the stick's length in order to be able to assemble a ...
a, b, c = map(int, input().split()) m = max(a, b, c) n = a+b+c-m if n<=m: print(m-n+1) else: print(0)
python
code_algorithm
[ { "input": "3 4 5\n", "output": "0\n" }, { "input": "100 10 10\n", "output": "81\n" }, { "input": "2 5 3\n", "output": "1\n" }, { "input": "3 1 1\n", "output": "2\n" }, { "input": "68 1 67\n", "output": "1\n" }, { "input": "100 100 100\n", "output"...
code_contests
python
0.6
68f4ed710d0b695a56de6839de2972f2
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School. In his favorite math class, the teacher taught him the following interesting definitions. A parenthesis sequence is a string, containing only characters "(" and ")". A correct parenthesis sequence is a parenthesis sequence ...
n = int(input()) s = list(input()) if n % 2 == 1: print(":(") else: op = n // 2 - s.count("(") for i in range(n): if s[i] == "?": if op > 0: s[i] = "(" else: s[i] = ")" op -= 1 #print("".join(s)) b = 0 for i in range(n):...
python
code_algorithm
[ { "input": "6\n(?????\n", "output": "((()))\n" }, { "input": "10\n(???(???(?\n", "output": ":(\n" }, { "input": "30\n((??)?)???(????(????)???????((\n", "output": ":(\n" }, { "input": "6\n))??((\n", "output": ":(\n" }, { "input": "4\n??(?\n", "output": ":(\n" ...
code_contests
python
0
c4b7c4ac5b08c82a7f760c66f9ece4b2
You are given a function f written in some basic language. The function accepts an integer value, which is immediately written into some variable x. x is an integer variable and can be assigned values from 0 to 2^{32}-1. The function contains three types of commands: * for n — for loop; * end — every command betw...
import sys MAX_NUMBER = 2**32 - 1 def solve(): input = sys.stdin.readline n = int(input()) stack = [] for _ in range(n): oper = input().strip() if oper == 'add': stack.append(1) elif oper == 'end': cur = 0 while len(stack) > 0: ...
python
code_algorithm
[ { "input": "2\nfor 62\nend\n", "output": "0\n" }, { "input": "11\nfor 100\nfor 100\nfor 100\nfor 100\nfor 100\nadd\nend\nend\nend\nend\nend\n", "output": "OVERFLOW!!!\n" }, { "input": "9\nadd\nfor 43\nend\nfor 10\nfor 15\nadd\nend\nadd\nend\n", "output": "161\n" }, { "input":...
code_contests
python
0.3
bcc1ed47e82b359fa0a709aa49192cd4
You have a list of numbers from 1 to n written from left to right on the blackboard. You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit). <image> When there are less than ...
test=int(input()) while(test!=0): n,x=map(int,input().split()) print(2*x) test-=1
python
code_algorithm
[ { "input": "3\n3 1\n4 2\n69 6\n", "output": "2\n4\n12\n" }, { "input": "1\n241139 1\n", "output": "2\n" }, { "input": "1\n2441139 10\n", "output": "20\n" }, { "input": "1\n2452199 2\n", "output": "4\n" }, { "input": "1\n244139 1\n", "output": "2\n" }, { ...
code_contests
python
0.4
d53a91cf2107185a9358c649e6e72ee8
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
a=str(input()) b=a[:];c=a[:];d=a[:] b=b.upper();d=d.upper();c=c.lower() if a==b: a=a.lower() elif a[0]==c[0]: if len(a)>1: if a[1:]==d[1:]: a=a.capitalize() else: pass else: a=a.upper() else: pass print(a)
python
code_algorithm
[ { "input": "cAPS\n", "output": "Caps\n" }, { "input": "Lock\n", "output": "Lock\n" }, { "input": "A\n", "output": "a\n" }, { "input": "Zz\n", "output": "Zz\n" }, { "input": "XweAR\n", "output": "XweAR\n" }, { "input": "F\n", "output": "f\n" }, ...
code_contests
python
0.4
000b7422bd2768faa4423cb115b19e0c
Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that "the years fly by...", it was decided that starting from the next year t...
F = {} def f(k): if not k in F: s, i, j = 0, 4, 4 while i <= k: s += i * f(k // i) i += j + 1 j += 2 F[k] = (k * (k + 1)) // 2 - s return F[k] def g(k): s, i, j = 0, 4, 4 while i <= k: s += (i - 1) * f(k // i) i += j + 1 ...
python
code_algorithm
[ { "input": "25 3\n", "output": "30\n" }, { "input": "50 5\n", "output": "125\n" }, { "input": "1 10\n", "output": "38\n" }, { "input": "1 5000000\n", "output": "8224640917276\n" }, { "input": "1 2\n", "output": "3\n" }, { "input": "1000000 5000000\n", ...
code_contests
python
0
081bfeefc841ee5b3a4d3b29ad0a5c93