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 | drgnbool | Solve the following coding problem using the programming language python:
In the world of DragonBool there are fierce warriors called Soints. Also there are even fiercer warriors called Sofloats – the mortal enemies of Soints.
The power of each warrior is determined by the amount of chakra he possesses which is some... | ```python
from sys import stdin
for trial in xrange(int(stdin.readline())):
N,M = map(int,stdin.readline().split())
sointsChakras = (101)*[0]
sofloatsChakras = (101)*[0]
for i in xrange(N):
C,L = map(int,stdin.readline().split())
sointsChakras[L]+=C
for i in xrange(M):
C,L ... | vfc_57941 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 3\n10 1\n20 2\n5 2\n5 2\n18 1\n5 5\n73 87\n69 13\n36 36\n77 46\n43 93\n49 46\n74 93\n78 87\n99 13\n59 36",
"output": "8\n89\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n10 ... |
code_contests | verifiable_code | numgame | Solve the following coding problem using the programming language python:
Alice and Bob play the following game. They choose a number N to play with. The rules are as follows :
1) Alice plays first, and the two players alternate.
2) In his/her turn, a player can subtract from N any proper divisor (not equal to N) ... | ```python
t = int(raw_input())
while t>0:
n = int(raw_input())
if n%2==1:
print "BOB"
else:
print "ALICE"
t-=1
``` | vfc_57949 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2",
"output": "BOB\nALICE\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | smcd1 | Solve the following coding problem using the programming language python:
Problem description.
Ram over slept and is late for class!
Ram doesn’t like to goto college, so he decides
to give his card to his friend. Unfortunately, Teacher got to know that number of students are less then present in the class.
Help Teache... | ```python
n=int(raw_input())
x=raw_input()
count=0
for i in x:
if i=='.':
count+=1
print count
``` | vfc_57953 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n.###.",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n.#\"#.",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1004_E. Sonya and Ice Cream | Solve the following coding problem using the programming language python:
Sonya likes ice cream very much. She eats it even during programming competitions. That is why the girl decided that she wants to open her own ice cream shops.
Sonya lives in a city with n junctions and n-1 streets between them. All streets are... | vfc_57957 | {
"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": "6 2\n1 2 3\n2 3 4\n4 5 2\n4 6 3\n2 4 6\n",
"output": "4",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1028_E. Restore Array | Solve the following coding problem using the programming language python:
While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers a_1, a_2, …, a_n. Since the talk was long and not promising, Kostya created a new cyclic array b_1, b_2, …, b_{n} so that b_i = (a_i m... | ```python
####################################### Define
maxN = int(2e5 + 10)
n = 0
b = [0] * maxN
ans = [0] * maxN
####################################### Functions
####################################### Main
n = int(input())
inp = input().split()
flag = False
for i in range(1, n + 1) :
b[i] = int(inp[i - 1])
... | vfc_57961 | {
"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": "2\n4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 3 1 0\n",
"output": "YES\n7 3 8 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1047_A. Little C Loves 3 I | Solve the following coding problem using the programming language python:
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution... | ```python
def main():
n = int(input())
if (n % 3 == 0) or (n % 3 == 1):
print(1, 1, n - 2)
else:
print(1, 2, n - 3)
if __name__ == '__main__':
main()
``` | vfc_57965 | {
"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": "233",
"output": "1 2 230\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "1 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6... |
code_contests | verifiable_code | 1070_J. Streets and Avenues in Berhattan | Solve the following coding problem using the programming language python:
Berhattan is the capital of Berland. There are n streets running parallel in the east-west direction (horizontally), and there are m avenues running parallel in the south-north direction (vertically). Each street intersects with each avenue, for... | ```python
t=input()
for i in xrange(t):
n, m, k=map(int, raw_input().split())
cnt=[0]*26
for ch in raw_input():
cnt[ord(ch)-ord('A')]+=1
assert sum(cnt)==k
result=1000000000
for common in xrange(26):
dp=[False]*(n+1)
dp[0]=True
for cur in xrange(26):
if cur!=common:
cur=cnt[cur]
for i in xrange... | vfc_57969 | {
"difficulty": "16",
"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\n4 4 8\nCZBBCZBC\n1 1 4\nTTCT\n",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3 9\nEEZZEEZZZ\n2 7 9\nEEZZEEZZZ\n",
"output": "0\n4\n",
"type": "stdin... |
code_contests | verifiable_code | 1092_E. Minimal Diameter Forest | Solve the following coding problem using the programming language python:
You are given a forest — an undirected graph with n vertices such that each its connected component is a tree.
The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the shortest path betwee... | ```python
from collections import deque
##make the tree
n,m=[int(x) for x in input().split()]
tree={}
for i in range(m):
a,b=[int(x) for x in input().split()]
if a not in tree:
tree[a]=[b]
else:
tree[a].append(b)
if b not in tree:
tree[b]=[a]
else:
tree[b].append(a)
f... | vfc_57973 | {
"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\n1 3\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n",
"output": "1\n1 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1111_D. Destroy the Colony | Solve the following coding problem using the programming language python:
There is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.
Each colony arrangement can be expressed as a string of even length, where the i-th character of the string represents the type of ... | ```python
from sys import stdin
MOD = 1000000007
s = stdin.readline().strip()
n = len(s)
buc = [0] * 101
fac = [0] * (n + 1)
inv = [0] * (n + 1)
dp = [0] * (n + 1)
# temp_dp = [0] * (n+1)
ans = [[0] * 55 for _ in range(55)]
def find(c: 'str') -> 'int':
if 'A' <= c <= 'Z':
return ord(c) - ord('A') + 26
... | vfc_57977 | {
"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": "abcd\n1\n1 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abba\n2\n1 4\n1 2\n",
"output": "2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
code_contests | verifiable_code | 1141_B. Maximal Continuous Rest | Solve the following coding problem using the programming language python:
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a_1, a_2, ..., a_n (each a_i is either 0 or 1), where a_i=0 if Polycarp works during the i-th hour of the... | ```python
n=int(input())
ans=0
curr=0
l=list(map(int,input().split()))
for i in range(2*n):
if(l[i%n]==1):
curr+=1
else:
curr=0
ans=max(ans,curr)
print(ans)
``` | vfc_57981 | {
"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": "5\n1 0 1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n0 1 0 1 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 115_A. Party | Solve the following coding problem using the programming language python:
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at... | ```python
import sys;readline = sys.stdin.buffer.readline
def i1(): return int(readline())
def nl(): return [int(s) for s in readline().split()]
def nn(n): return [int(readline()) for i in range(n)]
def nlp(x): return [int(s)+x for s in readline().split()]
def nll(n): return [[int(s) for s in readline().split()] for i ... | vfc_57985 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n-1\n1\n2\n1\n-1\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1182_A. Filling Shapes | Solve the following coding problem using the programming language python:
You have a given integer n. Find the number of ways to fill all 3 × n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap.
<image> This picture describes when n = 4. The left one... | ```python
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def MI(): return map(int,... | vfc_57989 | {
"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": "1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 11_A. Increasing Sequence | Solve the following coding problem using the programming language python:
A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t.
You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What... | ```python
n,d=map(int,input().split())
l=[int(i) for i in input().split()]
s=0
import math
for i in range(1,n):
if l[i]>l[i-1]:
continue
diff=l[i-1]-l[i]+1
s+=math.ceil(diff/d)
l[i]+=d*math.ceil(diff/d)
print(s)
``` | vfc_57993 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 3 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1240_A. Save the Nature | Solve the following coding problem using the programming language python:
You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!
You have n tickets to sell. The price of the i-th ticket is p_i. As a teller, you have a possibility to ... | ```python
t = int(input())
for case_num in range(t):
n = int(input())
p = list(map(int, input().split(' ')))
x, a = map(int, input().split(' '))
y, b = map(int, input().split(' '))
k = int(input())
p.sort()
p.reverse()
sum = [0]
for i in range(n):
sum.append(sum[-1] + p[i])
... | vfc_58001 | {
"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\n1\n100\n50 1\n49 1\n100\n8\n100 200 100 200 100 200 100 100\n10 2\n15 3\n107\n3\n1000000000 1000000000 1000000000\n50 1\n50 1\n3000000000\n5\n200 100 100 100 100\n69 5\n31 2\n90\n",
"output": "-1\n6\n3\n4\n",
"type":... |
code_contests | verifiable_code | 1282_B2. K for the Price of One (Hard Version) | Solve the following coding problem using the programming language python:
This is the hard version of this problem. The only difference is the constraint on k — the number of gifts in the offer. In this version: 2 ≤ k ≤ n.
Vasya came to the store to buy goods for his friends for the New Year. It turned out that he wa... | ```python
T=int(input())
for _ in range(T):
n,amt,k=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l);dp=[0]*(n+1);ans=0;
for i in range(n):
if i-k>=-1:dp[i]=dp[i-k]+l[i]
else:dp[i]=l[i]+dp[i-1]
#print(dp)
for i in range(n):
if dp[i]<=amt:ans=i+1;
print(ans)
``` | vfc_58009 | {
"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": "8\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n",
"output": "3\n4\n1\n1\n2\n0\n4\n5\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1302_C. Segment tree or Fenwick? | Solve the following coding problem using the programming language python:
This is an unusual problem in an unusual contest, here is the announcement: [http://codeforces.com/blog/entry/73543](//codeforces.com/blog/entry/73543)
You are given an array A of length n, initially filled with zeros. You need to process q que... | vfc_58013 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 5\n2 1 6\n1 3 2\n2 2 4\n1 6 3\n2 1 6\n5 3\n1 3 7\n1 1 4\n2 1 5\n",
"output": "\n0\n2\n5\n11\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1326_C. Permutation Partitions | Solve the following coding problem using the programming language python:
You are given a permutation p_1, p_2, …, p_n of integers from 1 to n and an integer k, such that 1 ≤ k ≤ n. A permutation means that every number from 1 to n is contained in p exactly once.
Let's consider all partitions of this permutation into... | ```python
import sys
input = sys.stdin.readline
if __name__ == "__main__":
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_val = sum(range(n, n - k, -1))
num_perm = 1
last_idx = -1
for i in range(n):
if p[i] > n - k:
if last_idx != -1:
... | vfc_58017 | {
"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 5\n2 1 5 3 4\n",
"output": "15 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n2 1 3\n",
"output": "5 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1367_A. Short Substrings | Solve the following coding problem using the programming language python:
Alice guesses the strings that Bob made for her.
At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers ... | ```python
t=int(input())
for i in range (t):
a=input()
print(a[0::2]+a[-1])
``` | vfc_58025 | {
"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\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n",
"output": "abac\nac\nbcdaf\nzzzzzz\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nabbaac\nabbaac\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n",
"ou... |
code_contests | verifiable_code | 1388_A. Captain Flint and Crew Recruitment | Solve the following coding problem using the programming language python:
Despite his bad reputation, Captain Flint is a friendly person (at least, friendly to animals). Now Captain Flint is searching worthy sailors to join his new crew (solely for peaceful purposes). A sailor is considered as worthy if he can solve F... | ```python
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
t = 1
t = int(input())
while t:
t -= 1
n = int(input())
# s = input()
if n > 30:
if (n-30) in [6, 10, 14]:
if n > 31:
print('YES')
print(6,10,15,n-31... | vfc_58029 | {
"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": "7\n7\n23\n31\n36\n44\n100\n258\n",
"output": "NO\nNO\nYES\n6 10 14 1\nYES\n6 10 15 5\nYES\n6 10 15 13\nYES\n6 10 14 70\nYES\n6 10 14 228\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 1408_H. Rainbow Triples | Solve the following coding problem using the programming language python:
You are given a sequence a_1, a_2, …, a_n of non-negative integers.
You need to find the largest number m of triples (i_1, j_1, k_1), (i_2, j_2, k_2), ..., (i_m, j_m, k_m) such that:
* 1 ≤ i_p < j_p < k_p ≤ n for each p in 1, 2, …, m;
* a_... | vfc_58033 | {
"difficulty": "14",
"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\n1\n1\n2\n0 0\n3\n0 1 0\n6\n0 0 1 2 0 0\n6\n0 1 0 0 1 0\n6\n0 1 3 2 0 0\n6\n0 0 0 0 5 0\n12\n0 1 0 2 2 2 0 0 3 3 4 0\n",
"output": "0\n0\n1\n2\n1\n1\n1\n2\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 142_B. Help General | Solve the following coding problem using the programming language python:
Once upon a time in the Kingdom of Far Far Away lived Sir Lancelot, the chief Royal General. He was very proud of his men and he liked to invite the King to come and watch drill exercises which demonstrated the fighting techniques and tactics of... | ```python
n, m = sorted(map(int, input().split()))
k = 4 * (m >> 2)
print(m if n == 1 else k + 2 * min(2, m - k) if n == 2 else (m * n + 1 >> 1))
``` | vfc_58037 | {
"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": "2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1526_E. Oolimry and Suffix Array | Solve the following coding problem using the programming language python:
Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array.
More formally, given a suffix array of length n and having an alphabet size k, count the number of strings that produce such a suffix arr... | ```python
MOD = 998244353
n, k = map(int, input().split())
arr = list(map(int, input().split()))
pos = [-1] * (n+1)
for i, a in enumerate(arr):
pos[a] = i
pos[-1] = -1
for i in range(n-1):
if pos[arr[i]+1] < pos[arr[i+1]+1]:
k += 1
if k < n:
print(0)
else:
fact = [1]
for i in range(1, k+1)... | vfc_58053 | {
"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 200000\n0 1 2 3 4 5\n",
"output": "\n822243495",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n0 2 1\n",
"output": "\n1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 158_C. Cd and pwd commands | Solve the following coding problem using the programming language python:
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).
Directories... | ```python
#!/usr/bin/env python3
def pwd(cur):
if len(cur) == 0:
print('/')
else:
print('/' + '/'.join(cur) + '/')
def process(cmd, cur):
cmd = cmd[3:]
ds = cmd.split('/')
if cmd[0] == '/':
cur = []
for d in ds:
if d == '..':
cur.pop()
el... | vfc_58057 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd\n",
"output": "/\n/home/vasya/\n/home/\n/home/petya/\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\ncd /a/b\npwd\ncd ../... |
code_contests | verifiable_code | 178_C2. Smart Beaver and Resolving Collisions | Solve the following coding problem using the programming language python:
The Smart Beaver from ABBYY has a lot of hobbies. One of them is constructing efficient hash tables. One of the most serious problems in hash tables is resolving collisions. The Beaver is interested in this problem very much and he decided to ex... | vfc_58061 | {
"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": "10 2 7\n+ 11 0\n+ 22 2\n+ 33 6\n+ 44 0\n+ 55 0\n- 22\n+ 66 0\n",
"output": " 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... | |
code_contests | verifiable_code | 224_E. Partial Sums | Solve the following coding problem using the programming language python:
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element number... | ```python
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
p=10**9+7
n,k=map(int,input().split())
b=list(map(int,input().split(... | vfc_58069 | {
"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": "3 1\n1 2 3\n",
"output": "1 3 6 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 0\n3 14 15 92 6\n",
"output": "3 14 15 92 6 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 249_C. Piglet's Birthday | Solve the following coding problem using the programming language python:
Piglet has got a birthday today. His friend Winnie the Pooh wants to make the best present for him — a honey pot. Of course Winnie realizes that he won't manage to get the full pot to Piglet. In fact, he is likely to eat all the honey from the p... | vfc_58073 | {
"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\n2 2 3\n5\n1 2 1\n2 1 2\n1 2 2\n3 1 1\n3 2 2\n",
"output": "0.000000000000\n0.333333333333\n1.000000000000\n1.000000000000\n2.000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... | |
code_contests | verifiable_code | 273_D. Dima and Figure | Solve the following coding problem using the programming language python:
Dima loves making pictures on a piece of squared paper. And yet more than that Dima loves the pictures that depict one of his favorite figures.
A piece of squared paper of size n × m is represented by a table, consisting of n rows and m column... | vfc_58077 | {
"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\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n",
"output": "571\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "48 1... | |
code_contests | verifiable_code | 297_A. Parity Game | Solve the following coding problem using the programming language python:
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then ... | ```python
print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO')
``` | vfc_58081 | {
"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": "01011\n0110\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0011\n1110\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 31_D. Chocolate | Solve the following coding problem using the programming language python:
Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided ... | ```python
w,h,n=list(map(int,input().split()))
a=[[0 for i in range(2*w-1)] for j in range(2*h-1)]
for i in range(1,2*h-1,2):
for j in range(1,2*w-1,2):
a[i][j]=' '
for i in range(n):
x1,y1,x2,y2=list(map(int,input().split()))
if x1==x2:
if x1!=0 and x1!=w:
for j in range(min(y1,... | vfc_58085 | {
"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 4 2\n0 1 2 1\n0 3 2 3\n",
"output": "2 2 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1\n",
"output": "1 1 1 1 \n",
"type": "stdin_stdout... |
code_contests | verifiable_code | 344_D. Alternating Current | Solve the following coding problem using the programming language python:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started e... | ```python
class Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items)-1]
def size(se... | vfc_58089 | {
"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": "++\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "+-\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-++-\n... |
code_contests | verifiable_code | 368_A. Sereja and Coat Rack | Solve the following coding problem using the programming language python:
Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook.
Tonigh... | ```python
racks, fine = map(int, input().split())
cost = list(map(int, input().split()))
cost.sort()
guests = int(input())
if guests > racks:
print (sum(cost) - ((guests - racks) * fine))
else:
print (sum(cost[:guests]))
``` | vfc_58093 | {
"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": "2 1\n2 1\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n2 1\n10\n",
"output": "-5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 390_B. Inna, Dima and Song | Solve the following coding problem using the programming language python:
Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much.
A song is a sequence of notes. Dima and Inna want to ... | ```python
num = int(input())
arr_a = list(map(int,(input()).split()))
arr_b = list(map(int,(input()).split()))
joy = 0
for i in range(num):
if arr_b[i] == 1:
joy -= 1
continue
if arr_a[i] * 2 >= arr_b[i]:
temp = arr_b[i] // 2
joy = joy + temp * (arr_b[i] - temp)
else:
... | vfc_58097 | {
"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 1 2\n2 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 412_A. Poster | Solve the following coding problem using the programming language python:
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The s... | ```python
n, k = map(int, input().split())
s = input()
def goRight():
i = k - 1
while i < n - 1:
print("RIGHT")
i += 1
i = n - 1
while i >= 0:
print("PRINT", s[i])
if i:
print("LEFT")
i -= 1
def goLeft():
i = k - 1
while i > 0:
print("LEFT")
i -= 1
i = 0
while i < n:
... | vfc_58101 | {
"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": "2 1\nR1\n",
"output": "PRINT R\nRIGHT\nPRINT 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\nR1\n",
"output": "PRINT 1\nLEFT\nPRINT R\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 439_C. Devu and Partitioning of the Array | Solve the following coding problem using the programming language python:
Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?
Given an array consisting of distinct integers.... | ```python
def solve():
n,k,p=map(int,input().split())
a=list(map(int,input().split()))
even=list(filter(lambda x: x%2==0, a))
odd=list(filter(lambda x:x%2==1, a))
if (len(odd)-(k-p))%2!=0:
print("NO");
return
ans=[[] for _ in range(k)]
for i in range(k-p):
if odd:
... | vfc_58105 | {
"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 5 3\n7 14 2 9 5\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 460_E. Roland and Rose | Solve the following coding problem using the programming language python:
Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and steal it.
To protect the rose, Roland want... | ```python
s = [[None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, No... | vfc_58109 | {
"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": "4 1\n",
"output": "16\n-1 0\n-1 0\n1 0\n1 0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 484_D. Kindergarten | Solve the following coding problem using the programming language python:
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty se... | ```python
#import sys
#input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
dp = [0] * n
pos, neg = -10 ** 18, -10 ** 18
for i, x in enumerate(a):
prv = 0 if i == 0 else dp[i - 1]
dp[i] = max(neg + x, pos - x, prv)
pos = max(pos, prv + x)
neg = max(neg, prv - x)
print(dp[-... | vfc_58113 | {
"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": "3\n3 3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 508_D. Tanya and Password | Solve the following coding problem using the programming language python:
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the passwo... | ```python
from collections import Counter, defaultdict
def main():
ht = defaultdict(list)
cnt = Counter()
n = int(input())
for _ in range(n):
s = input()
h, t = s[:2], s[1:]
ht[h].append(t)
cnt[h] += 1
cnt[t] -= 1
st = nd = flag = True
for t, i in cnt.it... | vfc_58117 | {
"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\nabc\nbCb\ncb1\nb13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa\n",
"output": "YES\naaaaaaaaa\n",
"type": "stdin_st... |
code_contests | verifiable_code | 533_A. Berland Miners | Solve the following coding problem using the programming language python:
The biggest gold mine in Berland consists of n caves, connected by n - 1 transitions. The entrance to the mine leads to the cave number 1, it is possible to go from it to any remaining cave of the mine by moving along the transitions.
The mine... | vfc_58121 | {
"difficulty": "7",
"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\n5 8 4 6 3 12\n1 2\n1 3\n4 2\n2 5\n6 3\n6\n7 4 2 5 3 11\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n10 14 7 12 4 50 1\n1 2\n2 3\n2 4\n5 1\n6 5\n1 7\n6\n7 3 4 8 8 10... | |
code_contests | verifiable_code | 557_E. Ann and Half-Palindrome | Solve the following coding problem using the programming language python:
Tomorrow Ann takes the hardest exam of programming where she should get an excellent mark.
On the last theoretical class the teacher introduced the notion of a half-palindrome.
String t is a half-palindrome, if for all the odd positions i (<... | vfc_58125 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "bbaabb\n13\n",
"output": "bbaabb",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abbabaab\n7\n",
"output": "abaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 583_C. GCD Table | Solve the following coding problem using the programming language python:
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
<image>
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of b... | ```python
import collections as cc
import math as mt
I=lambda:list(map(int,input().split()))
n,=I()
l=I()
f=cc.Counter(l)
ans=[]
for i in range(n):
now=max(f)
f[now]-=1
for j in ans:
f[mt.gcd(now,j)]-=2
ans.append(now)
f+=cc.Counter()
print(*ans)
``` | vfc_58129 | {
"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": "2\n1 1 1 1\n",
"output": "1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n42\n",
"output": "42",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 627_D. Preorder Test | Solve the following coding problem using the programming language python:
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.
Jacob's teacher will evaluate his model and grade Jacob ba... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
g = [[] for _ in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u-1].append(v-1)
g[v-1].append(u-1)
stack = [0]
done = [False] * n
par = [0] * n
order = []
while len(stack) > 0... | vfc_58137 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 5 5 5\n1 2\n1 3\n1 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 651_D. Image Preview | Solve the following coding problem using the programming language python:
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Simila... | ```python
import bisect
def preview(n, a, b, t, S):
t -= b+1 if S[0] else 1
S[0] = False
if t < 0:
return 0
R = []
s = 0
for i in range(1, n):
s += a + (b+1 if S[i] else 1)
if s > t:
break
R.append(s)
else:
return n
L = []
s = 0... | vfc_58141 | {
"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": "5 2 4 1000\nhhwhh\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2 4 13\nhhwhh\n",
"output": "4",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 677_B. Vanya and Food Processor | Solve the following coding problem using the programming language python:
Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, t... | ```python
n, h, k = map(int, input().split())
pots = map(int, input().split())
comb = [0]
for pot in pots:
if (comb[-1] % k + pot <= h):
comb[-1] += pot
else:
comb.append(pot)
sec = lambda x : x // k + int(x % k > 0)
ans = sum(map(sec, comb))
print(ans)
``` | vfc_58145 | {
"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": "5 6 3\n5 5 5 5 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 6 3\n1 2 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 6_B. President's Office | Solve the following coding problem using the programming language python:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the offi... | ```python
n, m, c = input().split()
n, m = int(n), int(m)
lst = []
for i in range(n):
lst.append(input())
N = set()
for i in range(n):
for j in range(m):
if lst[i][j] == c:
if j != 0 and lst[i][j-1] != c and lst[i][j-1] != ".":
N.add(lst[i][j-1])
if i != 0 and lst[i-1][j] != c and lst[i-1][j] != ".":
... | vfc_58149 | {
"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": "3 4 R\nG.B.\n.RR.\nTTT.\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 Z\n...\n.H.\n..Z\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 721_D. Maxim and Array | Solve the following coding problem using the programming language python:
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single oper... | ```python
import heapq as hq
from math import ceil
n, k, x = [int(i) for i in input().strip().split(' ')]
arr = [int(i) for i in input().strip().split(' ')]
is_neg = False
for i in arr:
if i < 0:
is_neg = True if is_neg == False else False
narr = [[abs(i), pos, i < 0] for pos, i in enumerate(arr)]
hq.heapi... | vfc_58153 | {
"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": "3 2 7\n5 4 2\n",
"output": "5 11 -5 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 743_B. Chloe and the sequence | Solve the following coding problem using the programming language python:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence ... | ```python
n, k = list(map(int, input().split()))
finish = False
length = 1
for i in range(n-1):
length = length * 2 + 1
while n!=1:
gran = length // 2 + 1
if k == gran:
print(n)
finish = True
break
if k < gran:
length = length // 2
n -= 1
if k > gran:
... | vfc_58157 | {
"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": "4 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 766_D. Mahmoud and a Dictionary | Solve the following coding problem using the programming language python:
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he d... | ```python
class Union:
def __init__(self, n):
self.p = {i:i for i in range(n)}
self.rank = {i:1 for i in range(n)}
def find(self, x):
if x < 0: return x
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(s... | vfc_58161 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 6 5\nhi welcome hello ihateyou goaway dog cat rat\n1 hi welcome\n1 ihateyou goaway\n2 hello ihateyou\n2 hi goaway\n2 hi hello\n1 hi hello\ndog cat\ndog hi\nhi hello\nihateyou goaway\nwelcome ihateyou\n",
"output": "YES\nYES... |
code_contests | verifiable_code | 78_C. Beaver Game | Solve the following coding problem using the programming language python:
Two beavers, Timur and Marsel, play the following game.
There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the leng... | ```python
from sys import stdin, stdout
def check(m, k):
for i in range(2, int(m ** 0.5) + 1):
if not m % i and (i >= k or m // i >= k):
return 1
else:
return 0
n, m, k = map(int, stdin.readline().split())
if m < 2 * k or (k != 1 and not check(m, k)):
stdout.wr... | vfc_58165 | {
"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": "1 15 4\n",
"output": "Timur\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 9 5\n",
"output": "Marsel\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 810_E. Find a car | Solve the following coding problem using the programming language python:
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking... | vfc_58169 | {
"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": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n",
"output": "1\n13\n93\n0\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 837_B. Flag of Berland | Solve the following coding problem using the programming language python:
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to ... | ```python
n, m = map(int, input().split())
f = [0 for _ in range(n)]
for i in range(n):
f[i] = input()
hor = True
if n % 3 != 0:
hor = False
else:
c = "RGB"
used = {"R":False, "G":False, "B":False}
used[f[0][0]] = True
cnt = 0
if [f[0][0] * m for i in range(n // 3)] == \
f[:n //... | vfc_58173 | {
"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": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 856_D. Masha and Cactus | Solve the following coding problem using the programming language python:
Masha is fond of cacti. When she was a little girl, she decided to plant a tree. Now Masha wants to make a nice cactus out of her tree.
Recall that tree is a connected undirected graph that has no cycles. Cactus is a connected undirected graph ... | vfc_58177 | {
"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": "7 3\n1 1 2 2 3 3\n4 5 1\n6 7 1\n2 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n1 2 3 4\n4 1 2057\n1 5 9085\n3 5 7001\n5 1 3602\n2 5 9758\n",
"output": "9... | |
code_contests | verifiable_code | 883_D. Packmen Strike Back | Solve the following coding problem using the programming language python:
Game field is represented by a line of n square cells. In some cells there are packmen, in some cells there are asterisks and the rest of the cells are empty. Packmen eat asterisks.
Before the game starts you can choose a movement direction, le... | vfc_58181 | {
"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\n*...P..*\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n*.P*P*\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 906_D. Power Tower | Solve the following coding problem using the programming language python:
Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is usually made of power-charged rocks. It is built with the help of rare magic by levitating the current top of tower and adding rocks at its bottom... | vfc_58185 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1000000000\n1 2 2 3 3 3\n8\n1 1\n1 6\n2 2\n2 3\n2 4\n4 4\n4 5\n4 6\n",
"output": " 1\n 1\n ... | |
code_contests | verifiable_code | 926_F. Mobile Communications | Solve the following coding problem using the programming language python:
A sum of p rubles is charged from Arkady's mobile phone account every day in the morning. Among the following m days, there are n days when Arkady will top up the account: in the day di he will deposit ti rubles on his mobile phone account. Arka... | ```python
n,p,m=map(int,input().split())
flag,t_neg,t_in,d,tot=0,0,0,1,0
for i in range (n):
ini_d=d
if flag==1:
tot+=(t-p)
if tot<0:
t_neg+=1
d,t=map(int,input().split())
if flag==0:
t_neg=(d-ini_d)
tot=t_neg*-p
flag=1
else:
tot+=(((d-1)-... | vfc_58189 | {
"difficulty": "12",
"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 6 7\n2 13\n4 20\n7 9\n",
"output": " 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 100\n10 70\n15 76\n21 12\n30 100\n6... |
code_contests | verifiable_code | 955_D. Scissors | Solve the following coding problem using the programming language python:
Jenya has recently acquired quite a useful tool — k-scissors for cutting strings. They are generally used for cutting out two non-intersecting substrings of length k from an arbitrary string s (its length should be at least 2·k in order to perfo... | vfc_58193 | {
"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": "7 4 3\nbaabaab\naaaa\n",
"output": "Yes\n1 5\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 981_F. Round Marriage | Solve the following coding problem using the programming language python:
It's marriage season in Ringland!
Ringland has a form of a circle's boundary of length L. There are n bridegrooms and n brides, and bridegrooms decided to marry brides.
Of course, each bridegroom should choose exactly one bride, and each bride... | ```python
def nis():
return map(int, raw_input().split())
def valid(dist):
left = 0
max_right = right = len(brides) - 1
for groom in grooms:
while groom - brides[left] > dist:
left += 1
while brides[right] - groom > dist:
right -= 1
left+=1
right+... | vfc_58197 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 100\n3 14 15 92 65 35 89 79 32 38\n2 71 82 81 82 84 5 90 45 23\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n0 1\n2 3\n",
"output": "1\n",
"type": "... |
code_contests | verifiable_code | 3rdsmallestandlargest-1 | Solve the following coding problem using the programming language python:
Alice decides to challenge Bob to a problem. She gives him a number.
Bob can rearrange the digits of this number by applying pair-wise swaps between any 2 digits in the number as many times as he wants. Now Alice asks him to write down all the... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from collections import Counter
cases = int(raw_input())
for case in xrange(0,cases):
st = raw_input()
lis = sorted(list(st))[ : :-1]
sc = Counter(st)
lenlis = len(l... | vfc_58201 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n123\n4\n1232\n\nSAMPLE",
"output": "213 231\nNot possible!\n1322 3122\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | big-p-and-punishment-5 | Solve the following coding problem using the programming language python:
Big P has become a Physical Education teacher at Hack International School.
Today, the students of class XII have been very undisciplined and he decides to punish them all.
He makes all of the N student (numbered 1 to N ) to stand in a line an... | ```python
def color_it(friendship_map,student_list,i,visitlist):
if len(friendship_map[i])>0 :
for j in friendship_map[i] :
if not visitlist[j]:
student_list[j-1]=True
visitlist[j]=True
color_it(friendship_map,student_list,j,visitlist)
def solve(f... | vfc_58205 | {
"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 2 1\n1 2\n2 3\n2\n\nSAMPLE",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6 2 1\n1 2\n2 3\n2\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | count-the-characters | Solve the following coding problem using the programming language python:
Harry is playing a game with is friend. He is given a notebook which has names of their friends written in various lowercase letter from 'a' to 'z'. His task is to find a 'special-letters'. A letter is a 'special-letters' if it occurs at least o... | ```python
from sys import stdin
ans = set()
t=int(stdin.readline())
a = stdin.readlines()
b = a[0].strip()
for i in b:
valid = 1
for j in a:
if i not in j:
valid = 0
break
if valid:
ans.add(i)
print len(ans)
``` | vfc_58209 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabcdde\nbaccd\neeabcg\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\nxhsbaqwbokcaqbkhrzddydwirmldcr\nkwkbkhlwmlpuomfaenahhnnpgqpkcxlspbomrweoqq\nrtdckeukf... |
code_contests | verifiable_code | finding-numbers | Solve the following coding problem using the programming language python:
Alice has just learnt multiplying two integers. He wants to multiply two integers X and Y to form a number Z. To make the problem interesting he will choose X in the range [1,M] and Y in the range [1,N]. Help him to find the number of ways in wh... | ```python
tc = int(raw_input())
for test in xrange(tc):
res =0
z,m,n = [ int(x) for x in raw_input().split() ]
for elem1 in xrange(1,int(z**0.5)+1):
#print "elem 1 --->",elem1
if z%elem1 == 0:
if elem1 == z/elem1 and ((1<= elem1 <= m and 1<= z/elem1 <= n) or ( 1<= elem1 <= n and 1<= z/elem1 <= m)):
#print... | vfc_58213 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 7 9\n5 2 10\n5 5 6\n2 8 1\n\nSAMPLE",
"output": "3\n1\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 7 9\n10 2 10\n5 5 6\n2 8 1\n\nSAMPLE",
"output": "3\n2\n2\n1\n",... |
code_contests | verifiable_code | interval-count-12 | Solve the following coding problem using the programming language python:
This problem of Oz is very straight forward. You are given N distinct prime integers i.e p1, p2,..., pN and an interval [L,R]. Calculate number of integers in this interval that are divisible by at least one of the given primes.
Input :
First ... | ```python
T=int(raw_input())
for i in xrange(T):
N,L,R=map(int, raw_input().split())
arrP=map(int, raw_input().split())
bits=[[] for _ in xrange(N+1)]
for i in xrange(1,pow(2,N)):
bits[bin(i).count("1")].append(i)
# calc for L-1, R inclusive from 1:
numL=0
numR=0
muls=[1]
sign=1
for i in xrange(... | vfc_58217 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1 10\n3\n2 1 10\n2 3\n\nSAMPLE",
"output": "3\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n1 1 1000000000000000000\n3\n1 1000000000000000000 1000000000000000000\n3\n10 1 10000... |
code_contests | verifiable_code | maximum-subset | Solve the following coding problem using the programming language python:
You will be given a set of distinct numbers. Your task is to find that even length subset which will give you a maximum value of P % (10^9 + 7). This value of P for a subset of length N is defined as below :
P = (product of N/2 maximu... | ```python
t = input()
while t>0:
t-=1
n = input()
a = map(int, raw_input().split())
l = []
mval = 0
subs = pow(2, n)
for i in range(subs):
ls = []
for j in range(n):
if (i & (1 << j) > 0):
ls.append(a[j])
if len(ls) > 0 and len(ls)%2 == 0:
ls.sort()
mp = 1
minp = 1
for k in range(0,len(l... | vfc_58221 | {
"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\n2 4\n3\n2 4 8\n\nSAMPLE",
"output": "2\n4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n2 4\n3\n4 4 8\n\nSAMPLE",
"output": "2\n2\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | organize-contest | Solve the following coding problem using the programming language python:
Campus Ambassador has organized a Coding Contest in his college. Contest has multiple rounds, in each round a participant may gain or lose few points. At the end, there is only one participant with the maximum points. In the course of the contes... | ```python
n=int(raw_input())
a={}
for i in range(n):
x,y=raw_input().split()
y=int(y)
if not a.has_key(x):
a[x]=[y,i]
else:
a[x][0]+=y
a[x][1]=i
b=a.items()
b.sort(key=lambda x:(-x[1][0],x[1][1]))
print b[0][0]
``` | vfc_58225 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nmini 3\nrini 5\nmini 2\n\nSAMPLE",
"output": "rini\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nmahi 3\nmahi 2\nvicky 5\nankit 5\npooja 4\nramesh 4\nankita 2\nmanisha 3\nmanisha ... |
code_contests | verifiable_code | rani-and-ladders-2 | Solve the following coding problem using the programming language python:
Do you remember the game of Snakes and Ladders ? We have removed all the snakes from the board. However to compensate for the loss of trouble, we have enlarged the board from a maximum limit (Target Square) of 100 to a maximum limit (Target Squa... | ```python
nooftest=input()
for i in range(nooftest):
size,l=map(int,raw_input().split())
dist=[]
ladderdestination=[]
ladderend=[]
for j in range(size+13):
ladderdestination.append(0)
dist.append(-1)
ladderend.append(-1)
for j in range(l):
temp=map(int,raw_input()... | vfc_58229 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n11025 64\n297 345\n3266 10057\n5366 9583\n1815 5123\n1255 1449\n315 1580\n160 513\n2557 3726\n452 4632\n560 3339\n6643 9342\n2591 5273\n1473 5777\n826 10203\n1572 3833\n101 323\n2311 5011\n2124 5492\n6325 6700\n7925 9037\n5995 6... |
code_contests | verifiable_code | smallest-positive-integer | Solve the following coding problem using the programming language python:
Given a number X between 0 to 1000000006 find smallest positive integer Y such that the products of digits of Y modulo 1000000007 is X.
Input Format
A single integer - X
Output Format
A single integer - Y
Input Constraint
0 ≤ X ≤ 100000000... | ```python
import sys
def get_min_length_single_digit_factors(x):
original_x = x
factor_counts = [0]*10
for i in xrange(8):
if x < 2:
break
factor = 9-i
while x % factor == 0:
x = x/factor
factor_counts[factor] += 1
if not x==1:
return get_min_length_single_digit_factors(original_x+1000000007)
re... | vfc_58233 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "16",
"output": "28",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0",
"output": "10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "220703118",
... |
code_contests | verifiable_code | think-a-thon-series-1 | Solve the following coding problem using the programming language python:
Now that you have won Code Monk and been hired by HackerEarth as a software engineer, you have been assigned to work on their wildly popular programming contest website.
HackerEarth is expecting a lot of participants (P) in Code Monk next year,... | ```python
t = int(raw_input())
for cs in xrange(1,t+1):
l,p,c = [int(i) for i in raw_input().split()]
a=0
temp = l
while(temp<p):
temp*=c
a+=1
ans =0
while((1<<ans)<a):
ans+=1
print "Case #"+str(cs)+": "+str(ans)
``` | vfc_58237 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n19 57 3\n24 97 2\n\nSAMPLE",
"output": "Case #1: 0\nCase #2: 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n50 700 2\n19 57 3\n1 1000 2\n24 97 2",
"output": "Case #1: 2\nCase ... |
code_contests | verifiable_code | p00107 Carry a Cheese | Solve the following coding problem using the programming language python:
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's h... | ```python
while True:
d, w, h = sorted(map(int, input().split()))
if d == w == h == 0:
break
dw = (d**2 + w**2)
n = int(input())
for i in range(n):
y = int(input())
if (2*y)**2 > dw:
print("OK")
else:
print("NA")
``` | vfc_58285 | {
"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": "10 6 8\n5\n4\n8\n6\n2\n5\n0 0 0",
"output": "NA\nOK\nOK\nNA\nNA",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 6 8\n5\n4\n1\n6\n2\n5\n0 0 0",
"output": "NA\nNA\nOK\nNA\nNA\n",
... |
code_contests | verifiable_code | p00241 Quaternion Multiplication | Solve the following coding problem using the programming language python:
An extension of a complex number is called a quaternion. It is a convenient number that can be used to control the arm of a robot because it is convenient for expressing the rotation of an object. Quaternions are $ using four real numbers $ x $,... | ```python
while True :
n = int(input())
if n == 0 :
break
for i in range(n) :
x1, y1, z1, w1, x2, y2, z2, w2 = map(int, input().split())
print((x1*x2 - y1*y2 - z1*z2 - w1*w2), (x1*y2 + x2*y1 + z1*w2 - z2*w1), (x1*z2 - y1*w2 + x2*z1 + y2*w1), (x1*w2 + y1*z2 - y2*z1 + x2*w1))
``... | vfc_58289 | {
"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\n1 2 3 4 7 6 7 8\n5 6 7 8 3 2 3 4\n0",
"output": "-58 16 36 32\n-50 32 28 48",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00617 Simple GUI Application | Solve the following coding problem using the programming language python:
Advanced Creative Mobile (ACM) has decided to develop a GUI application to be installed in a new portable computer.
As shown in the figure below, the GUI has a nested structure in which it has one main panel, several panels are arranged on it, ... | ```python
class Panel:
def __init__(self, name, points, children):
self.name = name
self.x1 = points[0]
self.x2 = points[2]
self.y1 = points[1]
self.y2 = points[3]
self.children = children
self.child_cnt = len(children)
def search(self, x, y):
if ... | vfc_58297 | {
"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": "5\n<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140</primary></main>\n10 10\n15 15\n40 60\n2 3\n130 80\n0",
"output": "main 2\nmain 2\nmenu 0\nOUT OF MAIN PANEL 1\nprimary 0",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | p00761 Recurring Decimals | Solve the following coding problem using the programming language python:
A decimal representation of an integer can be transformed to another integer by rearranging the order of digits. Let us make a sequence using this fact.
A non-negative integer a0 and the number of digits L are given first. Applying the followin... | ```python
while True:
list_a = []
a, L = input().split(" ")
if a=='0' and L=='0': break
L = int(L)
list_a.append(int(a))
while True:
if len(a) < L: a += '0'*(L-len(a))
an = int(''.join(sorted(a, reverse=True))) - int(''.join(sorted(a)))
if an in list_a:
idx =... | vfc_58301 | {
"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": "2012 4\n83268 6\n1112 4\n0 1\n99 2\n0 0",
"output": "3 6174 1\n1 862632 7\n5 6174 1\n0 0 1\n1 0 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2012 4\n83268 3\n1112 4\n0 1\n99 2\n0 0",
... |
code_contests | verifiable_code | p01026 Witch Craft Moves | Solve the following coding problem using the programming language python:
Problem
Aizu Magic School is a school where people who can use magic gather. Aizu Magic School has classrooms numbered from 1 to N and a corridor connecting the classrooms. You can go through the classrooms and corridors as many times as you li... | vfc_58309 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n2\n3\n4\n5\n6\n7\n1 2\n1 3\n3 4\n3 5\n5 6\n5 7\n10\n0 1 7\n0 2 7\n1 1 15\n0 1 7\n0 2 7\n0 1 1\n1 1 -15\n0 1 7\n0 2 7\n0 1 1",
"output": "16\n18\n31\n33\n16\n16\n18\n1",
"type": "stdin_stdout"
},
{
"f... | |
code_contests | verifiable_code | p01157 Online Quiz System | Solve the following coding problem using the programming language python:
ICPC (Internet Contents Providing Company) is working on a killer game named Quiz Millionaire Attack. It is a quiz system played over the Internet. You are joining ICPC as an engineer, and you are responsible for designing a protocol between cli... | vfc_58313 | {
"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": "3 2\n1 2 10\n3\n0 3420 o\n1 4589 o\n2 4638 x\n3\n1 6577 SUZUMIYA\n2 7644 SUZUMIYA\n0 19979 YASUZUMI\n4 2\n150 150 150 150\n4\n0 1344 HOGEHOGE\n1 1466 HOGEHOGE\n2 1789 HOGEHOGE\n3 19100 GEHO\n2\n2 1200 SETTEN\n3 700 SETTEN\n0 0",
... | |
code_contests | verifiable_code | p01296 Futon | Solve the following coding problem using the programming language python:
The sales department of Japanese Ancient Giant Corp. is visiting a hot spring resort for their recreational trip. For deepening their friendships, they are staying in one large room of a Japanese-style hotel called a ryokan.
In the ryokan, peop... | ```python
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline(... | vfc_58317 | {
"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\n0 0 x\n2 0 x\n0 1 x\n2 1 x\n4\n1 0 x\n0 1 x\n2 1 x\n1 2 x\n4\n0 0 x\n2 0 y\n0 1 y\n1 2 x\n0",
"output": "Yes\nNo\nYes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 x\n2 0 x\n0 1 ... |
code_contests | verifiable_code | p01465 Testing Circuits | Solve the following coding problem using the programming language python:
A Boolean expression is given. In the expression, each variable appears exactly once. Calculate the number of variable assignments that make the expression evaluate to true.
Input
A data set consists of only one line. The Boolean expression ... | vfc_58321 | {
"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": "(x1&x2)",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "(x1&x2)|(x3&x4)|(~(x5|x6)&(x7&x8))",
"output": "121",
"type": "stdin_stdout"
},
{
"fn_name": ... | |
code_contests | verifiable_code | p01625 Princess Tetra's Puzzle | Solve the following coding problem using the programming language python:
Princess Tetra of the Kingdom of Palace is known as an unrivaled puzzle lover, and has recently been enthusiastic about her own "Tetra puzzle". This is a puzzle that uses a board with equilateral triangle squares and a regular tetrapod block con... | vfc_58325 | {
"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": "3\n2 3 2 2 2 1\n2 0 1 -1 2 -1\n-2 -1 -1 -1 -2 0\n6\n-1 0 1 0 0 -1\n-2 -1 -3 -2 -4 -2\n2 -1 2 0 1 -1\n4 -2 3 -2 3 -1\n1 1 0 1 -1 1\n-3 -1 -1 -1 -2 0\n5\n-1 2 0 2 1 2\n-3 1 -2 1 -2 2\n-2 0 -2 -1 -3 0\n1 -1 0 -1 -1 -1\n1 0 2 0 2 -1\n4... | |
code_contests | verifiable_code | p01777 Disordered Data Detection | Solve the following coding problem using the programming language python:
F: Disordered Data Detection / Anomaly detection
story
Akane Miyamori is an engineer working for Musashino Software. Today, I'm worried about the bug report I received from the customer. "Weird story, the behavior of the software you made last... | vfc_58329 | {
"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": "7\n4 1 10 5 7 7 3\n5\n2 5 0\n3 6 1\n3 6 2\n1 7 2\n1 7 5",
"output": "1\n1\n0\n3\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n4 1 10 5 7 7 3\n5\n1 5 0\n3 6 1\n3 6 2\n1 7 2\n1 7 5",
... | |
code_contests | verifiable_code | p02050 K is Key of Takakkey | Solve the following coding problem using the programming language python:
K is a polygonal Kay
"Do I have to be No. 1? Is it not No. K?"
This is Mr. Kay's inscription. Recently, Mr. Kay seems to be exclusively interested in polygons, seeing N points placed on a vast two-dimensional plane spreading in front of him, a... | vfc_58337 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n1 1\n1 4\n2 2\n3 1\n3 5\n3 1\n0 2\n1 0\n-1 0\n3 2\n0 2\n1 0\n-1 0\n9 10\n8 1\n9 19\n2 10\n1 1\n4 17\n7 13\n3 4\n6 13\n9 21\n0 0",
"output": "11.812559200041266\n6.472135954999580\n-1\n52.202878812480016",
"type": "... | |
code_contests | verifiable_code | p02192 K Average Ranges | Solve the following coding problem using the programming language python:
K Average Ranges
Given the sequence a_1, a_2, .., a_N.
How many intervals in this sequence have an average value of K or more and a length of 1 or more?
input
N K
a_1 a_2 ... a_N
output
Output the answer.
Constraint
* 1 \ leq N \ leq 1... | vfc_58341 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 1073741824,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n8 6 9 1 2 1",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n8 6 9 1 2 1",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | p02346 Range Sum Query (RSQ) | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:
* add(i, x): add x to ai.
* getSum(s, t): print the sum of as, as+1,...,at.
Note that the initial values of ai (i = 1, 2, . . . , n) are 0.
... | ```python
from array import array
import bisect
import collections
import heapq
import itertools
import operator
import sys
class BIT:
def __init__(self, n):
self.n = n
self.arr = array("l", [0] * (n + 1))
def __str__(self):
return str(self.arr.tolist())
def add(self, i, x):
... | vfc_58345 | {
"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 5\n0 1 1\n0 2 2\n0 3 3\n1 1 2\n1 2 2",
"output": "3\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chcube | Solve the following coding problem using the programming language python:
One day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange.
Now he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same co... | ```python
T = input()
for _ in xrange(T):
ans = "NO"
f = raw_input().split()
f1 = f[0:2]
f2 = f[2:4]
f3 = f[4:]
for side in f1:
if side in f2 and side in f3:
ans = "YES"
break
print ans
``` | vfc_58349 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nblue yellow green orange black green\ngreen yellow green orange black green",
"output": "NO\nYES\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | devclass | Solve the following coding problem using the programming language python:
Devu is a class teacher of a class of n students. One day, in the morning prayer of the school, all the students of his class were standing in a line. You are given information of their arrangement by a string s. The string s consists of only le... | ```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_58353 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n0\nBB\n0\nBG\n0\nBBGG\n1\nBGG\n1\nBGGB\n1\nBBBGG\n2\nBBGG\n2\nBGB",
"output": "-1\n0\n1\n1\n1\n3\n1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1\nBB\n0\nBG\n0\nBBGG\n1\nBGG\n... |
code_contests | verifiable_code | iitk2p06 | Solve the following coding problem using the programming language python:
You are given e even and o odd numbers. In a single operation, you change an even to odd number or vice versa. Find out min number of operations needed to
do such that ratio of even to odd numbers becomes 2 : 3. If it is impossible to do so, out... | ```python
#Anwesh Mohanty
t=input()
while t>0:
a,b=map(int,raw_input().split())
if((a+b)%5==0):
r=int(2*(a+b)/5)
print abs(r-a)
else:
print -1
t-=1
``` | vfc_58357 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3\n3 2\n3 3",
"output": "0\n1\n-1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | saarc05 | Solve the following coding problem using the programming language python:
Problem description.
Most campuses have a lot of named buildings, and as the names tend to be rather long, the class schedules
have abbreviations. At IITD, it seems that the abbreviations have become used so widely that most people
don’t even r... | ```python
import copy
cases = int(raw_input())
i = 1
while cases:
cases -= 1
times = int(raw_input())
lis = []
while times:
times -= 1
lis.append(raw_input())
abb = raw_input().lower()
print "Data Set "+ str(i) + ":"
i += 1
j = 0
l1 = len(abb)
for s in lis:
... | vfc_58365 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2\nSaLvatori\nScience LibrarieS\nSSL\n3\nstudENt aeRoSpace laBoratory\nsalVAtori\nangeles\nSAL",
"output": "Data Set 1:\nData Set 2:\nstudENt aeRoSpace laBoratory\nsalVAtori",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1023_E. Down or Right | Solve the following coding problem using the programming language python:
This is an interactive problem.
Bob lives in a square grid of size n × n, with rows numbered 1 through n from top to bottom, and columns numbered 1 through n from left to right. Every cell is either allowed or blocked, but you don't know the ex... | ```python
from sys import stdout
n=int(input())
x=1
y=1
s='! '
s2=''
for i in range (n-1):
print('? '+str(x+1)+' '+str(y)+' '+str(n)+' '+str(n))
stdout.flush()
b=input()
if b=='YES':
s=s+'D'
x+=1
else:
s=s+'R'
y+=1
x1=x
y1=y
x=n
y=n
for i in range (n-1):
if y!=y1:... | vfc_58373 | {
"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\n \nYES\n \nNO\n \nYES\n \nYES\n \n",
"output": "? 2 1 4 4\n? 2 2 4 4\n? 3 2 4 4\n? 1 1 4 3\n? 1 1 3 3\n? 1 1 2 3\n! RDRRDD\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1044_F. DFS | Solve the following coding problem using the programming language python:
Let T be a tree on n vertices. Consider a graph G_0, initially equal to T. You are given a sequence of q updates, where the i-th update is given as a pair of two distinct integers u_i and v_i.
For every i from 1 to q, we define the graph G_i a... | vfc_58377 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n1 2\n2 3\n1 4\n4 5\n1 6\n2 5\n3 4\n5 2\n6 4\n3 4\n6 5\n",
"output": "3\n2\n3\n2\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2\n1 3\n2 3\n3 2\n",
"output": "2\n3... | |
code_contests | verifiable_code | 1067_E. Random Forest Rank | Solve the following coding problem using the programming language python:
Let's define rank of undirected graph as rank of its adjacency matrix in R^{n × n}.
Given a tree. Each edge of this tree will be deleted with probability 1/2, all these deletions are independent. Let E be the expected rank of resulting forest. ... | vfc_58381 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n2 3\n3 4\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2\n1 3\n1 4\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": n... | |
code_contests | verifiable_code | 108_C. Dorm Water Supply | Solve the following coding problem using the programming language python:
The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which cha... | ```python
n, m = map(int, input().split())
t, p = [], [[0, 0, 0] for i in range(n + 1)]
for i in range(m):
a, b, d = map(int, input().split())
p[b][1], p[a][0], p[a][2] = a, b, d
for a in range(1, n + 1):
if p[a][1] == 0:
b, c, d = a, p[a][0], p[a][2]
if not c: continue
whil... | vfc_58385 | {
"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": "3 3\n1 2 20\n2 3 10\n3 1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n1 2 60\n3 4 50\n",
"output": "2\n1 2 60\n3 4 50\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1109_B. Sasha and One More Name | Solve the following coding problem using the programming language python:
Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn t... | ```python
s = input()
n = len(s)
def check(name):
return name == name[::-1] and name != s
for i in range(1, n):
new_name = s[i:] + s[:i]
if check(new_name):
print(1)
exit()
for i in range(1, n // 2 + 1):
new_name = s[-i:] + s[i:-i] + s[:i]
if check(new_name):
print(2)
... | vfc_58389 | {
"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": "otto\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "qqqq\n",
"output": "Impossible",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 1138_E. 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_58393 | {
"difficulty": "11",
"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"
}
]
} | |
code_contests | verifiable_code | 1156_G. Optimizer | Solve the following coding problem using the programming language python:
Let's analyze a program written on some strange programming language. The variables in this language have names consisting of 1 to 4 characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constr... | ```python
from random import seed, randint
import sys
sys.setrecursionlimit(10000)
opr = ['#', '^', '&', '$']
namespace = { "res" : (False, "res") }
rules = dict()
lookup = dict()
cnt = -1
def get_tag(var):
if var in namespace:
return namespace[var][1]
else:
return var
N = int(input())
for _ ... | vfc_58397 | {
"difficulty": "13",
"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\nc=aa#bb\nd12=c\nres=c^d12\ntmp=aa$c\n",
"output": "2\naaaa=aa#bb\nres=aaaa^aaaa\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1179_A. Valeriy and Deque | Solve the following coding problem using the programming language python:
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with n elements. The i-th element is a_i (i = 1, 2, …, n). He gradually takes the first two leftmost elements from the deque (... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write i... | vfc_58401 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n1\n2\n10\n",
"output": "1 2\n2 3\n5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n0 0\n",
"output": "\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 1214_D. Treasure Island | Solve the following coding problem using the programming language python:
All of us love treasures, right? That's why young Vasya is heading for a Treasure Island.
Treasure Island may be represented as a rectangular table n × m which is surrounded by the ocean. Let us number rows of the field with consecutive integer... | ```python
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" n... | vfc_58409 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n....\n#.#.\n....\n.#..\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n..\n..\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name... |
code_contests | verifiable_code | 1237_F. Balanced Domino Placements | Solve the following coding problem using the programming language python:
Consider a square grid with h rows and w columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.
Let's call a placement of dominoes on the grid pe... | vfc_58413 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 2\n1 2 2 2\n4 3 4 4\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1255_E2. Send Boxes to Alice (Hard Version) | Solve the following coding problem using the programming language python:
This is the harder version of the problem. In this version, 1 ≤ n ≤ 10^6 and 0 ≤ a_i ≤ 10^6. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems
Christmas is coming, and our protago... | ```python
import sys
# inf = open('input.txt', 'r')
# input = inf.readline
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
def primeDivisors(num):
sqrtNum = int(num ** 0.5) + 1
primes = []
if not num & 1:
primes.append(2)
while not num & 1:
num ... | vfc_58417 | {
"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\n1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 8 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 1279_E. New Year Permutations | Solve the following coding problem using the programming language python:
Yeah, we failed to make up a New Year legend for this problem.
A permutation of length n is an array of n integers such that every integer from 1 to n appears in it exactly once.
An element y of permutation p is reachable from element x if x ... | ```python
# 1279E - New Year Permutations
# Idea:
# dp(i) --> # of good permutations of [i,n]
# cycles(m) --> # of blocks of len m ( == (m-2)! as first element is fixed)
# It is easy to test for impossibility ie. k > dp(1)
# Another subproblem: how to compute jth smallest cycle
# getGoodPerm(n,k) uses both getCycle(b... | vfc_58421 | {
"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\n3 3\n5 15\n4 13\n6 8\n4 2\n",
"output": "2 1 3 \n3 1 2 5 4 \n-1\n1 2 6 3 4 5 \n1 2 4 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 3\n5 25\n4 13\n6 8\n4 2\n",
"output": ... |
code_contests | verifiable_code | 129_C. Statues | Solve the following coding problem using the programming language python:
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has sever... | ```python
from sys import stdin
from collections import *
from copy import deepcopy
def valid(i, j):
n, m = [8] * 2
return i > -1 and i < n and j > -1 and j < m
def str_inp(n):
return list(reversed(list((list(stdin.readline()[:-1]) for x in range(n)))))
def check(x, y, step):
if step + 1 < 8 and a... | vfc_58425 | {
"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": ".......A\n........\n........\n........\n........\n........\n........\nM.......\n",
"output": "WIN",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ".......A\n........\n........\n........\n....... |
code_contests | verifiable_code | 1322_F. Assigning Fares | Solve the following coding problem using the programming language python:
Mayor of city M. decided to launch several new metro lines during 2020. Since the city has a very limited budget, it was decided not to dig new tunnels but to use the existing underground network.
The tunnel system of the city M. consists of n ... | vfc_58429 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7 5\n3 4\n4 2\n2 5\n5 1\n2 6\n4 7\n1 3\n6 7\n3 7\n2 1\n3 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n1 2\n2 3\n1 3\n",
"output": "3\n1 2 3 ",
"type... | |
code_contests | verifiable_code | 1341_E. 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 sys
input = sys.stdin.readline
from collections import deque
from typing import List
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
... | vfc_58433 | {
"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": "15 5\n0 3 7 14 15\n11 11\n",
"output": "45",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13 4\n0 3 7 13\n9 9\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 1426_D. Non-zero Segments | Solve the following coding problem using the programming language python:
Kolya got an integer array a_1, a_2, ..., a_n. The array can contain both positive and negative integers, but Kolya doesn't like 0, so the array doesn't contain any zeros.
Kolya doesn't like that the sum of some subsegments of his array can be ... | ```python
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode o... | vfc_58449 | {
"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\n4 -2 3 -9 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n-1 1 -1 1 -1 1 1 -1 -1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 1473_C. No More Inversions | Solve the following coding problem using the programming language python:
You have a sequence a with n elements 1, 2, 3, ..., k - 1, k, k - 1, k - 2, ..., k - (n - k) (k ≤ n < 2k).
Let's call as inversion in a a pair of indices i < j such that a[i] > a[j].
Suppose, you have some permutation p of size k and you build... | ```python
from collections import Counter
import string
import math
import sys
# sys.setrecursionlimit(10**6)
from fractions import Fraction
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
... | vfc_58457 | {
"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\n1 1\n2 2\n3 2\n4 3\n",
"output": "\n1 \n1 2 \n2 1 \n1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1\n3 2\n3 2\n4 3\n",
"output": "1\n2 1\n2 1\n1 3 2\n",
"type"... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.