source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
code_contests
verifiable_code
54_D. Writing a Song
Solve the following coding problem using the programming language python: One of the Hedgehog and his friend's favorite entertainments is to take some sentence or a song and replace half of the words (sometimes even all of them) with each other's names. The friend's birthday is approaching and the Hedgehog decided to...
vfc_63949
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\na\n10001\n", "output": "abbba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\nabba\n101\n", "output": "No solution\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
576_E. Painting Edges
Solve the following coding problem using the programming language python: Note the unusual memory limit for this problem. You are given an undirected graph consisting of n vertices and m edges. The vertices are numbered with integers from 1 to n, the edges are numbered with integers from 1 to m. Each edge can be unpa...
vfc_63953
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 600000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2 5\n1 2\n2 3\n1 3\n1 1\n2 1\n3 2\n3 1\n2 2\n", "output": "YES\nYES\nYES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 50 4\n1 2\n1 1\n1 1\n1 50\n1 50\n", "output"...
code_contests
verifiable_code
599_C. Day at the Beach
Solve the following coding problem using the programming language python: One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were...
```python n = int(input()) hs = list(map(int, input().split())) max_h = 0 rs = [] max_hs = [0] * n for i, h in enumerate(hs): rs.append((h, i)) max_h = max(max_h, h) max_hs[i] = max_h rs.sort() p, r = 0, -1 ans = 0 while r < n - 1: nh, nr = rs[p] if r >= nr: p += 1 else: r = nr ...
vfc_63957
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 1 3 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
620_B. Grandfather Dovlet’s calculator
Solve the following coding problem using the programming language python: Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (<https://en.wikipedia.org/wiki/Seven-segment_display>). <image> Max starts to type all the val...
```python #!/usr/bin/env python3 if __name__ == '__main__': a, b = map(int, input().split()) act = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] r = 0 for i in range(a, b+1): r += sum(act[ord(c)-ord('0')] for c in str(i)) print(r) ```
vfc_63961
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 15\n", "output": "39\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "222...
code_contests
verifiable_code
641_A. Little Artem and Grasshopper
Solve the following coding problem using the programming language python: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts ...
```python n = int(input()) s = input() arr = list(map(int, input().split())) seen = set() current_index = 0 while True: command = s[current_index] step = arr[current_index] if command == ">": current_index += step else: current_index -= step # print(current_index) if current_...
vfc_63965
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n&gt;&gt;&lt;\n2 1 1\n", "output": "FINITE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n&gt;&lt;\n1 2\n", "output": "FINITE\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
669_D. Little Artem and Dance
Solve the following coding problem using the programming language python: Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together. More detailed, there are n pairs of boys and girls standing in a circle. Initia...
```python import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 q = inp[ii]; ii += 1 summa = 0.0 diff = 0 par = 0 for _ in range(q): if inp[ii] == 1: x = inp[ii + 1]; ii += 2 summa += x par ^= x & 1 else: ii ...
vfc_63969
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 1\n2\n1 -2\n", "output": "1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 2\n2\n1 2\n", "output": "4 3 6 5 2 1 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
715_A. Plus and Square Root
Solve the following coding problem using the programming language python: ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '<image>' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Code...
```python import sys from math import * from fractions import gcd readints=lambda:map(int, input().strip('\n').split()) n=int(input()) prev=2 for i in range(1,n+1): nxt = (i*(i+1))**2 cur = (nxt-prev)//i print(cur) prev=int(sqrt(nxt)) ```
vfc_63977
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "2\n17\n46\n97\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "2\n17\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
735_C. Tennis Championship
Solve the following coding problem using the programming language python: Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if some...
```python f = [0, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 113490...
vfc_63981
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", ...
code_contests
verifiable_code
75_C. Modified GCD
Solve the following coding problem using the programming language python: Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are di...
```python import math from sys import * from bisect import bisect_right input=stdin.readline print=stdout.write a,b=map(int,input().split()) n=int(input()) gcd=math.gcd(a,b) ##print(gcd) factors=[] i=1 while(i*i<=gcd): if gcd%i==0: factors.append(gcd//i) if (i*i)!=gcd: factors.append...
vfc_63985
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 27\n3\n1 5\n10 11\n9 11\n", "output": "3\n-1\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "90 100\n8\n55 75\n46 68\n44 60\n32 71\n43 75\n23 79\n47 86\n11 57\n", "output": "-1\...
code_contests
verifiable_code
780_B. The Meeting Place Cannot Be Changed
Solve the following coding problem using the programming language python: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are n friends, and i-th of them is stan...
```python def solve(t,x,v): l=[x[i]-v[i]*t for i in range(len(x))] r=[x[i]+v[i]*t for i in range(len(x))] return 1 if max(l)<=min(r) else 0 n=int(input()) x=list(map(int,input().split())) v=list(map(int,input().split())) l=0 h=10**9 cnt=0 while l<h and cnt<100: mid=l+(h-l)/2 cnt+=1 if solve(mid...
vfc_63989
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 10 3 2\n2 3 2 4\n", "output": "1.400000", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n7 1 3\n1 2 1\n", "output": "2.000000", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
803_F. Coprime Subsequences
Solve the following coding problem using the programming language python: Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subseque...
```python # 803F import math import collections def do(): n = int(input()) nums = map(int, input().split(" ")) count = collections.defaultdict(int) for num in nums: for i in range(1, int(math.sqrt(num))+1): cp = num // i if num % i == 0: count[i] += 1 ...
vfc_63993
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 1 1\n", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
828_D. High Load
Solve the following coding problem using the programming language python: Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k...
```python import sys def main(): n,k = map(int,sys.stdin.readline().split()) a = n-k if a ==1: print(2) for i in range(k): print(1,i+2) elif a > k+1 : l = ((a-1)//k +1)*2 if (a-1)%k>1: print(l+2) elif (a-1)%k==1: print(l+1) ...
vfc_63997
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "2\n1 2\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "3\n1 2\n1 3\n1 4\n2 5\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
84_E. Track
Solve the following coding problem using the programming language python: You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path...
```python import sys from array import array # noqa: F401 from itertools import combinations from collections import deque def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, k = map(int, input().split()) chars = ( ['}' * (m + 2)] + ['}' + ''.join('{' if c == 'S' else '|' if c == 'T' ...
vfc_64001
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3 3\nTyS\n", "output": "y\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 2\nSba\nccc\naac\nccc\nabT\n", "output": "bcccc\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
873_B. Balanced Substring
Solve the following coding problem using the programming language python: You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones...
```python inp=lambda:map(int,input().split()) n=int(input()) s=input() a0=[0]*(10**5+1) a1=[0]*(10**5+1) if(s[0]=='0'): a0[0]=1 else: a1[0]=1 for i in range(1,n): if(s[i]=='0'): a0[i]=a0[i-1]+1 a1[i]=a1[i-1] else: a0[i]=a0[i-1] a1[i]=a1[i-1]+1 lab=[-2]*(2*10**5+1) m=[...
vfc_64005
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n111\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n11010111\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
899_A. Splitting in Teams
Solve the following coding problem using the programming language python: There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of ex...
```python n = int(input()) a = list(map(int,input().split())) one = a.count(1) two = a.count(2) def func(a,b): if(a>b): count = b a = a-b count = count + a//3 elif(b>a): count = a a = a-count elif(a==b): count = a return count if(one==0): pri...
vfc_64009
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 2 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
91_B. Queue
Solve the following coding problem using the programming language python: There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal ...
```python n = int(input()) A = [int(i) for i in input().split()] suf = [[10**10, -1] for i in range(n)] from bisect import bisect_left suf[-1][0] = A[-1] suf[-1][1] = n-1 for i in range(n-2, -1, -1): if suf[i+1][0] > A[i]: suf[i][0] = A[i] suf[i][1] = i else: suf[i][0] = suf[i+1][0] ...
vfc_64013
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n10 8 5 3 50 45\n", "output": "2 1 0 -1 0 -1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 3 1 10 11\n", "output": "1 0 -1 -1 -1 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
946_G. Almost Increasing Array
Solve the following coding problem using the programming language python: We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it). You are given an array a consisting of...
vfc_64017
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 8 9 5\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 4 3 2 1\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
995_D. Game
Solve the following coding problem using the programming language python: Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. E...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time (n, r) = (int(i) for i in input().split()) c = [int(i) for i in input().split()] start = time.time() s = sum(c) n2 = 2**n ans = [s/n2] for i in range(r): (k, new) = (int(i) for i in input().split()) s += new - c[k] c[k] ...
vfc_64025
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n0 1 2 3\n2 5\n0 4\n", "output": "1.5000000000\n2.2500000000\n3.2500000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n1 1 1 1\n", "output": "1.0000000000\n", "typ...
code_contests
verifiable_code
bakku-numbers
Solve the following coding problem using the programming language python: Aklank is fond of numbers which are divisible by either P1 or P2. He termed those numbers as Bakku numbers. Recently his best friend gave him a range of numbers. Now he is wondering what is the probability of finding Bakku numbers from that rang...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' from sys import stdin ar = map(int, stdin.readline().strip().split()) p1 = ar[0] p2 = ar[1] t = int(stdin.readline().strip()) #print p1, p2, t for i in xrange(0, t, 1): ar = ...
vfc_64029
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n2\n1 10\n20 34\n\nSAMPLE", "output": "0.500000\n0.466667\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7607 9769\n10\n1 1\n1 100000\n10000 100000\n999 1000\n7607 7607\n1 7605\n9770 ...
code_contests
verifiable_code
christmas-gamecon
Solve the following coding problem using the programming language python: Aniruddha and Andrew are playing a Game on Christmas Eve named "Christmas-Gamecon". In this they are given a list of numbers. In each turn alternatively one will select any one number from the list and decrease it by 1,2,3 or 4. The last person ...
```python def main(): test_cases = int(raw_input()) for _ in xrange(test_cases): n = int(raw_input()) list1 = raw_input().split() list2 = [] for i in xrange(n): list2.append(int(list1[i])%5) XOR = list2[0] for i in xrange(1, n): XOR = XOR ^ list2[i] if XOR == 0: print "Andrew" else: pr...
vfc_64033
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1 1\n2\n1 2\n\nSAMPLE", "output": "Andrew\nAniruddha\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n1 1\n2\n1 2\n\nSAMOLE", "output": "Andrew\nAniruddha\n", "type"...
code_contests
verifiable_code
elevator-manager
Solve the following coding problem using the programming language python: View Russian Translation In this problem the goal is to implement a program managing an elevator designed especially for mathematicians. The elevator can go to any of N floors numbered from 1 to N and it can carry an arbitrary number of people...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import math HUGE = 10**9 + 7 def _try_composite(a, d, n, s): if pow(a, d, n) == 1: return False for i in range(s): if pow(a, 2**i * d, n) == n-1: ...
vfc_64037
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 2\n1 2 3\n2 6 2\n\nSAMPLE", "output": "1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 2\n1 2 3\n2 1 2\n\nSAMPLE", "output": "1 3\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
heap-the-list
Solve the following coding problem using the programming language python: You will be given a list of space separated integers, your task is to form a min-heap tree from the given set of inputs and display the root element of the Min-heap formed. Input A list of n Space separated integers. Output Root element of t...
```python print sorted(map(int, raw_input().split()))[0] ```
vfc_64041
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "18 25 66 11 14 0 85 63 2 21 6 90 53 99 59 66 90 57 65 9 87 97 42 33 63 9 6 81 43 25 53 47 45 11 8 58 1 63 38 51 81 2 82 20 97 73 12 49 25 3 83 77 18 89 14 47 27 85 15 71 57 94 35 95 19 46 96 55 15 65", "output": "0\n", ...
code_contests
verifiable_code
lucky-numbers-20
Solve the following coding problem using the programming language python: Golu wants to find out the sum of Lucky numbers.Lucky numbers are those numbers which contain exactly two set bits.This task is very diffcult for him.So Help Golu to find sum of those numbers which exactly contain two set bits upto a given numbe...
```python import math, bisect temp , a , b , A , F = 1, [], [], [], {} while temp < 10**20: a.append(temp) temp=temp*2 for i in range(len(a)): for j in range(i+1,len(a)): b.append(a[i] + a[j]) b = sorted(b) for i in range(len(b)): if(i==0): A.append(b[i]) else: A.append(A[i-1] + b[i]) # print A[i] for _ in range...
vfc_64045
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n\nSAMPLE", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n74215\n6298825854637\n254237664381\n18611731909005\n7044762270511\n3888409250301\n1512558489677\n253060160...
code_contests
verifiable_code
problem-8
Solve the following coding problem using the programming language python: The penultimate task involved the calculation of the typical Fibonacci sequence up to the nth term. Input – single integer n Output – Fibonacci sequence up to the nth term, all terms on a new line SAMPLE INPUT 5 SAMPLE OUTPUT 1 1 2 3 5 The ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' #cout << fixed << setprecision(0) << fmod(((pow(1.6180339,i)-(pow(-0.6180339,i))) / 2.236067977) , pow(10,9)+7) << endl n = int(raw_input()) i = 1 whil...
vfc_64053
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n\nSAMPLE", "output": "1\n1\n2\n3\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "1\n1\n2\n3\n5\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
shantam-and-richness-1
Solve the following coding problem using the programming language python: Shantam is very rich , even richer than Richie Rich. He is extremely talented in almost everything except one , mathematics. So one day, he pays a visit to a temple (to pray for his upcoming mathematics exams) and decides to donate some amount ...
```python for _ in range(int(raw_input())): n,t=map(int,raw_input().split()) l,r,c,p,q,s=map(int,raw_input().split()) a=[0]*(n+5) for i in range(t): #l,r,c=map(int,raw_input().split()) if i: temp=l l= (l* p +...
vfc_64057
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2\n1 1 1 1 1 1\n5 1\n1 3 2 4 3 5\n\nSAMPLE", "output": "3 2\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 2\n1 1 1 1 1 1\n5 1\n1 3 2 4 1 5\n\nSAMPLE", "output": "3 2...
code_contests
verifiable_code
the-art-of-verification
Solve the following coding problem using the programming language python: Cleartrip decided that they wanted to verify the username and password of its users while they were authenticating for a process. One of the code service forms a GET URL which contains the username and password as its parameters. While parsing t...
```python inp=raw_input() P=inp.split('?') P1=P[0] P2=P[1] A=[] V=['username','pwd','profile','role','key'] for i in xrange(len(V)): if(i==len(V)-1): A.append(P2[P2.index(V[i]):]) else: A.append(P2[P2.index(V[i]):P2.index(V[i+1])-1]) for i in A: extract=i.split('=') print i.replace('=','...
vfc_64061
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "http://www.cleartrip.com/signin/service?username=test&pwd=test&profile=developer&role=ELITE&key=manager\n\nSAMPLE", "output": "username: test\npwd: test\nprofile: developer\nrole: ELITE\nkey: manager\n", "type": "stdin_...
code_contests
verifiable_code
xenny-and-classroom-circuits
Solve the following coding problem using the programming language python: Xenny was a teacher and his class consisted of N boys and N girls. He took all his students to the playground and asked them to stand in a straight line. The boys and the girls formed a perfect line, but Xenny seemed unhappy. He wanted them to f...
```python def func(typ,k,bg): count=0 if typ==0: for i in range(len(k)): if k[i]!=bg[i]: count+=1 return count/2 if typ==1 or typ==2: b=[] g=[] for i in range(len(k)): if k[i]!=bg[i]: if k[i]=='B': ...
vfc_64065
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\nBBGG\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n8\nBGBBGGBGBGGBBBGG\n5\nGGGGGBBBBB\n7\nGGBBBGBGBGGBGB", "output": "3\n2\n3\n", "type": "s...
code_contests
verifiable_code
p00066 Tic Tac Toe
Solve the following coding problem using the programming language python: Tic-tac-toe is a game in which you win when you put ○ and × alternately in the 3 × 3 squares and line up ○ or × in one of the vertical, horizontal, and diagonal lines (Fig.). 1 to Fig. 3) <image> | <image> | <image> --- | --- | --- Figure 1: ○ ...
```python ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: try: s = input() except EOFError: break flag = False for i in ok: if s[i[0]] == s[i[1]] == s[i[2]] and s[i[0]] != 's': print(s[i[0]]) flag = True ...
vfc_64109
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ooosxssxs\nxoosxsosx\nooxxxooxo", "output": "o\nx\nd", "type": "stdin_stdout" }, { "fn_name": null, "input": "ooosxssxs\nxooswsosx\nooxxxooxo", "output": "o\nd\nd\n", "type": "stdin_stdou...
code_contests
verifiable_code
p00198 Trouble in Shinagawa's Artifacts
Solve the following coding problem using the programming language python: Artist Shinagawa was asked to exhibit n works. Therefore, I decided to exhibit the six sides of the cube colored with paint as a work. The work uses all six colors, Red, Yellow, Blue, Magenta, Green, and Cyan, and each side is filled with one co...
```python D = [ (1, 5, 2, 3, 0, 4), # 'U' (3, 1, 0, 5, 4, 2), # 'R' (4, 0, 2, 3, 5, 1), # 'D' (2, 1, 5, 0, 4, 3), # 'L' ] p_dice = (0, 0, 0, 1, 1, 2, 2, 3)*3 def rotate_dice(L0): L = L0[:] for k in p_dice: yield L L[:] = (L[e] for e in D[k]) while 1: N = int(input()) if...
vfc_64113
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nCyan Yellow Red Magenta Green Blue\nCyan Yellow Red Magenta Green Blue\nRed Yellow Magenta Blue Green Cyan\n4\nRed Magenta Blue Green Yellow Cyan\nRed Yellow Magenta Blue Green Cyan\nMagenta Green Red Cyan Yellow Blue\nCyan Gree...
code_contests
verifiable_code
p00559 Foehn Phenomena
Solve the following coding problem using the programming language python: In the Kingdom of IOI, the wind always blows from sea to land. There are $N + 1$ spots numbered from $0$ to $N$. The wind from Spot $0$ to Spot $N$ in order. Mr. JOI has a house at Spot $N$. The altitude of Spot $0$ is $A_0 = 0$, and the altitud...
```python n, q, s, t = map(int, input().split()) a_lst = [int(input()) for _ in range(n + 1)] diff = [a_lst[i + 1] - a_lst[i] for i in range(n)] temp = sum([-d * s if d > 0 else -d * t for d in diff]) def score(d): if d > 0: return -s * d else: return -t * d for _ in range(q): l, r, x = map(int, input().s...
vfc_64121
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5 1 2\n0\n4\n1\n8\n1 2 2\n1 1 -2\n2 3 5\n1 2 -1\n1 3 5", "output": "-5\n-7\n-13\n-13\n-18", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 1 2\n0\n4\n1\n8\n1 2 2\n1 1 -2\n2 3 5\n1 2 -1\...
code_contests
verifiable_code
p00712 Unit Fraction Partition
Solve the following coding problem using the programming language python: A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p/q as the sum of finitely many unit fractions is called a partition of p/q into unit fractions...
```python from fractions import gcd def solve(p, q, a, n, l=1): ans = 1 if p==1 and q<=a and q>=l else 0 denom = max(l, q//p) p_denom = denom*p while n*q >= p_denom and denom <= a: #n/denom >= p/q: p_, q_ = p_denom-q, q*denom if p_ <= 0: denom += 1 p_denom += p ...
vfc_64125
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 120 3\n2 3 300 3\n2 3 299 3\n2 3 12 3\n2 3 12000 7\n54 795 12000 7\n2 3 300 1\n2 1 200 5\n2 4 54 2\n0 0 0 0", "output": "4\n7\n6\n2\n42\n1\n0\n9\n3", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00852 The Best Name for Your Baby
Solve the following coding problem using the programming language python: In the year 29XX, the government of a small country somewhere on the earth introduced a law restricting first names of the people only to traditional names in their culture, in order to preserve their cultural uniqueness. The linguists of the co...
vfc_64129
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\nA=a\nA=\nS=ASb\nS=Ab\n2 5\nS=aSb\nS=\n1 5\nS=S\n1 0\nS=S\n1 0\nA=\n2 0\nA=\nS=AA\n4 5\nA=aB\nA=b\nB=SA\nS=A\n4 20\nS=AAAAAAAAAA\nA=aA\nA=bA\nA=\n0 0", "output": "abb\n-\n-\n-\n-\n\naabbb\naaaaaaaaaaaaaaaaaaaa", "ty...
code_contests
verifiable_code
p00983 Reordering the Documents
Solve the following coding problem using the programming language python: Reordering the Documents Susan is good at arranging her dining table for convenience, but not her office desk. Susan has just finished the paperwork on a set of documents, which are still piled on her desk. They have serial numbers and were st...
```python def main(): mod = 10 ** 9 + 7 n, m = map(int, input().split()) a = [int(x) for x in input().split()] if not m: print(0) return mx = [0] * (n + 1) mn = [mod] * (n + 1) for i in range(n): if mx[i] > a[i]: mx[i + 1] = mx[i] else: ...
vfc_64133
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n1 3 4 2 6 5", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 5 4 2 6 5", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01115 Expression Mining
Solve the following coding problem using the programming language python: Expression Mining Consider an arithmetic expression built by combining single-digit positive integers with addition symbols `+`, multiplication symbols `*`, and parentheses `(` `)`, defined by the following grammar rules with the start symbol `...
```python import sys readline = sys.stdin.readline write = sys.stdout.write sys.setrecursionlimit(10**5) def solve(): N = int(readline()) if N == 0: return False S = readline().strip() + "$" L = len(S) pt = [0]*L st = [] for i in range(L): if S[i] == '(': st.appen...
vfc_64137
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 1073741824, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n(1+2)*3+3\n2\n1*1*1+1*1*1\n587\n1*(2*3*4)+5+((6+7*8))*(9)\n0", "output": "4\n9\n2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01253 Deadly Dice Game
Solve the following coding problem using the programming language python: T.I. Financial Group, a world-famous group of finance companies, has decided to hold an evil gambling game in which insolvent debtors compete for special treatment of exemption from their debts. In this game, each debtor starts from one cell on...
vfc_64141
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\nRBRBRB\n10 1\nRBBBRBBBBB\n10 2\nRBBBRBBBBB\n10 10\nRBBBBBBBBB\n0 0", "output": "0.50000000\n0.33333333\n0.22222222\n0.10025221", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\nRBRBR...
code_contests
verifiable_code
p01568 Repairing
Solve the following coding problem using the programming language python: In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network. The network consists of water pipe segments, stop valves and source point. A water pipe is represented by a segm...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def dot3(O, A, B): ox, oy = O; ax, ay = A; bx, by = B return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy) def cross3(O, A, B): ox, oy = O; ax, ay = A; bx, by = B return (ax - ox) * (by - oy) - (bx ...
vfc_64149
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n0 0 0 4\n0 2 2 2\n1 2\n0 1\n0 3", "output": "-1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01868 Scanner
Solve the following coding problem using the programming language python: Problem statement Here are $ N $ sheets of paper. You want to scan all paper by using $ 3 $ scanners in parallel. Each piece of paper has a fixed scanning time, and the time it takes to scan the $ i $ th paper is $ T_i $. You can scan the paper...
vfc_64157
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n1\n1\n1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1\n1\n2\n1", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
p02005 Colorful Drink
Solve the following coding problem using the programming language python: In the Jambo Amusement Garden (JAG), you sell colorful drinks consisting of multiple color layers. This colorful drink can be made by pouring multiple colored liquids of different density from the bottom in order. You have already prepared seve...
```python import sys liquids={} O=[] N = int(input()) for i in range(N): C,D=(input().split()) if C in liquids.keys(): liquids[C].append(int(D)) else: liquids[C]=[] liquids[C].append(int(D)) for i in liquids.keys(): liquids[i]=list(set(liquids[i])) liquids[i].sort() M = int...
vfc_64161
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nwhite 10\nblack 10\n2\nblack\nwhite", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nwhite 20\nblack 10\n2\nblack\norange", "output": "No", "type": "stdin_st...
code_contests
verifiable_code
p02290 Projection
Solve the following coding problem using the programming language python: For given three points p1, p2, p, find the projection point x of p onto p1p2. <image> Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xi, yi ≤ 10000 * p1 and p2 are not identical. Input xp1 yp1 xp2 yp2 q xp0 yp0 xp1 yp1 ... xpq−1 ypq−1 In the firs...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 0 0 3 4 1 2 5 output: 3.1200000000 4.1600000000 """ import sys class Segment(object): __slots__ = ('source', 'target') def __init__(self, source, target): self.source = complex(source) self.target = complex(target) def do...
vfc_64169
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 3 4\n1\n2 5", "output": "3.1200000000 4.1600000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 2 0\n3\n-1 1\n0 1\n1 1", "output": "-1.0000000000 0.0000000000\n0.0000000000 ...
code_contests
verifiable_code
cdva1606
Solve the following coding problem using the programming language python: Nanu, a Clash of Clans player is so much obsessed with the game and its new update. She wants to win as much battles as she can. Each of the enemy clan has N troops of lowercase letters. And for the attack she takes an army of length M. In the n...
```python from sys import stdin, stdout t = int(stdin.readline()) while t: t -= 1 n, m, k = map(int, stdin.readline().strip().split(' ')) N = stdin.readline().strip() M = stdin.readline().strip() M = M[:k] count = 0 for i in range(len(N)-k+1): s = N[i:i+k] if s == M: count += 1 if count == 0: count = -...
vfc_64177
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2 2\nabcab\nab\n5 2 1\nabccc\ncc", "output": "2\n3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
dce05
Solve the following coding problem using the programming language python: The captain of the ship TITANIC is a little .... off the track. He needs to select the crew for the ship. But everyone seems to be eligible. So to test their intelligence, he plays a game. The contestants have to stand in a line. They are give...
```python from math import floor from math import log n = int(raw_input()); while n > 0: no = int(raw_input()); print int(2**floor(log(no, 2))); n -= 1; ```
vfc_64181
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n12", "output": "4\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n6\n12", "output": "4\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
iiti00
Solve the following coding problem using the programming language python: Freakin' news has recently claimed that they have discovered a civilization on mars and that they have established contact with the martians. Following is a summary of the dawn hour breakin' news on freakin' news : Occassionally, the martian m...
```python l = raw_input().split() n, k = int(l[0]), int(l[1]) l = raw_input().split() l = [int(i) for i in l] a, b = 1, -1 ans = -1*sum(l[:n-k])+sum(l[n-k:]) print ans ```
vfc_64185
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 0 \n-2 5", "output": "-3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 \n-4 -4", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mvcoin
Solve the following coding problem using the programming language python: There is a line with 1000 cells numbered from 1 to 1000 from left to right and N coins placed on it. Coin i is placed at cell Xi, and no two coins are placed at the same cell. Bob would like to move the coins to the N leftmost cells of the line...
```python for _ in xrange(int(raw_input())): N, K = map(int, raw_input().split()) coins = map(int, raw_input().split()) if coins[-1] == N: print 0 continue seconds = 0 count = 0 for __ in xrange(coins[-1], 0, -1): if __ in coins: count += 1 else: seconds += ((count - 1) / K + 1) print seconds ```
vfc_64189
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n2 4 7\n5 3\n1 2 3 4 5", "output": "5\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 2\n2 4 7\n3 3\n1 2 3 4 5", "output": "5\n0\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
rrgame
Solve the following coding problem using the programming language python: You are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (i≠j), such that Ai, Aj ≤ M, and add K to both. The game ends when y...
```python import sys N, M, K = map(lambda x: int(x), sys.stdin.readline().split()) A = map(lambda x: int(x), sys.stdin.readline().split()) moves = map(lambda x: (M - x) / K + 1, A) moves_sum = sum(moves) moves_max = max(moves) moves.remove(moves_max) moves_max2 = max(moves) min_moves = max((moves_sum - moves_max + 1...
vfc_64193
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2\n1 2 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2\n0 2 3", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
witmath
Solve the following coding problem using the programming language python: Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only th...
```python import random def modulo(a,b,c): x = 1 y = a while b>0: if b%2==1: x = (x*y)%c y = (y*y)%c b = b/2 return x%c def millerRabin(N,iteration): if N<2: return 0 if N!=2 and N%2=...
vfc_64197
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n3\n4", "output": "2\n3\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\n3\n4", "output": "3\n3\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1020_B. Badge
Solve the following coding problem using the programming language python: In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of n students doing yet another trick. Let's assume that all these students are numbered from 1 to ...
```python n = int(input()) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] - 1 ans = [0] * len(p) for i in range(len(p)): visit = [0] * len(p) visit[i] = 1 p0 = i while True: pp = p[p0] if (visit[pp] == 1): ans[i] = pp break else: visit[pp] = 1 p0...
vfc_64201
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 2\n", "output": "2 2 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1043_E. Train Hard, Win Easy
Solve the following coding problem using the programming language python: Zibi is a competitive programming coach. There are n competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, ...
```python import sys n,m = [int(x) for x in sys.stdin.buffer.readline().split()] inp = [int(x) for x in sys.stdin.buffer.read().split()] order = sorted(range(n),key=lambda i:inp[2*i]-inp[2*i+1]) score = [0]*n val = sum(inp[1:2*n:2]) for ind in range(n): i = order[ind] # Do second problem together with orde...
vfc_64205
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3\n1 2\n2 3\n1 3\n", "output": "0 0 0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1066_C. Books Queries
Solve the following coding problem using the programming language python: You have got a shelf and want to put some books on it. You are given q queries of three types: 1. L id — put a book having index id on the shelf to the left from the leftmost existing book; 2. R id — put a book having index id on the shel...
```python from sys import * n = int(stdin.readline()) A = {} i ,j = 1,0 # print(i,j) for l in range(n): x, y = stdin.readline().split("\n") x, k = map(str,x.split()) k = int(k) if(x=='?'): stdout.write(str(min(A[k]-i , j-A[k]))+'\n') elif(x=='R'): j += 1 A[k] = j else: i -= 1 A[k] = i ```
vfc_64209
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nL 1\nR 2\nR 3\n? 2\nL 4\n? 1\nL 5\n? 1\n", "output": "1\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\nL 100\nR 100000\nR 123\nL 101\n? 123\nL 10\nR 115\n? 100\nR 110\n? 115\...
code_contests
verifiable_code
1089_F. Fractions
Solve the following coding problem using the programming language python: You are given a positive integer n. Find a sequence of fractions (a_i)/(b_i), i = 1 … k (where a_i and b_i are positive integers) for some k such that: $$$ \begin{cases} $b_i$ divides $n$, $1 < b_i < n$ for $i = 1 … k$ \\\ $1 ≤ a_i < b_i$ for ...
```python from math import sqrt from itertools import count, islice from fractions import Fraction def isPrime(n): return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1))) def factors(n: int): _factors = [] for i in range(2, int(sqrt(n)) + 1): times = 0 while n % i == 0: ...
vfc_64213
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "YES\n2\n1 2\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
1108_A. Two distinct points
Solve the following coding problem using the programming language python: You are given two segments [l_1; r_1] and [l_2; r_2] on the x-axis. It is guaranteed that l_1 < r_1 and l_2 < r_2. Segments may intersect, overlap or even coincide with each other. <image> The example of two segments on the x-axis. Your proble...
```python qry=int(input()) for _ in range(qry): lrs=list(map(int,input().split())) if lrs[0]==lrs[2]: print(lrs[0],lrs[3]) else: print(lrs[0],lrs[2]) ```
vfc_64217
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 1 2\n2 6 3 4\n2 4 1 3\n1 2 1 3\n1 4 5 8\n", "output": "1 2\n2 3\n2 1\n1 3\n1 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n233 233333 123 456\n", "output": "233 123\n",...
code_contests
verifiable_code
1137_C. Museums Tour
Solve the following coding problem using the programming language python: In the country N, there are n cities connected by m one-way roads. Although this country seems unremarkable, there are two interesting facts about it. At first, a week lasts d days here. At second, there is exactly one museum in each city of the...
vfc_64221
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 3\n3 1\n1 2\n2 4\n4 1\n2 3\n011\n110\n111\n001\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 7\n1 2\n1 3\n2 3\n1111111\n0000000\n0111111\n", "output": "2\n...
code_contests
verifiable_code
1155_E. Guess the Root
Solve the following coding problem using the programming language python: Jury picked a polynomial f(x) = a_0 + a_1 ⋅ x + a_2 ⋅ x^2 + ... + a_k ⋅ x^k. k ≤ 10 and all a_i are integer numbers and 0 ≤ a_i < 10^6 + 3. It's guaranteed that there is at least one i such that a_i > 0. Now jury wants you to find such an integ...
vfc_64225
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n\n2\n\n1\n\n", "output": "? 0\n? 1\n? 2\n? 3\n? 4\n? 5\n? 6\n? 7\n? 8\n? 9\n? 10\n! 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000002\n\n0\n", "output": "? 0\n? 1\n? 2\n? ...
code_contests
verifiable_code
1178_B. WOW Factor
Solve the following coding problem using the programming language python: Recall that string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters. For example, for the string a="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow"...
```python s = input() n = len(s) count_o = [] count_w = 0 count = 0 for i in range(1, n): if s[i] == 'v' and s[i-1] == 'v': count_w += 1 elif s[i] == 'o': count_o.append(count_w) for c in count_o: count += c * (count_w-c) print(count) ```
vfc_64229
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "vvvovvv\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "vvovooovovvovoovoovvvvovovvvov\n", "output": "100\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1196_B. Odd Sum Segments
Solve the following coding problem using the programming language python: You are given an array a consisting of n integers a_1, a_2, ..., a_n. You want to split it into exactly k non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belon...
```python import math import sys for _ in range(int(input())): n,k=map(int,sys.stdin.readline().split()) l=list(map(int,sys.stdin.readline().split())) c=0 for i in l: if i%2!=0: c+=1 if c%2!=k%2 or c<k: print("NO") else: print("YES") cnt=1 for ...
vfc_64233
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2\n", "output": "YES\n1 3 5\nNO\nNO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1213_D1. Equalizing by Division (easy version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the number of elements in the array. You are given an array a consisting of n integers. In one move you can choose any a_i and divide it by 2 rounding down (in other words, in one move you c...
```python import collections import functools import math import sys import bisect def In(): return map(int, sys.stdin.readline().split()) input = sys.stdin.readline def eqdiv(): n,k = In() cost = [0]*int(1e5*2+10) count = cost[:] l = list(In()) l.sort() for i in l: i = int(i) ...
vfc_64237
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 3 4 5\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1236_E. Alice and the Unfair Game
Solve the following coding problem using the programming language python: Alice is playing a game with her good friend, Marisa. There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. Then Alice will have m chances to guess where the do...
```python import sys input = sys.stdin.readline n,m=map(int,input().split()) A=list(map(int,input().split())) if n==1: print(0) sys.exit() from collections import Counter R=Counter() L=Counter() for i in range(n): R[i+1]=1 L[i+1]=1 for i,a in enumerate(A): x=R[a-(i+1)] del R[a-(i+1)] R[...
vfc_64241
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n3 1\n", "output": "21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n2 2 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
1254_C. Point Ordering
Solve the following coding problem using the programming language python: This is an interactive problem. Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertice...
vfc_64245
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n\n15\n\n-1\n\n1", "output": "\n1 1 4 6\n\n2 1 5 6\n\n2 2 1 4\n\n0 1 3 4 2 6 5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1297_I. Falling Blocks
Solve the following coding problem using the programming language python: Recently, Polycarp has invented a new mobile game with falling blocks. In the game, n blocks are falling down, one at a time, towards a flat surface with length d units. Each block can be represented as a rectangle with coordinates from l_i to ...
vfc_64253
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3\n", "output": "\n1\n2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 6\n1 2\n3 3\n2 3\n1 3\n2 4\n3 6\n1 5\n1 5\n", "output": "\n1\n2\n3\n1\n2\n3\n4\n4\n", ...
code_contests
verifiable_code
1340_C. Nastya and Unexpected Guest
Solve the following coding problem using the programming language python: If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. On the way from Denis's house to the girl's house is a road of n lines. This road can't be always cro...
```python import collections n,m=map(int,input().split()) arr=list(map(int,input().split())) arr=sorted(arr) g,r=map(int,input().split()) q=collections.deque() q.append((0,0,0)) checked=[[-1]*(g) for _ in range(m)] checked[0][0]=0 while len(q)!=0: v,t,cnt=q.popleft() if v!=m-1: cost1=arr[v+1]-arr[v] if t+c...
vfc_64261
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "13 4\n0 3 7 13\n9 9\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 5\n0 3 7 14 15\n11 11\n", "output": "45", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1362_C. Johnny and Another Rating Drop
Solve the following coding problem using the programming language python: The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitor...
```python class Solution(): def __init__(self): for t in range(int(input())): n = int(input()) self.solve(n) def solve(self, n): b = format(n, "b") res = 0 while b: res += int(b, 2) b = b[:-1] print(res) Solution() ``...
vfc_64265
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n7\n11\n1\n2000000000000\n", "output": "8\n11\n19\n1\n3999999999987\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1403_B. Spring cleaning
Solve the following coding problem using the programming language python: Spring cleanings are probably the most boring parts of our lives, except this year, when Flóra and her mother found a dusty old tree graph under the carpet. This tree has N nodes (numbered from 1 to N), connected by N-1 edges. The edges gathere...
vfc_64273
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n1 2\n2 4\n4 5\n5 6\n5 7\n3 4\n1 4\n2 2 4\n1 1\n", "output": "\n-1\n10\n8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1425_D. Danger of Mad Snakes
Solve the following coding problem using the programming language python: Mr. Chanek The Ninja is one day tasked with a mission to handle mad snakes that are attacking a site. Now, Mr. Chanek already arrived at the hills where the destination is right below these hills. The mission area can be divided into a grid of s...
```python # from __future__ import print_function,division # range = xrange import sys input = sys.stdin.readline sys.setrecursionlimit(10**4) from sys import stdin, stdout from collections import defaultdict, Counter from functools import lru_cache M = 10**9+7 fact = [1]*(2001) def fac(n): if(n==0 or n==1): ...
vfc_64277
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 1\n1 1 10\n2 2 20\n2 3 30\n5 2 40\n", "output": "33800\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1 0\n1 1 10\n1 999 30\n1 1000 40\n1 2 20\n", "output": "3000\n", "t...
code_contests
verifiable_code
1472_A. Cards for Friends
Solve the following coding problem using the programming language python: For the New Year, Polycarp decided to send postcards to all his n friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size w × h, which can be cut into pieces. Polycarp can cut any sheet of paper...
```python import sys def cardsForFriends(): for _ in range(int(input())): w, h, n = map(int, input().split()) ans, tmp = 1, 1 while not w & 1: w //= 2 ans += tmp tmp *= 2 while not h & 1: h //= 2 ans += tmp tmp *= 2 if ans >= n: print('YES') else: print('NO') def main(): cardsFor...
vfc_64285
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4\n", "output": "\nYES\nNO\nYES\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1024 1024 22212\n", "output": "YES\n", "type"...
code_contests
verifiable_code
1520_B. Ordinary Numbers
Solve the following coding problem using the programming language python: Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers. For a given number n, find the number of ordinary numbers...
```python """ Don't see the standings during the contest!!! you will lose motivation. """ # ---------------------------------------------------Import Libraries--------------------------------------------------- import sys import time import os from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, co...
vfc_64293
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1\n2\n3\n4\n5\n100\n", "output": "\n1\n2\n3\n4\n5\n18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n69696969\n", "output": "69\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
175_D. Plane of Tanks: Duel
Solve the following coding problem using the programming language python: Vasya plays the Plane of Tanks. Tanks are described with the following attributes: * the number of hit points; * the interval between two gun shots (the time required to recharge the gun); * the probability that the gun shot will not ...
vfc_64301
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 3 50 50 0\n100 2 48 50 0\n", "output": "0.88888888889\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 3 50 50 0\n100 1 50 50 50\n", "output": "0.50000000000\n", "type":...
code_contests
verifiable_code
195_E. Building Forest
Solve the following coding problem using the programming language python: An oriented weighted forest is an acyclic weighted digraph in which from each vertex at most one edge goes. The root of vertex v of an oriented weighted forest is a vertex from which no edge goes and which can be reached from vertex v moving al...
vfc_64305
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0\n1 1 5\n0\n0\n2 3 1 4 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0\n0\n1 2 1\n2 1 5 2 2\n1 1 2\n1 3 4\n", "output": "30\n", "type": "stdin_stdou...
code_contests
verifiable_code
219_E. Parking Lot
Solve the following coding problem using the programming language python: A parking lot in the City consists of n parking spaces, standing in a line. The parking spaces are numbered from 1 to n from left to right. When a car arrives at the lot, the operator determines an empty parking space for it. For the safety's ...
vfc_64309
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 11\n1 15\n1 123123\n1 3\n1 5\n2 123123\n2 15\n1 21\n2 3\n1 6\n1 7\n1 8\n", "output": "1\n7\n4\n2\n7\n4\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n1 362993\n2 362993\n1 2...
code_contests
verifiable_code
243_B. Hydra
Solve the following coding problem using the programming language python: One day Petya got a birthday present from his mom: a book called "The Legends and Myths of Graph Theory". From this book Petya learned about a hydra graph. A non-oriented graph is a hydra, if it has a structure, shown on the figure below. Namel...
vfc_64313
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 10 3 3\n1 2\n2 3\n1 3\n1 4\n2 5\n4 5\n4 6\n6 5\n6 7\n7 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 12 2 3\n1 2\n2 3\n1 3\n1 4\n2 5\n4 5\n4 6\n6 5\n6 7\n7 5\n8 7...
code_contests
verifiable_code
268_E. Playlist
Solve the following coding problem using the programming language python: Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to listen to the songs. Of course, ther...
```python n=input() v=[0]*n e,f=0,0 for i in range(n): a,b=map(int,raw_input().split()) e+=a v[i]=(a*b,100-b) v.sort(cmp=lambda x,y:x[1]*y[0]-x[0]*y[1]) for x in v: e+=f*x[1]/100. f+=x[0]/100. print '%.12f'%e ```
vfc_64317
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n300 0\n300 50\n240 50\n360 80\n", "output": "2121.000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n150 20\n150 50\n100 50\n", "output": "537.500000000\n", "type"...
code_contests
verifiable_code
291_B. Command Line Arguments
Solve the following coding problem using the programming language python: The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively a...
```python import sys # f = sys.stdin # f = open("input.txt", "r") a = input() i = 0 while i < len(a): if a[i] == '"': end = a.index('"', i+1) print("<", a[i+1:end], ">", sep="") i = end+1 elif a[i] != " " != '"' and (a[i-1] == " " or i-1 < 0): try: end = a.index(" ", ...
vfc_64321
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "\"RUn.exe O\" \"\" \" 2ne, \" two! . \" \"\n", "output": "<RUn.exe O>\n<>\n< 2ne, >\n<two!>\n<.>\n< >\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "firstarg second \"\" \n", ...
code_contests
verifiable_code
316_D2. PE Lesson
Solve the following coding problem using the programming language python: Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is thro...
```python n=int(raw_input()) MOD=1000000007 a=map(int,raw_input().split()) twos=sum(a)-n ones=n-twos ans=0 x=ones/2 weirds=[1,1] for i in xrange(2,x+3): weirds.append(weirds[-1]*(2*i-1)) nc2i=[1] for i in xrange(1,x+3): nc2i.append(nc2i[-1]*(ones-2*i+1)*(ones-2*i+2)/(2*i-1)/(2*i)) for i in xrange(x+1): ans+=weirds[i...
vfc_64325
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1 2 2 1 2 1 1 2\n", "output": "16800", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 2 1 2\n", "output": "120", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
339_E. Three Swaps
Solve the following coding problem using the programming language python: Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as follows (from left to right): 1, 2,...
```python n = input() a = [0] + map(int, raw_input().split()) la, ra, m = [0]*3, [0]*3, 0 def left(): for i in xrange(1, n+1): if a[i] != i: return i return 0 def right(): for i in xrange(n, 0, -1): if a[i] != i: return i return 0 def find(x): for i in xran...
vfc_64329
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 1 4 3 6 5\n", "output": "3\n5 6\n3 4\n1 2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
362_B. Petya and Staircases
Solve the following coding problem using the programming language python: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time...
```python import sys n, m = map(int, input().split()) if m != 0: data = [int(el) for el in input().split()] data.sort() if data[0] == 1 or data[-1] == n: print('NO') sys.exit() for e in range(m - 2): if data[e] + data[e + 1] + data[e + 2] == data[e] * 3 + 3: print('...
vfc_64333
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5\n2 4 5 7 9\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5\n2 4 8 3 6\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
385_E. Bear in the Field
Solve the following coding problem using the programming language python: Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection o...
```python #Simple non-optimized class of matrices. Used with small dense matrices. import functools import itertools import math class NotAMatrixError(Exception): pass class MatrixSizeError(Exception): def __init__(self, s1, s2): print('sizes do not match : ', s1, ', ', s2) class NotSquareError(Excep...
vfc_64337
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1 -1 -1 2\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 2 0 1 2\n", "output": "3 1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
406_D. Hill Climbing
Solve the following coding problem using the programming language python: This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one). There are n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills a...
vfc_64341
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 4\n2 1\n3 2\n4 3\n6 4\n7 4\n3\n3 1\n5 6\n2 3\n", "output": "5\n6\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
433_E. Tachibana Kanade's Tofu
Solve the following coding problem using the programming language python: Tachibana Kanade likes Mapo Tofu very much. One day, the canteen cooked all kinds of tofu to sell, but not all tofu is Mapo Tofu, only those spicy enough can be called Mapo Tofu. Each piece of tofu in the canteen is given a m-based number, all ...
vfc_64345
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 10 12\n2 5 9\n6 6 3 5 4 9 7\n2 0 6 1\n3 6 7 2 1\n", "output": "635439", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 1\n1 1\n3 1 0 0\n1 1 1\n1 0 1\n", "output": "97", "ty...
code_contests
verifiable_code
456_B. Fedya and Maths
Solve the following coding problem using the programming language python: Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression: (1n + 2n + 3n + 4n) mod 5 for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. i...
```python n=int(input()) if n==0: answer=4 else: a=1 if n%4==0: a+=6+1 elif n%4==1: a+=2+3 elif n%4==2: a+=4+9 else: a+=8+7 if n%2==0: a+=6 else: a+=4 answer=a%5 print(answer) ```
vfc_64349
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "124356983594583453458888889\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
478_E. Wavy numbers
Solve the following coding problem using the programming language python: A wavy number is such positive integer that for any digit of its decimal representation except for the first one and the last one following condition holds: the digit is either strictly larger than both its adjacent digits or strictly less than ...
vfc_64353
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "97461 457\n", "output": "1805270103\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
500_G. New Year Running
Solve the following coding problem using the programming language python: New Year is coming in Tree Island! In this island, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists exactly one path between them. For every person in Tree Island, it takes exa...
vfc_64357
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 3\n3 6\n7 4\n3 7\n5 4\n7 2\n4\n6 5 5 3\n3 5 4 6\n1 5 1 3\n1 5 3 1\n", "output": "2\n1\n0\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 3\n3 6\n7 4\n3 7\n5 4\n7 2\n4\n6 5 5 ...
code_contests
verifiable_code
526_E. Transmitting Levels
Solve the following coding problem using the programming language python: Optimizing the amount of data transmitted via a network is an important and interesting part of developing any network application. <image> In one secret game developed deep in the ZeptoLab company, the game universe consists of n levels, loca...
vfc_64361
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n2 4 2 1 3 2\n7\n4\n6\n", "output": "2\n4\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 20\n1 3 2 2 4 3 1 3 4\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n...
code_contests
verifiable_code
552_A. Vanya and Table
Solve the following coding problem using the programming language python: Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with ...
```python n = int(input()) matrix = [[0] * 100 for i in range(100)] for t in range(n): x1, y1, x2, y2 = map(int, input().split()) for i in range(y1 - 1, y2): for j in range(x1 - 1, x2): matrix[i][j] += 1 answer = 0 for row in matrix: answer += sum(row) print(answer) ```
vfc_64365
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1 3 3\n1 1 3 3\n", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1 2 3\n2 2 3 3\n", "output": "10", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
579_A. Raising Bacteria
Solve the following coding problem using the programming language python: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hop...
```python xStr = input() x = int(xStr) put = 0 while x>0: if x%2 == 0: x = x//2 continue else: put = put+1 x = x//2 print(put) ```
vfc_64369
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "343000816\n...
code_contests
verifiable_code
5_E. Bindian Signalizing
Solve the following coding problem using the programming language python: Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case ...
```python n = int(input()) hill = tuple(map(int, input().split())) pairs = 0 highest, at = max((h, k) for k, h in enumerate(hill)) last = highest count = 0 p = list() push = p.append pop = p.pop for at in range(at - 1, at - n, -1): current = hill[at] while current > last: pairs += count last, co...
vfc_64373
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 4 5 3\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2118 2118 2118\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
622_C. Not Equal on a Segment
Solve the following coding problem using the programming language python: You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi. For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi. Input The first line contains two integers n, m (1 ≤ n, m ≤ ...
```python import sys n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) assert(len(a) == n) prev = [-1] * n l = r = 0 while l < n: while r < n and a[l] == a[r]: r += 1 # [l, r) --> a[l] for i in range(l, r): prev[i] = l - 1 l = r for i in r...
vfc_64377
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n1 2 1 1 3 5\n1 4 1\n2 6 2\n3 4 1\n3 4 2\n", "output": "2\n3\n-1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n3 2 4 5 5\n1 3 3\n", "output": "3\n", "type": "stdi...
code_contests
verifiable_code
643_F. Bears and Juice
Solve the following coding problem using the programming language python: There are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days). Bears love drinking juice. They don't like wine but they can't distinguish it from juice by taste or smell. A bear doesn't slee...
vfc_64381
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 3\n", "output": "32\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
670_E. Correct Bracket Sequence Editor
Solve the following coding problem using the programming language python: Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-...
```python n, m, p = [int(x) for x in input().split()] A = input().rstrip() B = input().rstrip() pair = [0] * n stack = [] for (i, c) in enumerate(A): if c == '(': stack.append(i) else: j = stack.pop() pair[i] = j pair[j] = i start = 0 pointer = p - 1 left = list(range(-1, n-1))...
vfc_64385
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12 5 3\n((()())(()))\nRRDLD\n", "output": "(()(()))\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 8 8\n(())()()\nLLLLLLDD\n", "output": "()()\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
717_C. Potions Homework
Solve the following coding problem using the programming language python: Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singi...
```python fuck = int(input()) a = sorted(int(input()) for _ in range(fuck)) print(sum(a[i]*a[-i-1] for i in range(fuck))%10007) # Surprise motherfucker ```
vfc_64393
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n3\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n4\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
737_E. Tanya is 5!
Solve the following coding problem using the programming language python: Tanya is now five so all her friends gathered together to celebrate her birthday. There are n children on the celebration, including Tanya. The celebration is close to its end, and the last planned attraction is gaming machines. There are m mac...
vfc_64397
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 15\n11 7\n2 2 10 1 5\n1 2 20\n2 1 4 2 3\n", "output": "20\n01\n17\n1 1 0 2\n3 2 0 2\n2 2 0 2\n1 1 2 1\n2 2 2 1\n3 2 2 1\n3 1 3 4\n1 2 3 4\n2 2 3 4\n1 2 7 1\n2 2 7 1\n2 2 8 5\n1 2 8 5\n1 1 13 2\n2 2 13 2\n2 2 15 3\n2 2 18 ...
code_contests
verifiable_code
761_D. Dasha and Very Difficult Problem
Solve the following coding problem using the programming language python: Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai. Abo...
```python read = lambda: map(int, input().split()) n, l, r = read() a = list(read()) p = list(read()) d = [i for i in range(n)] d.sort(key = lambda x: p[x]) cur = l - a[d[0]] b = [0] * n for ind in d: b[ind] = a[ind] + cur if b[ind] < l: cur = l - a[ind] b[ind] = l cur += 1 if max(b) > r: ...
vfc_64401
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 9\n3 4 8 9\n3 2 1 4\n", "output": "2 2 2 9 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6\n", "output": "-1", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
784_F. Crunching Numbers Just for You
Solve the following coding problem using the programming language python: You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done... You are given an array of integers. S...
```python a = input()[2:] n = [0 for i in range(1000000)] g = 123 for i in range(130000): g *= 3 a = list(map(int, a.split())) x = [0 for _ in range(len(a))] for i in range(len(x)): x[i] = min(a) a.remove(x[i]) for o in x: print(o, end=' ') ```
vfc_64405
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 1 2\n", "output": "1 2 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 54 100 27 1 33 27 80 49 27 6\n", "output": "1 6 27 27 27 33 49 54 80 100 ", "type": "stdin_stdout...
code_contests
verifiable_code
852_A. Digits
Solve the following coding problem using the programming language python: John gave Jack a very hard problem. He wrote a very big positive integer A0 on a piece of paper. The number is less than 10200000 . In each step, Jack is allowed to put ' + ' signs in between some of the digits (maybe none) of the current number...
vfc_64417
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5806\n", "output": "5+8+0+6\n1+9\n1+0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
876_B. Divisiblity of Differences
Solve the following coding problem using the programming language python: You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the ...
```python n, k , m = map(int, input().split()) a = list(map(int, input().split())) ai =[[]*100000 for i in range(100000)] h = 0 z = 0 v = 0 for i in range(n): h =a[i]%m ai[h].append(a[i]) if len(ai[h])==k: print('Yes') print(*ai[h]) v +=1 break if v == 0: print('No') ```
vfc_64421
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 3\n1 8 4\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 5\n2 7 7 7\n", "output": "Yes\n2 7 7\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
8_B. Obsession with Robots
Solve the following coding problem using the programming language python: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to...
```python __author__ = "runekri3" def cells_touching(cell_1, cell_2): abs_x = abs(cell_1[0] - cell_2[0]) if abs_x > 1: return False abs_y = abs(cell_1[1] - cell_2[1]) if abs_y > 1: return False if not (abs_x == 1 and abs_y == 1): return True movements = input() total_move...
vfc_64425
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "RRUULLDD\n", "output": "BUG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "LLUUUR\n", "output": "OK\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
922_A. Cloning Toys
Solve the following coding problem using the programming language python: Imp likes his plush toy a lot. <image> Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine ...
```python # Imports ############################################## # Input (x, y) = tuple(map(lambda x:int(x), input().split())) ############################################## # Main code yes = 'Yes' no = 'No' res = yes if y == 0: res = no elif y == 1 and x != 0: res = no elif x < y-1: res = no elif (...
vfc_64429
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1001\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
977_F. Consecutive Subsequence
Solve the following coding problem using the programming language python: You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal...
```python n=int(input()) l=list(map(int,input().split())) d={} dp=[0 for i in range(n)] ind=dp[:] dp[0]=1 d[l[0]]=0 for i in range(1,len(l)): if l[i]-1 in d: dp[i]=1+dp[d[l[i]-1]] ind[i]=d[l[i]-1] else: dp[i]=1 d[l[i]]=i print(max(dp)) i=dp.index(max(dp)) mx=max(dp) ans=[] while mx: ...
vfc_64437
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10 9 8 7\n", "output": "1\n1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 3 5 2 4 6\n", "output": "2\n1 4 \n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
bear-and-bowling-3
Solve the following coding problem using the programming language python: Limak is an old brown bear. He often goes bowling with his friends. For rolling a ball one gets a score - a non-negative integer number of points. Score for the i-th roll is multiplied by i and scores are summed up. For example, for rolls with ...
```python s=0 mod=(10**9)+7 n=input() c=pow(2,n-1,mod) d=pow(2,abs(n-2),mod) arr=map(int,raw_input().split()) for i in xrange(n): s=((s%mod)+((arr[i]*c)%mod))%mod c=((c%mod)+(d%mod))%mod print s%mod ```
vfc_64445
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6 12 8\n\nSAMPLE", "output": "160\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
clock-mania
Solve the following coding problem using the programming language python: In PIET's CS Deparment there is a contest of Geometry. In this contest students are told to find minimum angle between hour and minute hand. Input: The first line contains the number of test cases, T. T lines follow, each of which contains two ...
```python for _ in xrange(input()): hr,mn=map(int,raw_input().split()) if hr==12: hr=0 ahr=int(hr*30)+int(mn*0.5) amn=int(mn*6) angle=abs(ahr-amn) if angle>180: angle=360-angle print angle ```
vfc_64449
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n12 30\n06 00\n\nSAMPLE", "output": "165\n180\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n11 12\n12 13\n12 02\n05 22\n02 18\n07 06\n07 55\n03 30\n08 36\n09 46", "output": "...
code_contests
verifiable_code
expand-it-1
Solve the following coding problem using the programming language python: Ma5termind and Subway are bored of their normal life.They want to do something interesting so that they can enjoy their last sem of college life.As usual Ma5termind comes up with a simple and interesting game. Ma5termind gives Subway a compress...
```python import re S = str(raw_input()) pairs = re.findall(r'([a-z])([0-9]+)', S) alphabets_count = [0] * 26 for pair in pairs: alphabets_count[ord(pair[0])-97] += int(pair[1]) for Q_I in range(int(raw_input())): K = int(raw_input()) res = -1 for i in range(26): if K <= alphabets_count[i]: res = chr(i+97)...
vfc_64453
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a2b3c2a1\n4\n2\n5\n1\n8\n\nSAMPLE", "output": "a\nb\na\nc\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "a2b3c2a1\n4\n4\n5\n1\n8\n\nSAMPLE", "output": "b\nb\na\nc\n", "type": ...
code_contests
verifiable_code
himu-and-long-drive-3
Solve the following coding problem using the programming language python: Himu wants to go on a long drive with his girlfriend. There are N cities numbered from 1 to N, and every city is connected to every other city with bidirectional road. The length of a road is equal to XOR of the city numbers it is connecting. Fo...
```python t = int(raw_input()) while t: a=1 n =int(raw_input()) n = n^1 while(n): n/=2 a=a*2 a-=1 print a t-=1 ```
vfc_64457
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n7900\n7755\n9858\n5346\n9566\n3655\n9743\n194\n387\n669\n3447\n4042\n1555\n2658\n7923\n6305\n5828\n2814\n...
code_contests
verifiable_code
magic-sum
Solve the following coding problem using the programming language python: We have a FULL binary tree i.e. each node except leaves has two children. The magic sum between any two leaf nodes (both possibly same) is the number obtained after adding values of all the nodes (including starting and ending nodes) in a uniq...
```python def tlnr(i): global lis if 2*i+1 > len(lis)-1: return lis[i],lis[i] ldia=tlnr(2*i+1) rdia=tlnr(2*i+2) return max(ldia[0],rdia[0],ldia[1]+rdia[1]+lis[i]),max(ldia[1],rdia[1])+lis[i] T = int(raw_input()) for _ in xrange(T): N = int(raw_input()) lis = [int(e) for e in raw_input().split()] print tlnr(0)[...
vfc_64461
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n7\n2 4 5 8 -4 3 -6\n\nSAMPLE", "output": "22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n7\n2 3 5 8 -4 3 -6\n\nSAMPLE", "output": "21\n", "type": "stdin_stdout" }...