Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
int64
2.36k
5k
question
stringlengths
52
14k
solutions
stringlengths
79
675k
input_output
stringlengths
37
505k
difficulty
stringclasses
1 value
url
stringlengths
36
94
starter_code
stringlengths
0
952
2,361
You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; Let th...
["from collections import defaultdict as dd\nfrom collections import deque\nimport bisect\nimport heapq\n\ndef ri():\n return int(input())\n\ndef rl():\n return list(map(int, input().split()))\n\n\ndef solve():\n n = ri()\n output = [0] * (n)\n\n Q = [(-n, 0 ,n - 1)]\n for i in range(1, n + 1):\n ...
{"inputs": ["6\n1\n2\n3\n4\n5\n6\n"], "outputs": ["1 \n1 2 \n2 1 3 \n3 1 2 4 \n2 4 1 3 5 \n3 4 1 5 2 6 \n"]}
introductory
https://codeforces.com/problemset/problem/1353/D
2,362
$n$ robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous! Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the loc...
["def main():\n import sys\n input = sys.stdin.readline\n \n def solve():\n n = int(input())\n maxx = 10**5\n minx = -10**5\n maxy = 10**5\n miny = -10**5\n \n for _ in range(n):\n x, y, f1, f2, f3, f4 = map(int, input().split())\n if no...
{ "inputs": [ "4\n2\n-1 -2 0 0 0 0\n-1 -2 0 0 0 0\n3\n1 5 1 1 1 1\n2 5 0 1 0 1\n3 5 1 0 0 0\n2\n1337 1337 0 1 1 1\n1336 1337 1 1 0 1\n1\n3 5 1 1 1 1\n" ], "outputs": [ "1 -1 -2\n1 2 5\n0\n1 -100000 -100000\n" ] }
introductory
https://codeforces.com/problemset/problem/1196/C
2,363
There are $n$ athletes in front of you. Athletes are numbered from $1$ to $n$ from left to right. You know the strength of each athlete — the athlete number $i$ has the strength $s_i$. You want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team....
["\nT = int(input())\n\nfor _ in range(T):\n a = int(input())\n hh = sorted(map(int, input().split()))\n ans = 10**10\n for h1, h2 in zip(hh[:-1], hh[1:]):\n ans = min(ans, h2 - h1)\n\n print(ans)\n", "for u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n l.s...
{ "inputs": [ "5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\n" ], "outputs": [ "1\n0\n2\n999\n50\n" ] }
introductory
https://codeforces.com/problemset/problem/1360/B
2,364
You are given an undirected unweighted graph consisting of $n$ vertices and $m$ edges (which represents the map of Bertown) and the array of prices $p$ of length $m$. It is guaranteed that there is a path between each pair of vertices (districts). Mike has planned a trip from the vertex (district) $a$ to the vertex (d...
["import sys\nfrom collections import deque\ninput = sys.stdin.readline\n\nt = int(input())\nfor _ in range(t):\n n, m, a, b, c = list(map(int,input().split()))\n p = list(map(int, input().split()))\n p.sort()\n \n pref = [0]\n curr = 0\n for i in range(m):\n curr += p[i]\n pref.appen...
{ "inputs": [ "2\n4 3 2 3 4\n1 2 3\n1 2\n1 3\n1 4\n7 9 1 5 7\n2 10 4 8 5 6 7 3 3\n1 2\n1 3\n1 4\n3 2\n3 5\n4 2\n5 6\n1 7\n6 7\n" ], "outputs": [ "7\n12\n" ] }
introductory
https://codeforces.com/problemset/problem/1343/E
2,365
We guessed a permutation $p$ consisting of $n$ integers. The permutation of length $n$ is the array of length $n$ where each element from $1$ to $n$ appears exactly once. This permutation is a secret for you. For each position $r$ from $2$ to $n$ we chose some other index $l$ ($l < r$) and gave you the segment $p_l, p...
["import sys\ninput = sys.stdin.readline\n\ndef dfs(x,S):\n #print(x,S)\n for i in range(len(S)):\n if x in S[i]:\n S[i].remove(x)\n\n #print(x,S)\n \n LEN1=0\n for s in S:\n if len(s)==1:\n LEN1+=1\n ne=list(s)[0]\n if LEN1==2:\n re...
{ "inputs": [ "5\n6\n3 2 5 6\n2 4 6\n3 1 3 4\n2 1 3\n4 1 2 4 6\n5\n2 2 3\n2 1 2\n2 1 4\n2 4 5\n7\n3 1 2 6\n4 1 3 5 6\n2 1 2\n3 4 5 7\n6 1 2 3 4 5 6\n3 1 3 6\n2\n2 1 2\n5\n2 2 5\n3 2 3 5\n4 2 3 4 5\n5 1 2 3 4 5\n" ], "outputs": [ "3 1 4 6 2 5 \n3 2 1 4 5 \n2 1 6 3 5 4 7 \n1 2 \n2 5 3 4 1 \n" ] }
introductory
https://codeforces.com/problemset/problem/1343/F
2,366
Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For ...
["for _ in range(int(input())):\n n = int(input())\n A = list(map(int, input().split()))\n m = 10 ** 9\n c = 0\n for i in range(n - 1, -1, -1):\n if A[i] <= m:\n m = A[i]\n else:\n c += 1\n print(c)", "t = int(input())\nfor z in range(t):\n n = int(input())\n ...
{ "inputs": [ "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n" ], "outputs": [ "3\n0\n1\n8\n2\n" ] }
introductory
https://codeforces.com/problemset/problem/1213/B
2,367
You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the string $s$ of length $len$ and reverse it; at the same time choose any con...
["q = int(input())\nfor _ in range(q) :\n n = int(input())\n s = input()\n t = input()\n\n x = set(s)\n y = set(t)\n\n if x != y :\n print(\"NO\")\n continue\n\n if len(x) == n :\n a = [0] * n\n for i, c in enumerate(t) :\n a[i] = s.find(c)\n\n yeet = 0\n vis = [False] * n\n for i in ra...
{ "inputs": [ "4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc\n" ], "outputs": [ "NO\nYES\nNO\nYES\n" ] }
introductory
https://codeforces.com/problemset/problem/1256/F
2,368
You have $n$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $i$-th gift consists of $a_i$ candies and $b_i$ oranges. During one move, you can choose some gift $1 \le i \le n$ and do one of the following operations: ...
["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n ma = min(a)\n mb = min(b)\n \n ops = 0\n for xa, xb in zip(a, b):\n da = xa - ma\n db = xb - mb\n ops += max(da, db)\n \n ...
{ "inputs": [ "5\n3\n3 5 6\n3 2 3\n5\n1 2 3 4 5\n5 4 3 2 1\n3\n1 1 1\n2 2 2\n6\n1 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1\n3\n10 12 8\n7 5 4\n" ], "outputs": [ "6\n16\n0\n4999999995\n7\n" ] }
introductory
https://codeforces.com/problemset/problem/1399/B
2,369
This problem is a version of problem D from the same contest with some additional constraints and tasks. There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$). You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of ea...
["# @author \n\nimport sys\n\nclass GCandyBoxHardVersion:\n def solve(self):\n q = int(input())\n for _ in range(q):\n n = int(input())\n a = [0] * n\n f = [0] * n\n for i in range(n):\n a[i], f[i] = [int(_) for _ in input().split()]\n\n ...
{ "inputs": [ "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n" ], "outputs": [ "3 3\n3 3\n9 5\n" ] }
introductory
https://codeforces.com/problemset/problem/1183/G
2,370
The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is as follows: $[\unde...
["#!usr/bin/env python3\nfrom collections import defaultdict, deque\nfrom heapq import heappush, heappop\nfrom itertools import permutations, accumulate\nimport sys\nimport math\nimport bisect\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef LS():return [l...
{ "inputs": [ "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n" ], "outputs": [ "7\n2\n4\n1\n1\n3\n" ] }
introductory
https://codeforces.com/problemset/problem/1335/E1
2,371
You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ is a subarray consisting several first elements: the prefix of the array $a$...
["for __ in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n ar.reverse()\n ans = n - 1\n flag = False\n for i in range(1, n):\n if ar[i] < ar[i - 1]:\n flag = True\n if flag:\n if ar[i] > ar[i - 1]:\n break\n an...
{ "inputs": [ "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n" ], "outputs": [ "0\n4\n0\n2\n3\n" ] }
introductory
https://codeforces.com/problemset/problem/1385/C
2,372
Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$). In one move, you can do one of the following things: Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increase $a_i$ by one); Append the copy of some (single) element of $a$ to the en...
["import math\nfor _ in range(int(input())):\n n=int(input())\n if n==1:\n print(0)\n else:\n k=int(n**(0.5))\n if k*k<n:\n k+=1\n # print(n,k) \n ans=k-1\n if k*(k-1)>=n:\n ans+=(k-2)\n else:\n ans+=(k-1)\n print(ans) ...
{ "inputs": [ "5\n1\n5\n42\n1337\n1000000000\n" ], "outputs": [ "0\n3\n11\n72\n63244\n" ] }
introductory
https://codeforces.com/problemset/problem/1426/C
2,373
You are given an array $a$ consisting of $n$ integers (it is guaranteed that $n$ is even, i.e. divisible by $2$). All $a_i$ does not exceed some integer $k$. Your task is to replace the minimum number of elements (replacement is the following operation: choose some index $i$ from $1$ to $n$ and replace $a_i$ with some...
["import sys\ndef input():\n\treturn sys.stdin.readline()[:-1]\n\nt = int(input())\nfor _ in range(t):\n\tn, k = map(int, input().split())\n\ta = list(map(int, input().split()))\n\tcum = [0 for _ in range(2*k+2)]\n\tfor i in range(n//2):\n\t\tx, y = a[i], a[n-i-1]\n\t\tcum[2] += 2\n\t\tcum[min(x, y)+1] -= 1\n\t\tcum[x+...
{ "inputs": [ "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n" ], "outputs": [ "0\n1\n4\n2\n" ] }
introductory
https://codeforces.com/problemset/problem/1343/D
2,374
You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$. There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types: [Image] Types of ...
["ans = []\nfor _ in range(int(input())):\n n = int(input())\n s = list(input())\n t = list(input())\n lvl = 0\n X = [s, t]\n f = 1\n for i in range(n):\n if s[i] in '3456' and t[i] in '3456':\n lvl = 1 - lvl\n elif X[lvl][i] in '3456':\n f = 0\n ans.a...
{ "inputs": [ "6\n7\n2323216\n1615124\n1\n3\n4\n2\n13\n24\n2\n12\n34\n3\n536\n345\n2\n46\n54\n" ], "outputs": [ "YES\nYES\nYES\nNO\nYES\nNO\n" ] }
introductory
https://codeforces.com/problemset/problem/1234/C
2,375
The only difference between easy and hard versions is constraints. You are given a sequence $a$ consisting of $n$ positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is as follows: $[\unde...
["from operator import itemgetter\nimport sys\ninput = sys.stdin.readline\n\nMAX_A = 200\nt = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n \n ruiseki = [[0] * MAX_A for i in range(n + 1)]\n for i in range(n):\n for j in range(MAX_A):\n ru...
{ "inputs": [ "6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n" ], "outputs": [ "7\n2\n4\n1\n1\n3\n" ] }
introductory
https://codeforces.com/problemset/problem/1335/E2
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
8