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 | 32_E. Hide-and-Seek | Solve the following coding problem using the programming language python:
Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (xv, yv... | ```python
xv,yv=list(map(int,input().split()))
xp,yp=list(map(int,input().split()))
xw1,yw1,xw2,yw2=list(map(int,input().split()))
xm1,ym1,xm2,ym2=list(map(int,input().split()))
def a(x1,y1,x2,y2,x3,y3,x4,y4):
if x1==x2:
if x3==x4:
return False
else:
k2=(y3-y4)/(x3-x4)
... | vfc_41849 | {
"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": "0 0\n10 0\n100 100 101 101\n1 0 3 0\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1 3\n1 3\n0 2 0 4\n0 0 0 1\n",
"output": "NO",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 351_C. Jeff and Brackets | Solve the following coding problem using the programming language python:
Jeff loves regular bracket sequences.
Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows... | vfc_41853 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 6\n1 2\n2 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 10000000\n2\n3\n",
"output": "25000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 375_D. Tree and Queries | Solve the following coding problem using the programming language python:
You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. We will assume that the tree vertices are numbered by integers from 1 to n. Then we represent the color of vertex v as cv. The tree root is a vertex with nu... | vfc_41857 | {
"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": "8 5\n1 2 2 3 3 2 3 3\n1 2\n1 5\n2 3\n2 4\n5 6\n5 7\n5 8\n1 2\n1 3\n1 4\n2 3\n5 3\n",
"output": "2\n2\n1\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n1 2 3 4\n1 2\n2 3\n3 4\n1... | |
code_contests | verifiable_code | 398_A. Cards | Solve the following coding problem using the programming language python:
User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.
1. At first, the score is 0.
2. For eac... | ```python
a,b=[int(i) for i in input().split()]
if(a==0):
print(-b**2)
print('x'*b)
elif(b==0):
print(a**2)
print('o'*a)
elif(b==1):
print(a**2-1)
print('x'+'o'*a)
else:
ans=-float('inf')
gr_no=None
for i in range(2,min(a+2,b+1)):
v1=(a+2-i)**2 + i-2
quo=b//i
... | vfc_41861 | {
"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 3\n",
"output": "-1\nxxoox",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 0\n",
"output": "16\noooo\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 420_B. Online Meeting | Solve the following coding problem using the programming language python:
Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company condu... | ```python
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
'''
Created on 13/09/2018
@author: ernesto
'''
n, m = [int(x) for x in input().strip().split(" ")]
posibles_jefes = set(range(1, n + 1))
anteriores = set()
posteriores = set()
continuos = [True] * (n + 1)
mencionados = set()
posibles_jefes_men... | vfc_41865 | {
"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\n+ 1\n- 1\n- 3\n+ 3\n+ 4\n- 4\n",
"output": "3\n2 3 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n+ 1\n- 1\n+ 2\n- 2\n",
"output": "0\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 446_E. DZY Loves Bridges | Solve the following coding problem using the programming language python:
DZY owns 2m islands near his home, numbered from 1 to 2m. He loves building bridges to connect the islands. Every bridge he builds takes one day's time to walk across.
DZY has a strange rule of building the bridges. For every pair of islands u,... | vfc_41869 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1 4\n1 1 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 6\n389094 705719 547193 653800 947499 17024\n",
"output": "556970\n",
"type": "stdin_stdout"... | |
code_contests | verifiable_code | 469_A. I Wanna Be the Guy | Solve the following coding problem using the programming language python:
There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only p levels of the game. And Little Y can pass only q... | ```python
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
d=[]
for i in range(1,p[0]+1):
d+=[p[i]]
for i in range(1,q[0]+1):
if(q[i] not in d):
d+=[q[i]]
if(len(d)==n):
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | vfc_41873 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1 2 3\n2 2 3\n",
"output": "Oh, my keyboard!\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 1 2 3\n2 2 4\n",
"output": "I become the guy.\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 515_A. Drazil and Date | Solve the following coding problem using the programming language python:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0, 0) and Varda's home is located in point (a, b). In each step, he can move in a unit distance in horizontal or vertic... | ```python
a, b, s = map(int,input().split())
if (s - abs(a) - abs(b)) % 2 == 1 or s < abs(a) + abs(b):
print('NO')
else:
print('YES')
``` | vfc_41881 | {
"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": "0 5 1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 15 25\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 542_B. Duck Hunt | Solve the following coding problem using the programming language python:
A duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0, 0). As he doesn't like walking for his prey, he prefers to shoot only vertically up (because in this case, the ducks fall straigh... | vfc_41885 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n-3 0\n1 3\n-1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n-1 1\n2 4\n5 9\n6 8\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 569_C. Primes or Palindromes? | Solve the following coding problem using the programming language python:
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. He... | ```python
import sys
p,q = map(int,sys.stdin.readline().split())
def prime(n):
#print(int(n**0.5))
for div in range(2,int(n**0.5)+1):
if n%div==0:
return False
return True
def palindrom(n):
n = str(n)
for pos in range((len(n)+1)//2):
if n[pos]!=n[-1-pos]:
... | vfc_41889 | {
"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": "6 4\n",
"output": "172\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 42... |
code_contests | verifiable_code | 590_A. Median Smoothing | Solve the following coding problem using the programming language python:
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya... | ```python
import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
arr = list(map(int, lines[1].strip().split(" ")))
arr.append(arr[-1])
res = []
maxChange = 0
left = 0
for i in range(1, n+1):
if arr[i] == arr[i-1]:
L = i - left
res += [arr[left]]*(L//2) + [arr[i-1]]*(L-L//2)
maxC... | vfc_41893 | {
"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": "5\n0 1 0 1 0\n",
"output": "2\n0 0 0 0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 0 1 1\n",
"output": "0\n0 0 1 1\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 611_H. New Year and Forgotten Tree | Solve the following coding problem using the programming language python:
A tree is a connected undirected graph with n - 1 edges, where n denotes the number of vertices. Vertices are numbered 1 through n.
Limak is a little polar bear. His bear family prepares a New Year tree every year. One year ago their tree was m... | vfc_41897 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n?? ??\n? ?\n? ?\n? ??\n?? ?\n?? ??\n? ??\n? ?\n? ?\n?? ??\n? ?\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12\n? ?\n? ?\n? ?\n? ??\n?? ?\n?? ??\n? ??\n? ?\n? ?\n? ?... | |
code_contests | verifiable_code | 631_E. Product Sum | Solve the following coding problem using the programming language python:
Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special.
You are given an array a of length n.... | vfc_41901 | {
"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\n1 1 2 7 1\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 2 5\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 660_C. Hard Process | Solve the following coding problem using the programming language python:
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones ... | ```python
a,b=map(int,input().split())
z=list(map(int,input().split()))
ans=[]
for i in range(len(z)):
if(z[i]==0):
ans.append(i)
freq=[]
count=1
inde=0
if(len(ans)==0):
print(len(z))
print(*z)
exit()
pair=[[0,0] for i in range(len(ans))]
if(z[0]==0):
inde=1
for i in range(1,len(z)):
... | vfc_41905 | {
"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": "7 1\n1 0 0 1 1 0 1\n",
"output": "4\n1 0 0 1 1 1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 2\n1 0 0 1 0 1 0 1 0 1\n",
"output": "5\n1 0 0 1 1 1 1 1 0 1 ",
"type": "st... |
code_contests | verifiable_code | 683_G. The Fraction | Solve the following coding problem using the programming language python:
Periodic decimal fraction is usually written as: [entire_part.non-periodic_part (period)]. Any simple fraction can be represented as a periodic decimal fraction and vice versa. For example, the decimal fraction 0.2(45) corresponds to a fraction ... | vfc_41909 | {
"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": "0.2(45)\n",
"output": "27/110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0.75(0)\n",
"output": "3/4\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 707_A. Brain's Photos | Solve the following coding problem using the programming language python:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on th... | ```python
n, m = [int(s) for s in input().split()]
for i in range(n):
a = [str(s) for s in input().split()]
if 'C' in a or 'Y' in a or 'M' in a:
m = -1
break
else:
pass
print('#Color') if m == -1 else print('#Black&White')
``` | vfc_41913 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\nC M\nY Y\n",
"output": "#Color\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\nW\n",
"output": "#Black&White\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 72_B. INI-file | Solve the following coding problem using the programming language python:
The INI file format is a de facto standard for configuration files. INI files are simple text files with a basic structure. They are commonly associated with Microsoft Windows, but are also used on other platforms.
Each line in INI-file stands ... | vfc_41917 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "11\na= 1\nb=a\na = 2\n ; comment\n[z]\n1=2\n[y]\n2=3\n[z]\n2=1\n[w]\n",
"output": "a=2\nb=a\n[w]\n[y]\n2=3\n[z]\n1=2\n2=1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 74_D. Hanger | Solve the following coding problem using the programming language python:
In one very large and very respectable company there is a cloakroom with a coat hanger. It is represented by n hooks, positioned in a row. The hooks are numbered with positive integers from 1 to n from the left to the right.
The company workers... | ```python
import sys
from heapq import *
n,q = map(int,raw_input().split())
rl = sys.stdin.readline
z,l,r,t = {},{},{},{}
h = []
qq = 2*q+2
a = [True]*qq
b,e = [0]*qq,[0]*qq
ac = 0
def add(bb,ee):
global b,e,h,ac
if bb>=ee:
l[ee]=r[bb-1]=0
return
b[ac]=bb
e[ac]=ee
r[bb-1]=l[ee]=ac
heappush... | vfc_41921 | {
"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": "9 11\n1\n2\n0 5 8\n1\n1\n3\n0 3 8\n9\n0 6 9\n6\n0 1 9\n",
"output": "2\n3\n2\n5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 773_C. Prairie Partition | Solve the following coding problem using the programming language python:
It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x.
For example, the prairie partitio... | ```python
from collections import Counter
from math import log2
powers = [2 ** p for p in range(64)]
def can():
near = Counter()
for num in set(nums):
p = int(log2(num))
near[p] += nums[num]
seq_cp = seqs - Counter()
for num in set(near):
cnt = near[num]
while cnt != 0... | vfc_41925 | {
"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": "6\n1 1 1 2 2 2\n",
"output": "2 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 1 2 2 3 4 5 8\n",
"output": "2 \n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 798_B. Mike and strings | Solve the following coding problem using the programming language python:
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move h... | ```python
def fn(s1,s2):
l1=list(s1)
l2=list(s2)
ans=0
for i in range(len(l1)):
if l1==l2:
break
l1=l1[1:]+[l1[0]]
ans+=1
if l1==l2:
return ans
else:
print(-1)
exit()
n1=int(input())
l=[]
if n1==1:
print(0)
exit()
for i in range... | vfc_41929 | {
"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": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nkc\nkc\nkc\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 818_D. Multicolored Cars | Solve the following coding problem using the programming language python:
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses s... | ```python
n,A=map(int,input().split())
c=[]
c=list(map(int,input().split()))
if(A not in c):
print(c[0])
elif(c[0] == A):
print(-1)
else:
ind = c.index(A)
d={}
for i in range(ind):
if(c[i] in d.keys()):
d[c[i]] +=1
else:
d[c[i]] = 1
acar = 1
for i in r... | vfc_41933 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n2 2 4 5 3\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 843_E. Maximum Flow | Solve the following coding problem using the programming language python:
You are given a directed graph, consisting of n vertices and m edges. The vertices s and t are marked as source and sink correspondingly. Additionally, there are no edges ending at s and there are no edges beginning in t.
The graph was construc... | vfc_41937 | {
"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 6 1 5\n1 2 1\n2 3 1\n3 5 1\n1 4 1\n4 3 0\n4 5 1\n",
"output": "2\n1 1\n1 2\n1 2\n1 1\n0 1\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10 1 6\n10 5 0\n5 6 1\n1 9 0\n4 10 0\n7 ... | |
code_contests | verifiable_code | 864_C. Bus | Solve the following coding problem using the programming language python:
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it im... | ```python
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
"""
created by shhuan at 2017/10/4 19:43
"""
a, b, f, k = map(int, input().split())
if b < f or f+b < a:
print(-1)
exit(0)
r = a-f
res = 0
fuel = b
for i in range(k):
if i % 2 == 0:
... | vfc_41941 | {
"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": "6 9 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5 4 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | 88_B. Keyboard | Solve the following coding problem using the programming language python:
Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of th... | ```python
import math
def shift_key_test(arr, dictionary, distance, row, column):
arr_dict = {}
if dictionary.get("S") is not None:
for a, b in dictionary.get("S"):
upper_limit = b - distance
lower_limit = b + distance
if upper_limit < 0:
upper_limit... | vfc_41945 | {
"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": "2 2 1\nab\ncS\n5\nabcBA\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 9 4\nqwertyuio\nasdfghjkl\nSzxcvbnmS\n35\nTheQuIcKbRoWnFOXjummsovertHeLazYDOG\n",
"output": "... |
code_contests | verifiable_code | 912_E. Prime Gift | Solve the following coding problem using the programming language python:
Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn how to solve number theory problems in the past year. That's why instead of Ded Moroz he was visited by his teammate Andrew, who solem... | vfc_41949 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 5\n7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 7 11 13 31\n17\n",
"output": "93\n",
"type": "stdin_stdout"
},
{
"fn_name": null... | |
code_contests | verifiable_code | 934_E. A Colourful Prospect | Solve the following coding problem using the programming language python:
Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement.
Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Ye... | ```python
from math import sqrt
class vector:
def __init__(self, _x = 0, _y = 0):
self.x = _x
self.y = _y
def len(self):
return sqrt(self.x ** 2 + self.y ** 2)
def len_sq(self):
return self.x ** 2 + self.y ** 2
def __mul__(self, other):
if (type(self) == type(other)):
return self.x * other.x + self.y ... | vfc_41953 | {
"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": "3\n0 0 2\n2 0 2\n1 1 2\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 960_G. Bandit Blues | Solve the following coding problem using the programming language python:
Japate, while traveling through the forest of Mala, saw N bags of gold lying in a row. Each bag has some distinct weight of gold between 1 to N. Japate can carry only one bag of gold with him, so he uses the following strategy to choose a bag.
... | vfc_41957 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 2\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 ... | |
code_contests | verifiable_code | 988_D. Points and Powers of Two | Solve the following coding problem using the programming language python:
There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary ... | ```python
n = int(input())
a = [int(i) for i in input().split()]
d = {}
power = [2**i for i in range(31)]
ans = []
for i in a:
d[i] = 0
for num in d.keys():
for p in power:
if num+p in d:
ans = [num, num+p]
if num+p+p in d:
print(3)
ans.append(nu... | vfc_41961 | {
"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": "5\n-1 2 5 8 11\n",
"output": "1\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3 5 4 7 10 12\n",
"output": "3\n3 4 5\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | amazing-race-3 | Solve the following coding problem using the programming language python:
It is the final leg of the most famous amazing race. The top 'n' competitors have made it to the final. The final race has just begun. The race has 'm' checkpoints. Each team can reach any of the 'm' checkpoint but after a team reaches a particu... | ```python
def possible(time):
match = [-1 for i in xrange(m)]
vis = [0 for i in xrange(n)]
ret, tim = 0, 42
def dfs(u):
vis[u] = tim
for t, i in G[u]:
if t <= time:
if match[i] == -1 or (vis[match[i]] != tim and dfs(match[i])):
match[i] = u
return True
else:
break
return False
for i i... | vfc_41965 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 1\n0 1\n0 0\n0 10\n27 29\n458 9651\n5 3\n\nSAMPLE",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1\n0 1\n0 0\n0 10\n27 29\n458 9651\n5 3\n\nS@MPLE",
"output": "... |
code_contests | verifiable_code | candy-1 | Solve the following coding problem using the programming language python:
Daenerys Targaryen set her eyes on The Kingdom of The North which is ruled by the House Stark. There is a huge market in the Castle of Winterfell that sells products of all prices starting from 1 coin i.e. there are products worth Rs 1, 2, 3 . .... | ```python
t = input()
ls = 10**17
for _ in xrange(t):
n = input()
num = [int(i) for i in raw_input().split()]
num.sort()
x = 0
for i in num:
if(i<=x+1):
x+=i
x+=1
if(x>ls):
print -1
else:
print x
``` | vfc_41969 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10\n1 2 4 8 16 32 64 128 256 512\n5\n1 3 4 5 7\n\nSAMPLE",
"output": "1024\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10\n1 2 4 8 16 32 64 128 256 512\n5\n0 3 4 5 7\n\nSAMPLE",... |
code_contests | verifiable_code | defuse-the-bomb-3 | Solve the following coding problem using the programming language python:
Platypus Perry is on a mission again. This time, Dr. Heinz Doofenshmirtz has plotted a bomb in the centre of Danville town. He wishes to rebuild the town.
We need to defuse the bomb for Perry. As always, Dr. Heinz has given perry the key combin... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
T=input()
for t in xrange(T):
l=raw_input().split()
#a=(int)l[0]
#print l[0]*2
b=int(l[1])
index=0
for i in range(len(l[0])-len(l[1])+1):
x=int(l[0][index:index+len(l[... | vfc_41973 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n98765 23\n\nSAMPLE",
"output": "2254\n2001\n1748\n1495\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n987654321 123\n120000000 22",
"output": "121401\n107748\n94095\n80442\n66... |
code_contests | verifiable_code | game-of-thrones | Solve the following coding problem using the programming language python:
Joffrey Baratheon is the king of all seven kingdoms. His birthday is coming very soon. So he invited all lords, ladies and kings of the all kingdoms. So Joffrey send a unique secret code X with all invitations. When any person want to attend th... | ```python
import math
t=input()
c=0
A=[]
if t>=1 and t<=10:
for i in range(0,t):
n=input()
c=0
A=[]
if n>=1 and n<=100000:
s=raw_input().split()
if len(s)==n:
for j in range(0,len(s)):
k=int(s[j])
if k>=1... | vfc_41977 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n339\n7120 78930 993 610 24465 83397 59561 14581 32981 94398 5903 62965 79985 51684 32294 46105 69019 38996 16521 30147 60587 96835 96471 20161 43333 79230 93149 47024 89262 8182 13144 41449 9263 31721 96777 65455 6930 34278 4221... |
code_contests | verifiable_code | kth-shortest-path | Solve the following coding problem using the programming language python:
You are given a cost matrix of dimensions m X n. The problem of finding the minimal path from top-left corner to some cell in the matrix is well studied. Here, we are gonna add a little twist.
To refresh your memory, the total cost of a path is... | ```python
from collections import deque
for _ in xrange(input()):
R, C = map(int, raw_input().split())
li = []
for _ in xrange(R):
li.append(raw_input().split())
res = []
for i in xrange(R):
t = []
for j in xrange(C):
t.append([])
res.append(t... | vfc_41981 | {
"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 2\n1 2\n3 4\n2\n1 1 1\n1 1 2\n2 2\n1 2\n## 4\n3\n1 1 1\n1 1 2\n1 0 1\n\nSAMPLE",
"output": "7\n8\n7\nNot so many paths\nObstacle",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | monk-and-iq | Solve the following coding problem using the programming language python:
Monk and his P-1 friends recently joined a college. He finds that N students have already applied for different courses before him. Courses are assigned numbers from 1 to C. He and his friends will follow the following conditions when choosing ... | ```python
import heapq
def solve(c, iqs, piqs):
res = []
q = [(0, i, 0, (0, 0)) for i in range(len(iqs) + 1, c + 1)]
q += [(iq, i, 1, (0, iq)) for i, iq in enumerate(iqs, 1)]
heapq.heapify(q)
for iq in piqs:
_, course, student_count, last_iqs = q[0]
res.append(course)
studen... | vfc_41985 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 4\n2 8 5 1\n9 10 5 1\n\nSAMPLE",
"output": "5 4 1 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 10 10\n2 8 5 1 10 5 9 9 3 5\n2 5 1 8 6 5 1 10 1 6",
"output": "4 1 9 3 6 10 4... |
code_contests | verifiable_code | passing-the-parcel | Solve the following coding problem using the programming language python:
Have you ever been a part of the exciting game Passing the Parcel ? Sid is on a school picnic with his classmates. The teacher decides to make the whole class play the game of Passing the Parcel. Since the
winner of the game gets lots of chocol... | ```python
num = int(raw_input())
song = raw_input()
students = list(range(1,num+1))
ballpointer = 0
# problem
while len(students) > 1:
for lyrics in song:
if len(students) == 1:
break
if lyrics == 'b':
del students[ballpointer]
if lyrics == 'a':
ballpointe... | vfc_41989 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nabba\n\nSAMPLE",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\nbbba\n\nSAMPLE",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | roy-and-counting-sorted-substrings-1 | Solve the following coding problem using the programming language python:
Roy has a string S of length N. String S is made of lower case English alphabets. He likes sorted strings. So he wonders how many substrings of S are sorted.
Given the string S, your task is to count the number of sorted substrings of S.
... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
t=int(raw_input())
while t:
t-=1
n=int(raw_input())
s=raw_input()
sort=1
c=0
for i in range(1,n):
if(s[i]>=s[i-1]):
sort+=1
else:
c+= (so... | vfc_41993 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\nabc\n3\nbba\n4\nabac\n3\nzyxSAMPLE",
"output": "6\n4\n6\n3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | string-query-22 | Solve the following coding problem using the programming language python:
Given a string s and m queries. For each query delete the K-th occurence of a character x.
Input:
The first line contains the string s followed by an integer m.
The string consists of lowercase letters.
After that m lines follow each line conta... | ```python
s = raw_input()
s = list(s)
ln = len(s)
di = {}
ind = 0
for i in s:
if i in di:
t = di[i]
t.append(ind)
di[i] = t
else:
di[i] = [ind]
ind+=1
#print di
m = input()
while m:
m-=1
k,x = raw_input().split()
k = int(k)
k -= 1
t = di[x]
t.pop(k)
di[x] = t
temp = '$'*ln
temp = list(temp)
for i in... | vfc_41997 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abcdbcaab\n5\n2 a\n1 c\n1 d\n3 b\n2 a\n\nSAMPLE",
"output": "abbc\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abcdbcaab\n5\n2 a\n1 c\n1 c\n3 b\n2 a\n\nSAMPLE",
"output": "abdb\n"... |
code_contests | verifiable_code | utkarsh-and-old-graph-3 | Solve the following coding problem using the programming language python:
In his childhood, Utkarsh had a Graph having N nodes and N-1 edges. It was always possible to go from any node to any other node via a path.
Now after so many years he has discovered the same Graph in the store room of his house. But many edg... | ```python
import math
x,y=map(int,raw_input().split())
for i in range(y):
z=raw_input()
print (((x*(x-1))/2)-(x-1))
``` | vfc_42001 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n4 2\n2 1\n3 2\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "60763 1494\n52004 12938\n18442 7602\n43931 22561\n48729 11667\n38628 28838\n44614 9005\n38681 20... |
code_contests | verifiable_code | p00017 Caesar Cipher | Solve the following coding problem using the programming language python:
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphab... | ```python
ca = ord('a')
def convert(s, d):
res = []
for c in s:
if c not in ' .':
c = chr(((ord(c) - ca + d) % 26) + ca)
res.append(c)
return "".join(res)
for line in open(0).readlines():
s = line.strip()
for d in range(26):
s0 = convert(s, d)
if "the" in ... | vfc_42045 | {
"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": "xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt.",
"output": "this is the picture that i took in the trip.",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "xlmw mw xli tmgxyvi xlex m xsso mr ilx ... |
code_contests | verifiable_code | p00470 Commute routes | Solve the following coding problem using the programming language python:
problem
A city in Canada where JOI lives is divided into a grid pattern by w roads that extend straight in the north-south direction and h roads that extend straight in the east-west direction.
The w roads in the north-south direction are numb... | ```python
for e in iter(input,'0 0'):
w,h=map(int,e.split())
M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w]
for i in range(1,w):
for j in range(1,h):
a,b,c,d=[*M[i-1][j][:2],*M[i][j-1][2:]]
M[i][j]=[d,a+b,b,c+d]
print((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5)
``` | vfc_42057 | {
"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 4\n15 15\n0 0",
"output": "5\n43688",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n15 20\n0 0",
"output": "5\n58046\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00805 Fishnet | Solve the following coding problem using the programming language python:
A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previous night he had encountered a terrible storm and had reached this uninhabited island. Some wrecks of his ship were sp... | vfc_42065 | {
"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": "2\n0.2000000 0.6000000\n0.3000000 0.8000000\n0.3000000 0.5000000\n0.5000000 0.6000000\n2\n0.3333330 0.6666670\n0.3333330 0.6666670\n0.3333330 0.6666670\n0.3333330 0.6666670\n4\n0.2000000 0.4000000 0.6000000 0.8000000\n0.1000000 0.5... | |
code_contests | verifiable_code | p00936 Squeeze the Cylinders | Solve the following coding problem using the programming language python:
Example
Input
2
10 10
Output
40.00000000
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x i... | vfc_42069 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n10 10",
"output": "40.00000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n10 4",
"output": "26.649110641\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01069 Sum of Sequences | Solve the following coding problem using the programming language python:
Problem
Given a sequence A with n elements, a sequence B with m elements, q queries each consisting of an integer c.
For each query
The absolute value of the difference between the sum of all [la, ra] in sequence A and the sum of all [lb, rb] i... | vfc_42073 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 1\n1 2 3\n3 1 2\n3",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4 2\n1 2 3 4 5\n2 2 2 2\n11\n12",
"output": "3\n4",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01203 Compress Files | Solve the following coding problem using the programming language python:
Your computer is a little old-fashioned. Its CPU is slow, its memory is not enough, and its hard drive is near to running out of space. It is natural for you to hunger for a new computer, but sadly you are not so rich. You have to live with the ... | vfc_42077 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n2 1\n2 1\n2 1\n2 1\n2 1\n5 1\n1 1\n4 2\n0 0",
"output": "2\nImpossible",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01506 Digit | Solve the following coding problem using the programming language python:
For a positive integer a, let S(a) be the sum of the digits in base l. Also let L(a) be the minimum k such that S^k(a) is less than or equal to l-1. Find the minimum a such that L(a) = N for a given N, and print a modulo m.
Input
The input c... | vfc_42085 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 1000 10\n1 1000 10\n0 0 0",
"output": "Case 1: 1\nCase 2: 10",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 1000 4\n1 1000 10\n0 0 0",
"output": "Case 1: 1\nCase 2: 10\n",
"... | |
code_contests | verifiable_code | p01677 Broken Audio Signal | Solve the following coding problem using the programming language python:
Problem Statement
Nathan O. Davis is a student at the department of integrated systems.
Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an au... | ```python
INF = float('inf')
def judge(src):
x_max = INF
x_min = -INF
for i,(s1,s2) in enumerate(zip(src,src[1:])):
if s1 == s2:
return 'none'
if i%2:
s1,s2 = s2,s1
if s1 != 'x' and s2 != 'x':
if s1 < s2:
return 'none'
... | vfc_42089 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 x 2 4 x\n2\nx x\n2\n1 2\n2\n2 1\n2\n1000000000 x\n4\nx 2 1 x\n0",
"output": "3\nnone\nambiguous\nnone\nambiguous\nnone",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 x 2 4 x\n2\nx... |
code_contests | verifiable_code | p01821 Identity Function | Solve the following coding problem using the programming language python:
Example
Input
3
Output
1
The input will be given via stdin and the output should be printed to stdout by your code.
Now solve the problem by providing the code. | ```python
N = int(input())
def gcd(m, n):
while n:
m, n = n, m % n
return m
def lcm(m, n):
return m // gcd(m, n) * n
def carmichael(x):
r = 1
b = 0
while x & 1 == 0:
b += 1
x >>= 1
if b > 1:
r = 2 if b == 2 else 2**(b-2)
y = 3
while y*y <= x:
... | vfc_42093 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p01956 Window | Solve the following coding problem using the programming language python:
In the building of Jewelry Art Gallery (JAG), there is a long corridor in the east-west direction. There is a window on the north side of the corridor, and $N$ windowpanes are attached to this window. The width of each windowpane is $W$, and the... | ```python
n,h,w=map(int,input().split())
x=list(map(int,input().split()))
wide_total=n*w
wide_cover=[False]*wide_total
for i in range(n):
if (i+1)%2==1:
for j in range(i*w+x[i],i*w+x[i]+w):
wide_cover[j]=True
else:
for j in range(i*w-x[i],i*w-x[i]+w):
wide_cover[j]=True
... | vfc_42097 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 3\n1 1 2 3",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1 4\n3 3 2 2",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | p02103 Great Devil Sakanikia | Solve the following coding problem using the programming language python:
Problem
The great devil Sacagna was still attacked by her natural enemy cat today.
I bought a secret weapon because I couldn't do it all the time.
This secret weapon can block the cat's path of movement by creating huge rocks that keep cats awa... | vfc_42101 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 3\n0 2\n2 2\n4 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 2\n0 2\n2 2",
"output": "1",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p02243 Single Source Shortest Path II | Solve the following coding problem using the programming language python:
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
Constraints
* $1 \leq n \leq 10,000$
* $0 \leq c_i ... | ```python
import heapq
n = int(input())
C = [[] for _ in range(n)]
for _ in range(n):
tmp = list(map(int,input().split()))
for i in range(1,tmp[1]+1):
C[tmp[0]].append(tuple(tmp[2*i:2*i+2]))
q = []
def heap_dijkstra(start = 0):
visited = [False]*n
INF = 10000000000
d = [INF]*n
d[star... | vfc_42105 | {
"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\n0 3 2 3 3 1 1 2\n1 2 0 2 3 4\n2 3 0 3 3 1 4 1\n3 4 2 1 0 1 1 4 4 3\n4 2 2 1 3 3",
"output": "0 0\n1 2\n2 2\n3 1\n4 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 3 2 3 3 1 1 1\n1 ... |
code_contests | verifiable_code | p02389 Rectangle | Solve the following coding problem using the programming language python:
Write a program which calculates the area and perimeter of a given rectangle.
Constraints
* 1 ≤ a, b ≤ 100
Input
The length a and breadth b of the rectangle are given in a line separated by a single space.
Output
Print the area and perimet... | ```python
a, b = input().split()
print(int(a)*int(b),int(a)*2+int(b)*2)
``` | vfc_42109 | {
"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",
"output": "15 16",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 5",
"output": "0 10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | cb05 | Solve the following coding problem using the programming language python:
A regular octagon with vertices X1, X2,..., X8 is provided. A frog starts jumping from the vertex X1. It may jump to any of the two adjacent vertices in one jump except from X5. When it reaches X5, it stops and stays there. Let P(n) be the numbe... | ```python
a=[]
i=2
a.insert(0,0)
a.insert(1,2)
while i<101:
n=4*a[i-1]-2*a[i-2]
a.append(n)
i=i+1
#def f(n):
# if n == 0:
# return 0
# elif n == 1:
# return 2
# else:
# return 4*f(n-1) -2*f(n-2)
t=input()
i=0
while i<t:
n=input()
if n%2==0:
n=n/2-1
print a[n]
el... | vfc_42113 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n4",
"output": "0\n0\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n5",
"output": "0\n0\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | crz02 | Solve the following coding problem using the programming language python:
In the University College of JNTUK Vizianagaram external lab examinations were being conducted. Management has decided to strictly prohibit the mal practices for that the management has decided to arrange cardboards of size nx2 to place in betwe... | ```python
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# pylint: disable=invalid-name,missing-docstring,bad-builtin
from sys import stdin
def main():
arr = [0]*(1000001)
arr[0] = arr[1] = 1
for x in xrange(2, 1000001):
arr[x] = (arr[x - 1] + arr[x - 2]) % 1000000007
dstream = map(int, stdin.read... | vfc_42117 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n2\n3",
"output": "1\n2\n3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | harry | Solve the following coding problem using the programming language python:
Problem description
Nineteen years after the conclusion of events of Harry Potter and the Deathly Hallows, Harry Potter is now a Ministry of Magic employee. His youngest son Albus Severus Potter struggle with the weight of a family legacy he nev... | ```python
import random
import math
for test_Case in range(int(raw_input())):
potion = raw_input()
count_potion = [0]*26
for c in potion:
count_potion[ord(c)-ord('a')]+=1
count_ingr = [0]*26
n = int(raw_input())
for i in range(n):
temp = r... | vfc_42121 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nabccde\n2\nacd\nbc\nabccde\n2\nad\nbce\nmnopq\n3\namn\nopsp\nqrwas",
"output": "NO\nNO\nYES",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | mgcrnk | Solve the following coding problem using the programming language python:
Everybody loves magic, especially magicians who compete for glory on the Byteland Magic Tournament. Magician Cyael is one such magician.
Cyael has been having some issues with her last performances and today she’ll have to perform for an audienc... | ```python
from sys import stdin
for trial in xrange(int(stdin.readline())):
N = int(stdin.readline())
S = [map(int,stdin.readline().split()) for i in range(N)]
dp = [[0 for i in xrange(N)] for j in xrange(N)]
for i in xrange(1,N): dp[i][0] = dp[i-1][0]+S[i][0]
for i in xrange(1,N): dp[0][i] = dp[0]... | vfc_42125 | {
"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\n0 -4\n8 0\n2\n0 -45\n-3 0",
"output": "8.000000\nBad Judges\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2\n0 -4\n8 0\n2\n0 -45\n-2 0",
"output": "8.0000000\nBad Judges... |
code_contests | verifiable_code | recipe | Solve the following coding problem using the programming language python:
The chef has a recipe he wishes to use for his guests,
but the recipe will make far more food than he can serve to the guests.
The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but ma... | ```python
from fractions import gcd as g
def gcdN(l):
l.sort()
temp=l[0]
for i in l[1:]:
temp=g(temp,i)
return temp
# print gcdN([12,6,3,4,2])
for testcases in xrange(int(raw_input())):
temp=map(int,raw_input().split())
n=gcdN(temp[1:])
for i in temp[1:]:
print (i/n),
print ''
``` | vfc_42129 | {
"difficulty": "1",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 4 4\n3 2 3 4\n4 3 15 9 6",
"output": "1 1\n2 3 4\n1 5 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 4 4\n3 2 3 4\n4 3 20 9 6",
"output": "1 1\n2 3 4\n3 20 9 6\n",
... |
code_contests | verifiable_code | tree | Solve the following coding problem using the programming language python:
Let's define a good tree:
It is a tree with k * n nodes labeled from 0 to k * n - 1
Node i and node j are not adjacent, for all 0 <= i, j < k * n such that i div k = j div k (here div means integer division. E.g. 7 div 2 = 3)
Given n and k, ... | ```python
# a dive into the deep, a lot of concepts here
# Kirchoff's Matrix Tree Theorem, Laplacian matrix, cofactors, a revision into
# determinants
# Revision: replacing a row by itself minus a multiple of another row:
# doesn't change determinant
# k=3, A =
# 0,0,0,1,1,1,1,1,1.......1
# 0,0,0,1,1,1,1,1,1....... | vfc_42133 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1",
... |
code_contests | verifiable_code | 1016_D. Vasya And The Matrix | Solve the following coding problem using the programming language python:
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!
Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise exc... | ```python
def sum(x):
ans = 0
for i in x:
ans ^= i
return ans
i = lambda: [*map(int, input().split())]
n, m = i()
a = i()
b = i()
if sum(a) != sum(b):
print("NO")
quit()
print("YES")
one = sum(a[1:]) ^ b[0]
print(one, end = " ")
for i in b[1:]:
print(i, end = " ")
print()
st = ""
for i ... | vfc_42137 | {
"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 3\n1 7 6\n2 15 12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n2 9\n5 3 13\n",
"output": "YES\n12 3 13\n9 0 0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 103_D. Time to Raid Cowavans | Solve the following coding problem using the programming language python:
As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space.
Sometimes cows gather into cowavan... | ```python
import sys
range = xrange
input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
n = inp[ii]
ii += 1
A = [float(x) for x in inp[ii:ii + n]]
ii += n
queries = [[] for _ in range(n)]
q = inp[ii]
ii += 1
m = 500
ans = [0]*q
B = []
for _ in range(q):
a = inp[ii] - 1
ii += 1
b... | vfc_42141 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 70000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n2\n1 1\n1 2\n",
"output": "6\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2 3 5 7\n3\n1 3\n2 3\n2 2\n",
"output": "9\n3\n10\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | 1062_E. Company | Solve the following coding problem using the programming language python:
The company X has n employees numbered from 1 through n. Each employee u has a direct boss p_u (1 ≤ p_u ≤ n), except for the employee 1 who has no boss. It is guaranteed, that values p_i form a tree. Employee u is said to be in charge of employe... | vfc_42145 | {
"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": "11 5\n1 1 3 3 3 4 2 7 7 6\n4 6\n4 8\n1 11\n9 11\n8 11\n",
"output": "4 1\n8 1\n1 0\n11 3\n8 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n3 1 3 3\n4 5\n1 5\n1 2\n3 5\n",
"ou... | |
code_contests | verifiable_code | 1084_D. The Fair Nut and the Best Path | Solve the following coding problem using the programming language python:
The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in... | ```python
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
from collections import deque
n=int(input())
l=list(map(int,input().split()))
visited=set()
graph={i:set() for i in range(1,n+1)}
d={}
papa=[0 for i in range(n+1)]
level=[[] for i in range(n+1)]
z=[[0] for i... | vfc_42149 | {
"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": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 3\n1 2 2\n1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1104_A. Splitting into digits | Solve the following coding problem using the programming language python:
Vasya has his favourite number n. He wants to split it to some non-zero digits. It means, that he wants to choose some digits d_1, d_2, …, d_k, such that 1 ≤ d_i ≤ 9 for all i and d_1 + d_2 + … + d_k = n.
Vasya likes beauty in everything, so he... | ```python
n = int(input())
f = 0
for i in range(9,0,-1):
if n%i==0:
f = 1
break
if f == 0:
print(1)
print(n)
else:
print(n//i)
print(*(n//i*str(i).split()))
``` | vfc_42153 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "4\n1 1 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1131_F. Asya And Kittens | Solve the following coding problem using the programming language python:
Asya loves animals very much. Recently, she purchased n kittens, enumerated them from 1 and n and then put them into the cage. The cage consists of one row of n cells, enumerated with integers from 1 to n from left to right. Adjacent cells had a... | ```python
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n + 1)]
self.rank = [0 for _ in range(n + 1)]
self.size = [1] * (n + 1)
self.group = [[i] for i in range(n + 1)]
def find(self, x):
# If x is root
if self.parent[x] == x:
... | vfc_42157 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 4\n2 5\n3 1\n4 5\n",
"output": "1 4 3 2 5 ",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1152_B. Neko Performs Cat Furrier Transform | Solve the following coding problem using the programming language python:
Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.
Assume that we have a cat with a numbe... | ```python
from sys import stdin,stdout
from collections import Counter
def ai(): return list(map(int, stdin.readline().split()))
def ei(): return map(int, stdin.readline().split())
def ip(): return int(stdin.readline().strip())
def op(ans): return stdout.write(str(ans) + '\n')
import math
n = ip()
ans = 0
li = []
for... | vfc_42161 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n",
"output": "0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n",
"output": "0\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "39\n",
... |
code_contests | verifiable_code | 1173_F. Nauuo and Portals | Solve the following coding problem using the programming language python:
Nauuo is a girl who loves playing games related to portals.
One day she was playing a game as follows.
In an n× n grid, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. We denote a ... | vfc_42165 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 1 5 4 2\n4 2 1 3 5\n",
"output": "3\n2 1 1 3\n5 2 2 2\n5 3 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 2\n3 1 2\n",
"output": "2\n1 1 1 2\n3 2 2 3\n",
"type... | |
code_contests | verifiable_code | 1191_D. Tokitsukaze, CSL and Stone Game | Solve the following coding problem using the programming language python:
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a n... | ```python
import sys
n = int(input())
a = sorted([int(i) for i in input().split()])
t = 0
for i in range(1,n):
t += a[i]==a[i-1]
if t >= 2:
print("cslnb")
sys.exit(0)
if t:
for i in range(n):
if a[i]==a[i+1]:
if a[i] and a[i]!=a[i-1]+1:
a[i] -= 1
break
else:
print("cslnb")
sys.exit(0)
print(... | vfc_42169 | {
"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": "3\n2 3 1\n",
"output": "sjfnb\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n",
"output": "cslnb\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 120_E. Put Knight! | Solve the following coding problem using the programming language python:
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard n × n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square ... | vfc_42173 | {
"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": "2\n2\n1\n",
"output": "1\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n34\n58\n97\n93\n50\n17\n95\n47\n72\n11\n76\n28\n89\n82\n86\n68\n56\n74\n68\n4\n72\n24\n3\n82\n60\n11\n39\n7... | |
code_contests | verifiable_code | 1230_B. Ania and Minimizing | Solve the following coding problem using the programming language python:
Ania has a large integer S. Its decimal representation has length n and doesn't contain any leading zeroes. Ania is allowed to change at most k digits of S. She wants to do it in such a way that S still won't contain any leading zeroes and it'll... | ```python
n, k = [int(x) for x in input().strip().split()]
S = input().strip()
if n == 1 and k == 1:
res = '0'
elif k == 0:
res = S
else:
S = [c for c in S]
if S[0] != '1':
S[0] = '1'
k -= 1
i = 1
while k > 0:
if i >= n:
break
if S[i] == '0':
... | vfc_42177 | {
"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": "1 1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n102\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 1251_E2. Voting (Hard Version) | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.
There are n voters, and two ways to convince each of them to vote... | ```python
from sys import stdin, stdout
import heapq
class MyHeap(object):
def __init__(self, initial=None, key=lambda x:x):
self.key = key
if initial:
self._data = [(key(item), item) for item in initial]
heapq.heapify(self._data)
else:
self._data = []
def p... | vfc_42181 | {
"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\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n",
"output": "8\n0\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3\n1 5\n2 10\n2 8\n7\n... |
code_contests | verifiable_code | 1271_D. Portals | Solve the following coding problem using the programming language python:
You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer n castles of your opponent.
Let's describe the game process in detail. Initially you control an army ... | ```python
import sys
input = sys.stdin.buffer.readline
N, M, K = map(int, input().split())
A = [0] * N
B = [0] * N
C_raw = [0] * N
for i in range(N):
A[i], B[i], C_raw[i] = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
u, v = map(int, input().split())
adj[v].append(u)
C = [[... | vfc_42185 | {
"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 3 7\n7 4 17\n3 0 8\n11 2 0\n13 3 5\n3 1\n2 1\n4 1\n",
"output": "22",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1315_E. Double Elimination | Solve the following coding problem using the programming language python:
The biggest event of the year – Cota 2 world championship "The Innernational" is right around the corner. 2^n teams will compete in a double-elimination format (please, carefully read problem statement even if you know what is it) to identify th... | vfc_42193 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n1 3 5 7\n",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n6\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... | |
code_contests | verifiable_code | 1337_A. Ichihime and Triangle | Solve the following coding problem using the programming language python:
Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.
These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winne... | ```python
"""
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math,cmath,time
start_time = time.time()
################# ---- USER DEFINED INPUT FUNCTIONS ---- #################
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
... | vfc_42197 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 5 7\n1 5 5 7\n100000 200000 300000 400000\n1 1 977539810 977539810\n",
"output": "3 5 5\n5 5 5\n200000 300000 300000\n1 977539810 977539810\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 1359_E. Modular Stability | Solve the following coding problem using the programming language python:
We define x mod y as the remainder of division of x by y (\% operator in C++ or Java, mod operator in Pascal).
Let's call an array of positive integers [a_1, a_2, ..., a_k] stable if for every permutation p of integers from 1 to k, and for ever... | ```python
import sys
import string
input = sys.stdin.readline
import math
#import numpy
#letters = list(string.ascii_lowercase)
from decimal import Decimal
n = list(map(int, input().split()))
n,k = n[0], n[1]
m = 998244353
fact = []
fac = 1
for i in range(1, n+2):
fac *= i
fac = fac % m
fact.append(fac)
... | vfc_42201 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "500000 1\n",
"output": "500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1337 42\n",
"output": "95147305\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1379_F2. Chess Strikes Back (hard version) | Solve the following coding problem using the programming language python:
Note that the difference between easy and hard versions is that in hard version unavailable cells can become available again and in easy version can't. You can make hacks only if all versions are solved.
Ildar and Ivan are tired of chess, but t... | vfc_42205 | {
"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": "1 3 3\n1 1\n1 5\n2 4\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 10\n4 2\n6 4\n1 3\n4 2\n6 4\n2 2\n2 4\n1 3\n4 4\n3 1\n",
"output": "YES\nYES\nNO\... | |
code_contests | verifiable_code | 139_E. Mushroom Gnomes - 2 | Solve the following coding problem using the programming language python:
One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story:
Everybody knows that the mushroom gnomes' power lies in the magic mushrooms that grow in the native woods of the gnomes. Ther... | vfc_42209 | {
"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": "2 1\n2 2 50 50\n4 2 50 50\n3 1\n",
"output": "0.250000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n2 2 50 50\n1 1\n",
"output": "0.500000\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 1423_I. Lookup Tables | Solve the following coding problem using the programming language python:
John has Q closed intervals of consecutive 2K-bit numbers [l_i, r_i] and one 16-bit value v_i for each interval. (0 ≤ i < Q)
John wants to implement a function F that maps 2K-bit numbers to 16-bit numbers in such a way that inputs from each int... | vfc_42213 | {
"difficulty": "15",
"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 3\n4 4 3\n5 6 2\n12 14 1\n",
"output": "impossible\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n4 5 3\n6 7 2\n0 3 0\n12 13 1\n",
"output": "possible\n3\n3\n2\n2\n0\n3\n0\n1... | |
code_contests | verifiable_code | 1443_B. Saving the City | Solve the following coding problem using the programming language python:
Bertown is a city with n buildings in a straight line.
The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length n, where the i-th character is "1" if there is a mine under the buildi... | ```python
# ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
def solve():
a,b = map(int, input().split())
... | vfc_42217 | {
"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\n1 1\n01000010\n5 1\n01101110\n",
"output": "2\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 1\n01000110\n5 1\n01101110\n",
"output": "2\n6\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | 1468_K. The Robot | Solve the following coding problem using the programming language python:
There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. W... | ```python
#region Header
#!/usr/bin/env python3
# from typing import *
import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq
def input():
return sys.stdin.readline()[:-1]
# sys.setrecursionlimit(1000000)
#endregion
# _INPUT = """# paste here...
# """
# sy... | vfc_42221 | {
"difficulty": "17",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nL\nRUUDL\nLLUU\nDDDUUUUU\n",
"output": "\n-1 0\n1 2\n0 0\n0 1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1516_B. AGAGA XOOORRR | Solve the following coding problem using the programming language python:
Baby Ehab is known for his love for a certain operation. He has an array a of length n, and he decided to keep doing the following operation on it:
* he picks 2 adjacent elements; he then removes them and places a single integer in their pla... | ```python
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
r = 0
for j in range(len(a)):
r ^= a[j]
if not r:
print("Yes")
else:
t = 0
i = 0
s = 0
while i < len(a) and t < 2:
s ^= a[i]
if s... | vfc_42229 | {
"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": "2\n3\n0 2 2\n4\n2 3 1 10\n",
"output": "\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n3 3 3 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 171_D. Broken checker | Solve the following coding problem using the programming language python:
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for th... | ```python
vals = [2, 3, 1, 2, 1]
i = int(input())
print(vals[i-1])
``` | vfc_42237 | {
"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\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"ou... |
code_contests | verifiable_code | 191_B. Demonstration | Solve the following coding problem using the programming language python:
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King of Berland. Berland opposition, led by Mr. Ovalny, believes that the elections were not fair enough and wants to organize a demonstration at one ... | ```python
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
value = int(stdin.readline())
prices = list(map(int, stdin.readline().split()))
used = {}
challengers = prices[:-1]
for i in range(n - 1):
challengers[i] = (challengers[i], i)
challengers.sort(reverse = True)
ind = challengers[k -... | vfc_42241 | {
"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 4\n1000000000000000\n5 4 3 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n8\n3 2 4 1 5\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 215_B. Olympic Medal | Solve the following coding problem using the programming language python:
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with r... | ```python
from math import sqrt
f = lambda: list(map(int, input().split()))
r1 = max(f()[1:])
p1s = f()[1:]
p2 = min(f()[1:])
a, b = f()
print(str(sqrt(max(b * p1 * r1**2 / float(a * p2 + b * p1) for p1 in p1s))))
``` | vfc_42245 | {
"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": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n",
"output": "2.2677868381\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 2 3\n1 2\n3 3 2 1\n1 2\n",
"output": "2.6832815730\n",
"type": "... |
code_contests | verifiable_code | 263_E. Rhombus | Solve the following coding problem using the programming language python:
You've got a table of size n × m. On the intersection of the i-th row (1 ≤ i ≤ n) and the j-th column (1 ≤ j ≤ m) there is a non-negative integer ai, j. Besides, you've got a non-negative integer k.
Your task is to find such pair of integers (a... | vfc_42253 | {
"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": "5 7 3\n8 2 3 4 2 3 3\n3 4 6 2 3 4 6\n8 7 6 8 4 5 7\n1 2 3 2 1 3 2\n4 5 3 2 1 2 1\n",
"output": "3 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 2\n1 2 3 4\n1 1 1 1\n2 2 2 2\n4 3 2 1\... | |
code_contests | verifiable_code | 287_E. Main Sequence | Solve the following coding problem using the programming language python:
As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since p... | ```python
import sys
range = xrange
input = raw_input
n = int(input())
P = [int(x) for x in input().split()]
for i in [int(x) - 1 for x in input().split()][1:]:
P[i] *= -1
stack = []
for i in reversed(range(n)):
p = P[i]
if (not stack) or stack[-1] != p:
stack.append(abs(p))
P[i] = -abs(p... | vfc_42257 | {
"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": "4\n1 2 2 1\n2 3 4\n",
"output": "YES\n1 2 -2 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 1 1\n1 3\n",
"output": "YES\n1 1 -1 -1\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 312_E. Fetch the Treasure | Solve the following coding problem using the programming language python:
Rainbow built h cells in a row that are numbered from 1 to h from left to right. There are n cells with treasure. We call each of these n cells "Treasure Cell". The i-th "Treasure Cell" is the ai-th cell and the value of treasure in it is ci dol... | vfc_42261 | {
"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": "10 3 5 2\n5 50\n7 60\n8 100\n2 2 5\n3\n1 3\n3\n3\n",
"output": "55\n100\n50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "484 30 46 67\n51 74\n105 26\n242 24\n22 81\n48 46\n21 11\n60 74\... | |
code_contests | verifiable_code | 335_C. More Reclamation | Solve the following coding problem using the programming language python:
In a far away land, there are two cities near a river. One day, the cities decide that they have too little space and would like to reclaim some of the river area into land.
The river area can be represented by a grid with r rows and exactly tw... | ```python
r,n = [int(x) for x in input().split()]
cells = [[int(x) for x in input().split()] for i in range(n)]
cells.sort()
#print(cells)
out = False
res = {True:"WIN",False:"LOSE"}
if len(cells) == 0: print(res[r%2 == 1])
else:
out = False
#print(cells[0][0] > 1)
#print(cells[-1][0] < r)
for i in ra... | vfc_42265 | {
"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": "1 1\n1 2\n",
"output": "LOSE\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "12 2\n4 1\n8 1\n",
"output": "WIN\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 358_C. Dima and Containers | Solve the following coding problem using the programming language python:
Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her pre... | ```python
n = int(input())
r = ['popStack', 'popQueue', 'popFront' ]
r2 = ['pushStack', 'pushQueue', 'pushFront' ]
_ = 0
while _ < n:
x = []
i = 0
while _ < n:
z = int(input())
_ += 1
if z == 0: break
x.append([z, i])
i+=1
if len(x) <= 3:
... | vfc_42269 | {
"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": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0\n",
"output": "0\npushStack\n1 popStack\npushQueue\npushStack\n2 popStack popQueue\npushFront\npushQueue\npushStack\n3 popStack popQueue popFront\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 381_B. Sereja and Stairs | Solve the following coding problem using the programming language python:
Sereja loves integer sequences very much. He especially likes stairs.
Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the following condition is met:
a1 < a2 < ... < ai - 1... | ```python
from sys import stdin,stdout
from math import factorial as f
inp=stdin.readline
op=stdout.write
n=int(inp())
a=list(map(int,inp().split()))
a.sort()
# op(str(a))
if(len(set(a))==n):
op(str(len(a))+"\n")
a=[str(i) for i in a]
op(' '.join(a[::-1])+"\n")
else:
temp=float('inf')
i=0
rev=[]... | vfc_42273 | {
"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\n1 1 2 2 3 3\n",
"output": "5\n1 2 3 2 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "5\n1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 402_A. Nuts | Solve the following coding problem using the programming language python:
You have a nuts and lots of boxes. The boxes have a wonderful feature: if you put x (x ≥ 0) divisors (the spacial bars that can divide a box) to it, you get a box, divided into x + 1 sections.
You are minimalist. Therefore, on the one hand, you... | ```python
from math import ceil
k, a, b, v = map(int, input().split())
res = 0
c = ceil(a / v)
while (b >= k - 1) and (c > 0):
res += 1
c -= k
b -= k - 1
if c > 0:
res += 1
c -= b + 1
if c > 0:
res += c
print(res)
``` | vfc_42277 | {
"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": "100 100 1 1000\n",
"output": "1",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 42_B. Game of chess unfinished | Solve the following coding problem using the programming language python:
Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", — Volodya said and was right for sur... | ```python
import sys
b = 'sabcdefgh'
a1,a2,a3,a4 = map(str,input().split())
x1 = b.index(a1[0])-1
y1 = int(a1[1]) -1
x2 = b.index(a2[0])-1
y2 = int(a2[1]) -1
x3 = b.index(a3[0])-1
y3 = int(a3[1]) -1
x4 = b.index(a4[0])-1
y4 = int(a4[1]) -1
c = []
for i in range(8):
c.append([0]*8)
pr = 0
pr1 = 0
pr4 = 0
pr3 = 0
for... | vfc_42281 | {
"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": "a2 b1 a3 a1\n",
"output": "OTHER\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "a6 b4 c8 a8\n",
"output": "CHECKMATE\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 451_E. Devu and Flowers | Solve the following coding problem using the programming language python:
Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flowers. All flowers in a single box are of the same color (hence they are indistinguishable). Also, no two boxes have flowers of the same c... | vfc_42285 | {
"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 5\n1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 474_D. Flowers | Solve the following coding problem using the programming language python:
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowe... | ```python
#a, b, c, d = [int(x) for x in stdin.readline().split()]
#a, b, c, d = map( int, stdin.readline().split() )
from sys import stdin, stdout
modconst=1000000007
n,k=map(int, stdin.readline().split())
f=[0]*100001
ss=[0]*100001
f[0]=0
for i in range(1,k):
f[i]=1
f[k]=2
for i in range(k+1,100001):
f[i]=(... | vfc_42289 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 3\n2 3\n4 4\n",
"output": "6\n5\n5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n64329 79425\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_na... |
code_contests | verifiable_code | 498_C. Array and Operations | Solve the following coding problem using the programming language python:
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ i... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def matching(n,m,path):
match1 = [-1]*n
match2 = [-1]*m
for node in range(n):
for nei in path[node]:
if match2[nei] == -1:
match1[node] = nei
... | vfc_42293 | {
"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 2\n8 3 8\n1 2\n2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n8 12 8\n1 2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_n... |
code_contests | verifiable_code | 521_D. Shop | Solve the following coding problem using the programming language python:
Vasya plays one very well-known and extremely popular MMORPG game. His game character has k skill; currently the i-th of them equals to ai. Also this game has a common rating table in which the participants are ranked according to the product of... | ```python
def euclid(a, b):
if b == 0:
return (1, 0, a)
else:
(x, y, g) = euclid(b, a%b)
return (y, x - a//b*y, g)
def modDivide(a, b, p):
(x, y, g) = euclid(b, p)
return a // g * (x + p) % p
def comb(n, k):
return modDivide(fac[n], fac[k] * fac[n-k] % P, P)
k, n, m = list(map(int, input().split()))
a = l... | vfc_42297 | {
"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 3\n13 20\n1 1 14\n1 2 30\n2 1 6\n3 2 2\n",
"output": "3\n2 3 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 6 6\n2 2 1 8 5 3 8 5 3 4\n3 8 5\n3 10 1\n3 7 8\n2 3 5\n1 5 1\n3 8 5\n",... |
code_contests | verifiable_code | 549_A. Face Detection | Solve the following coding problem using the programming language python:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular ... | ```python
n, m = [int(i) for i in input().split()]
img = [list(input()) for i in range(n)]
cnt = 0
for i in range(n - 1):
for j in range(m - 1):
arr = [img[i][j], img[i + 1][j], img[i][j + 1], img[i + 1][j + 1]]
if 'f' in arr and 'a' in arr and 'c' in arr and 'e' in arr:
cnt += 1
print(c... | vfc_42301 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\nxx\ncf\nae\nxx\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 575_C. Party | Solve the following coding problem using the programming language python:
Note the unusual memory limit for the problem.
People working in MDCS (Microsoft Development Center Serbia) like partying. They usually go to night clubs on Friday and Saturday.
There are N people working in MDCS and there are N clubs in the c... | vfc_42305 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 4000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n5 8 7 1\n6 9 81 3\n55 78 1 6\n1 1 1 1\n",
"output": "167\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 597_A. Divisibility | Solve the following coding problem using the programming language python:
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1... | ```python
k, a, b = map(int, input().split())
def Do(a, b,):
suma = 0
if a < 0:
if b == 0:
print(-a // k + 1)
if b > 0:
suma = 1
a = -a
if a % k == 0:
if b % k == 0:
suma += b // k + a // k
... | vfc_42309 | {
"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 -4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 10\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 618_C. Constellation | Solve the following coding problem using the programming language python:
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening N... | ```python
f = lambda: list(map(int, input().split()))
d = lambda x, y: (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2
r = lambda x, y, z: (x[0] - y[0]) * (x[1] - z[1]) == (x[1] - y[1]) * (x[0] - z[0])
n = int(input())
t = [f() for i in range(n)]
j = k = -1
b = c = 0
x = t.pop()
for i in range(n - 1):
a = d(x, t[i])
... | vfc_42313 | {
"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\n0 1\n1 0\n1 1\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n0 2\n2 0\n2 2\n1 1\n",
"output": "1 2 5\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 666_C. Codeword | Solve the following coding problem using the programming language python:
The famous sculptor Cicasso is a Reberlandian spy!
These is breaking news in Berlandian papers today. And now the sculptor is hiding. This time you give the shelter to the maestro. You have a protected bunker and you provide it to your friend. ... | vfc_42321 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\na\n2 2\n1 bc\n2 5\n",
"output": " 51\n 162626\n",
"type": "stdin_stdout"
},
{
"fn_na... | |
code_contests | verifiable_code | 690_A2. Collective Mindsets (medium) | Solve the following coding problem using the programming language python:
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in th... | ```python
n = int(input())
if n & 1:
print(n//2)
else:
k = 1
while k <= n:
k *= 2
print((n - k//2)//2)
``` | vfc_42325 | {
"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\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.