question stringlengths 1.33k 3.93k | response1 stringlengths 754 5.86k | response2 stringlengths 754 5.2k | gt int64 0 3 | answer listlengths 2 2 |
|---|---|---|---|---|
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nArun has a rooted tree of N vertices rooted at vertex 1. Each vertex can either be coloured black or white.\n\nInitially, the vertices are coloured A_{1}, A_{2}, \\ld... | \n```python\nimport sys\nfrom collections import deque, defaultdict\n\ndef main():\n input = sys.stdin.read().split()\n ptr = 0\n T = int(input[ptr])\n ptr += 1\n results = []\n \n for _ in range(T):\n N = int(input[ptr])\n ptr += 1\n A = list(map(int, input[ptr:ptr+N]))\n ... | \nTo solve this problem, we need to determine the minimum number of operations required to transform the initial color configuration of a tree into the desired color configuration. Each operation allows us to paint an entire subtree to either black or white.\n\n### Approach\n1. **Tree Construction**: Build the tree usi... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nA rabbit is playing a role-playing game. Just before entering the castle, he was ambushed by an enemy!\n\nIt was a battle between one hero operated by a rabbit and n ... | \n```python\nimport heapq\n\ndef main():\n import sys\n input = sys.stdin.read().split()\n ptr = 0\n n = int(input[ptr])\n ptr += 1\n hero_h = int(input[ptr])\n hero_a = int(input[ptr + 1])\n hero_d = int(input[ptr + 2])\n hero_s = int(input[ptr + 3])\n ptr += 4\n enemies = []\n for ... | \n```python\nimport heapq\n\ndef main():\n import sys\n input = sys.stdin.read().split()\n ptr = 0\n n = int(input[ptr])\n ptr += 1\n\n hero_h = int(input[ptr])\n hero_a = int(input[ptr+1])\n hero_d = int(input[ptr+2])\n hero_s = int(input[ptr+3])\n ptr +=4\n\n enemies = []\n for _ i... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nLittle Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game f... | \nTo solve this problem, we need to determine the minimum number of maps Johnny needs to study such that the probability of the game being played on one of those maps is at least a given probability $ P $. \n\n### Approach\n1. **Understanding the Game Mechanics**: The game selects three maps at random, and each player ... | \n```python\nimport math\nimport sys\n\ndef solve():\n input = sys.stdin.read().split()\n N = int(input[0])\n P_str = input[1]\n P = float(P_str)\n total_triplets = math.comb(N, 3)\n \n for K in range(N + 1):\n term1 = 0.0\n if K >= 1 and (N - K) >= 2:\n term1 = math.comb(K... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nYou 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$.... | \n```python\nimport sys\nfrom collections import deque\n\ndef main():\n input = sys.stdin.read\n data = input().split()\n idx = 0\n t = int(data[idx])\n idx += 1\n results = []\n \n for _ in range(t):\n n = int(data[idx])\n m = int(data[idx+1])\n a = int(data[idx+2])\n ... | \n```python\nimport sys\nfrom collections import deque, defaultdict\n\ndef get_path(start, end, adj, n):\n parent = [0] * (n + 1)\n visited = [False] * (n + 1)\n q = deque([start])\n visited[start] = True\n parent[start] = -1\n found = False\n while q:\n u = q.popleft()\n if u == end:... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nYou are given a rooted tree consisting of $n$ vertices. The vertices are numbered from $1$ to $n$, and the root is the vertex $1$. You are also given a score array $s... | \nTo solve this problem, we need to determine the maximum value of a valid multiset of paths in a rooted tree, where each path starts from the root and satisfies specific constraints on the distribution of paths among the nodes. The constraints require that for any two siblings (children of the same parent), the number... | \n```python\nimport sys\n\ndef main():\n input = sys.stdin.read().split()\n ptr = 0\n t = int(input[ptr])\n ptr += 1\n for _ in range(t):\n n, k = int(input[ptr]), int(input[ptr+1])\n ptr += 2\n p = list(map(int, input[ptr:ptr + n-1]))\n ptr += n-1\n s = list(map(int, i... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nLee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn\'t feel good at all. Lee invented it so tediously slow that he mana... | \nTo solve the problem efficiently, we need to determine the maximum number of yellow vertices that can be achieved by coloring claws in a Rooted Dead Bush (RDB) of level $ n $. Each claw consists of a node with exactly three children. \n\n---\n\n### **Key Observations and Strategy**\n\n1. **RDB Construction Rule**:\n ... | \nTo solve this problem, we need to determine the maximum number of yellow vertices Lee can achieve by coloring claws in his Rooted Dead Bush (RDB) of level $ n $. The solution involves precomputing values based on a recurrence relation to efficiently answer multiple test cases.\n\n### Approach\n1. **Understanding the ... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nJon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns d... | \n```python\nimport math\nimport sys\n\ndef compute_prob(k, n):\n total = 0.0\n for i in range(k + 1):\n sign = (-1) ** i\n comb = math.comb(k, i)\n term = comb * ((k - i) / k) ** n\n total += sign * term\n return total\n\ndef main():\n input = sys.stdin.read().split()\n idx =... | \n```python\nimport math\nimport sys\n\ndef compute_prob(k, n):\n total = 0.0\n for i in range(k + 1):\n comb = math.comb(k, i)\n sign = (-1) ** i\n term = sign * comb * ((k - i) / k) ** n\n total += term\n return total\n\ndef main():\n input = sys.stdin.read().split()\n idx =... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nRecently you\'ve discovered a new shooter. They say it has realistic game mechanics.\n\nYour character has a gun with magazine size equal to $k$ and should exterminat... | \nTo solve this problem, we need to determine the minimum number of bullets required to eliminate all waves of monsters while accounting for the time constraints and the realistic reloading mechanic. The key challenge is to efficiently manage the bullets and reloading operations to ensure all monsters are eliminated wi... | \nTo solve this problem, we need to determine the minimum number of bullets required to exterminate all waves of monsters, considering the constraints of reloading and time. The solution involves dynamic programming to track the minimum bullets spent at each step.\n\n### Approach\n1. **Dynamic Programming (DP) Setup**:... | 0 | [
0,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nJon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns d... | \n```python\nimport math\nimport sys\n\ndef compute_prob(k, n):\n total = 0.0\n for i in range(k + 1):\n comb = math.comb(k, i)\n sign = (-1) ** i\n term = sign * comb * ((k - i) / k) ** n\n total += term\n return total\n\ndef main():\n input = sys.stdin.read().split()\n idx =... | \n```python\nimport math\nimport sys\n\ndef compute_prob(k, n):\n total = 0.0\n for i in range(k + 1):\n comb = math.comb(k, i)\n sign = (-1) ** i\n term = sign * comb * ((k - i) / k) ** n\n total += term\n return total\n\ndef main():\n input = sys.stdin.read().split()\n idx =... | 3 | [
1,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nBefore the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size n × n (n is ... | \nTo solve this problem, we need to generate an `n x n` matrix where:\n\n1. All elements are integers from `0` to `n-1`.\n2. The main diagonal contains only zeroes.\n3. The matrix is symmetric (i.e., `matrix[i][j] == matrix[j][i]` for all `i` and `j`).\n4. Each row contains distinct elements.\n\n---\n\n### ✅ Key Observ... | \n```python\n# YOUR CODE HERE\nimport sys\n\ndef generate_magic_matrix():\n n = int(sys.stdin.readline())\n matrix = [[0] * n for _ in range(n)]\n\n for i in range(n):\n if i % 2 == 0:\n left = 1\n right = n - 1\n even_list = []\n for k in range(n - 1):\n ... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nIt is a simplified version of problem F2. The difference between them is the constraints (F1: $k \\le 2$, F2: $k \\le 10$).\n\nYou are given an integer $n$. Find the ... | \n```python\nimport sys\nimport itertools\n\ndef solve_k1(n_str):\n m = len(n_str)\n for d in range(1, 10):\n candidate = int(str(d) * m)\n if candidate >= int(n_str):\n return candidate\n return int(\'1\' * (m + 1))\n\ndef generate_all_sets():\n single_sets = [set([d]) for d in ran... | \nTo solve the problem of finding the minimum $ k $-beautiful number $ x $ such that $ x \\geq n $, we utilize a structured approach that handles both $ k = 1 $ and $ k = 2 $ efficiently. \n\n---\n\n### **Approach**\n\n1. **Understanding k-beautiful numbers**:\n - A number is $ k $-beautiful if it contains no more th... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nBefore the start of the football season in Berland a strange magic ritual is held. The most experienced magicians have to find a magic matrix of the size n × n (n is ... | \nTo solve this problem, we need to generate an `n x n` matrix where:\n\n1. All elements are integers from `0` to `n-1`.\n2. The main diagonal contains only zeroes.\n3. The matrix is symmetric (i.e., `matrix[i][j] == matrix[j][i]` for all `i` and `j`).\n4. Each row contains distinct elements.\n\n---\n\n### ✅ Key Observ... | \nTo solve this problem, we are asked to generate an **n x n** symmetric matrix where:\n\n- The **main diagonal** contains only zeros.\n- The matrix is **symmetric** (i.e., matrix[i][j] == matrix[j][i] for all i and j).\n- Each row must contain **distinct elements**.\n- The matrix contains **all integers from 0 to n-1*... | 3 | [
1,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nPetr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way... | \nTo solve this problem, we need to determine whether a given permutation was generated using Petr\'s method or Alex\'s method. The key insight is based on the parity of the permutation, which is influenced by the number of swaps used during generation.\n\n---\n\n### 🔍 Approach\n\n1. **Cycle Detection**:\n - The per... | \nTo determine whether the given permutation was generated using Petr\'s method or Alex\'s method, we leverage the **parity** of the permutation. The key insight is that the number of swaps (which determines the permutation\'s parity) influences the number of cycles in the permutation\'s cycle decomposition.\n\n### Key... | 3 | [
1,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nCooking Examinations Authority (C.E.A.) is conducting an Ordinary Cooking Level (O.C.L.) test, which tests the candidate skills on three different aspects - Appearanc... | \nTo solve this problem, we need to determine the maximum points Chef can score in the Ordinary Cooking Level (O.C.L.) test, which consists of three aspects: Appearance, Flavor, and Texture. Each aspect has 20 problems, and Chef has a total of 240 minutes to solve them. The goal is to maximize the points Chef can achie... | \nTo solve the problem of determining the maximum points Chef can score in the O.C.L. test, we adopt a brute-force approach that iterates through all possible combinations of problems Chef can solve across the three aspects. Each aspect has a maximum of 20 problems, and we must ensure that the total time spent does not... | 3 | [
1,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nKoa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:\n\nIn one operation Koa sele... | \nTo solve this problem, we need to determine the number of distinct binary strings that can be obtained by performing a series of operations on a given binary string. Each operation allows merging two adjacent characters by setting the first to the maximum of the two and then removing the second character. The solutio... | \nTo solve the problem of determining how many distinct binary strings can be obtained from a given binary string using a specific merging operation, we can use a **dynamic programming** approach.\n\n### Key Idea\n\nEach operation allows us to merge adjacent characters by taking the maximum of the two and then deleting... | 0 | [
0,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nThere are $n$ children, numbered $1,2,\\ldots,n$, sitting around a circle in a clockwise manner. The ${i}$th child has a piece of paper with the number $a_i$ written ... | \nTo solve the problem of simulating the game of children updating their numbers based on their neighbors\' values over a large number of rounds, we leverage **matrix exponentiation** and **matrix transformations** to handle the large number of rounds efficiently.\n\n---\n\n### 🔍 Problem Breakdown\n\nEach child in a c... | \nTo solve this problem, we need to simulate a game where children sitting in a circle update their numbers based on their neighbors\' values over multiple rounds. The challenge is to efficiently compute the final values for each child starting from each possible initial position, given the constraints of very large nu... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nFox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.\n\nThe players take t... | \nTo solve this problem, we simulate the game where Ciel and Jiro take turns to pick cards from the top or bottom of piles, respectively. The goal is to determine the optimal strategy for both players to maximize their own scores.\n\n---\n\n### ✅ **Approach Explanation**\n\n1. **Input Parsing**: Read the number of pile... | \n```python\nimport sys\nfrom functools import lru_cache\n\ndef main():\n n = int(sys.stdin.readline())\n cards = []\n total_sum = 0\n for _ in range(n):\n parts = list(map(int, sys.stdin.readline().split()))\n s_i = parts[0]\n card_list = parts[1:]\n cards.append(card_list)\n ... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nRead problems statements in Mandarin Chinese and Russian. \n\nChef loves brackets. So much so, that rather than just use plain brackets like (), {}, or [], he has in... | \nTo solve this problem, we need to count the number of balanced bracket subsequences in a given sequence of integers. Each integer represents a bracket type, with negative values representing opening brackets and positive values representing closing brackets. The solution involves using dynamic programming to efficien... | \n```python\n# YOUR CODE HERE\nMOD = 10**9 + 7\n\ndef main():\n import sys\n input = sys.stdin.read().split()\n n = int(input[0])\n A = list(map(int, input[1:n+1]))\n \n dp = [[0] * n for _ in range(n)]\n \n # Initialize for i > j (empty subsequence)\n for i in range(n):\n for j in ran... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nSnuke can change a string t of length N into a string t\' of length N - 1 under the following rule:\n\n* For each i (1 ≤ i ≤ N - 1), the i-th character of t\' must be... | \nTo solve the problem of determining the minimum number of operations required to make all characters in a string the same, we utilize a strategy based on analyzing the spread of character occurrences within the string.\n\n---\n\n### ✅ Key Observations\n\n- Each operation reduces the length of the string by one.\n- Th... | \n```python\nimport sys\nfrom collections import defaultdict\n\ndef main():\n s = sys.stdin.readline().strip()\n char_indices = defaultdict(list)\n for idx, c in enumerate(s):\n char_indices[c].append(idx)\n \n min_ops = len(s) # Initialize with maximum possible value\n\n for c in char_indices... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nA new gangster is trying to take control of the city. He makes a list of his $N$ adversaries (e.g. gangster $\\mbox{1}$, gangster $2$, ... gangster $N-1$, gangster $N... | \n```python\nimport sys\n\ndef solve():\n input = sys.stdin.read().split()\n idx = 0\n N = int(input[idx])\n idx += 1\n K = int(input[idx])\n idx += 1\n\n mercenary_costs = []\n for _ in range(K):\n row = list(map(int, input[idx:idx+N]))\n mercenary_costs.append(row)\n idx +... | \nTo solve this problem, we need to determine the minimum cost for a gangster to eliminate all his adversaries using a set of mercenaries, each of whom can be assigned to a consecutive group of gangsters. The goal is to minimize the total cost while ensuring all gangsters are eliminated.\n\n### Approach\n1. **Problem A... | 1 | [
1,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nYou are given an array $a_1, a_2, \\dots , a_n$ and two integers $m$ and $k$.\n\nYou can choose some subarray $a_l, a_{l+1}, \\dots, a_{r-1}, a_r$. \n\nThe cost of su... | \n```python\n# YOUR CODE HERE\nimport sys\n\ndef main():\n input = sys.stdin.read().split()\n idx = 0\n n = int(input[idx])\n idx += 1\n m = int(input[idx])\n idx += 1\n k = int(input[idx])\n idx += 1\n a = list(map(int, input[idx:idx+n]))\n \n prefix_sum = [0] * (n + 1)\n for i in r... | \nTo solve this problem, we need to determine the maximum cost of any subarray from a given array, where the cost is defined as the sum of the subarray minus a penalty based on the length of the subarray. The penalty is determined by the ceiling of the subarray length divided by a given integer `m`, multiplied by anoth... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nThere are N players standing in a line, indexed 1 to N from left to right. They all play a game of Rock, Paper, Scissors. Each player has already decided which move t... | \n```python\nimport sys\n\ndef main():\n input = sys.stdin.read\n data = input().split()\n idx = 0\n T = int(data[idx])\n idx += 1\n results = []\n \n for _ in range(T):\n N = int(data[idx])\n idx += 1\n S = data[idx]\n idx += 1\n \n dp = [\'\'] * (N + 2... | \nTo solve this problem efficiently, we need to determine the winner of a sequential Rock, Paper, Scissors game for each starting position from 1 to N. The winner of the sequence from position `i` to position `N` is determined by sequentially battling each player from left to right.\n\n---\n\n### 🧠 Key Observations\n\... | 0 | [
0,
0
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nThe store sells $n$ beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a neckl... | \nTo solve the problem of determining the maximum length of a k-beautiful necklace that can be formed from a given set of beads, we follow a structured approach based on the periodic nature of such necklaces. The solution involves checking each possible necklace length from the maximum possible (equal to the number of ... | \n```python\nimport sys\nimport math\nfrom collections import Counter\n\ndef main():\n input = sys.stdin.read().split()\n idx = 0\n t = int(input[idx])\n idx += 1\n results = []\n for _ in range(t):\n n = int(input[idx])\n k = int(input[idx + 1])\n idx += 2\n s = input[idx]... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nKoa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form:\n\nIn one operation Koa sele... | \nTo solve this problem, we need to determine the number of distinct binary strings that can be obtained by performing a series of operations on a given binary string. Each operation allows merging two adjacent characters by setting the first to the maximum of the two and then removing the second character. The solutio... | \n```python\nimport sys\n\nMOD = 10**9 + 7\n\ndef main():\n s = sys.stdin.readline().strip()\n n = len(s)\n if n == 0:\n print(0)\n return\n\n # dp[i] will store a set of distinct strings for the first i characters\n dp = [set() for _ in range(n)]\n dp[0].add(s[0])\n \n for i in ra... | 2 | [
0,
1
] |
\nYou will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.\n\nYou are given an array $a_1, a_2, \\dots , a_n$ and two integers $m$ and $k$.\n\nYou can choose some subarray $a_l, a_{l+1}, \\dots, a_{r-1}, a_r$. \n\nThe cost of su... | \n```python\n# YOUR CODE HERE\nimport sys\n\ndef main():\n input = sys.stdin.read().split()\n idx = 0\n n = int(input[idx])\n idx += 1\n m = int(input[idx])\n idx += 1\n k = int(input[idx])\n idx += 1\n a = list(map(int, input[idx:idx+n]))\n \n prefix = [0] * (n + 1)\n for i in range... | \nTo solve this problem, we need to determine the maximum cost of any subarray from a given array, where the cost is defined as the sum of the subarray minus a penalty based on the length of the subarray. The penalty is determined by the ceiling of the subarray length divided by a given integer `m`, multiplied by anoth... | 2 | [
0,
1
] |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 7