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 | 1389_C. Good String | Solve the following coding problem using the programming language python:
Let's call left cyclic shift of some string t_1 t_2 t_3 ... t_{n - 1} t_n as string t_2 t_3 ... t_{n - 1} t_n t_1.
Analogically, let's call right cyclic shift of string t as string t_n t_1 t_2 t_3 ... t_{n - 1}.
Let's say string t is good if i... | ```python
t = int(input())
for i in range(t):
s=input()
ans=0
e=len(s)
qr=0
for j in range(10):
for q in range(10):
b=False
r=0
for i in range(len(s)):
if j!=q:
if (s[i]==str(j)) and (not b):
... | vfc_69277 | {
"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\n95831\n100120013\n252525252525\n",
"output": "3\n5\n0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1430_D. String Deletion | Solve the following coding problem using the programming language python:
You have a string s consisting of n characters. Each character is either 0 or 1.
You can perform operations on the string. Each operation consists of two steps:
1. select an integer i from 1 to the length of the string s, then delete the cha... | ```python
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,i... | vfc_69285 | {
"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\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n",
"output": "3\n1\n1\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6\n111010\n1\n1\n1\n1\n2\n11\n6\n101010\n",
"output": "3\n1... |
code_contests | verifiable_code | 1453_F. Even Harder | Solve the following coding problem using the programming language python:
Gildong is now developing a puzzle game. The puzzle consists of n platforms numbered from 1 to n. The player plays the game as a character that can stand on each platform and the goal of the game is to move the character from the 1-st platform t... | ```python
MAX_N = 3000
inf = MAX_N
def solve():
global inf
n = int(input())
a = [0] + list(map(int, input().split()))
dp = [[0] * (n + 1) for i in range(n + 1)]
for i in range(2, n + 1):
cnt = 0
for j in range(i, n + 1):
dp[i][j] = inf
for j in range(i - 1,... | vfc_69289 | {
"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": "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 2 1 0 2 1 0\n",
"output": "\n0\n3\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 3 1 0 2 1 0\n",
"outp... |
code_contests | verifiable_code | 1477_D. Nezzar and Hidden Permutations | Solve the following coding problem using the programming language python:
Nezzar designs a brand new game "Hidden Permutations" and shares it with his best friend, Nanako.
At the beginning of the game, Nanako and Nezzar both know integers n and m. The game goes in the following way:
* Firstly, Nezzar hides two per... | vfc_69293 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4 2\n1 2\n3 4\n6 4\n1 2\n1 3\n3 5\n3 6\n2 1\n1 2\n",
"output": "\n1 2 3 4\n3 4 1 2\n2 3 4 1 6 5\n1 4 3 2 5 6\n1 2\n1 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 2\n1 2\n3 4\n... | |
code_contests | verifiable_code | 201_C. Fragile Bridges | Solve the following coding problem using the programming language python:
You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum po... | ```python
dpL = [-1 for i in range(100005)]
dpR = [-1 for i in range(100005)]
dpbackL = [-1 for i in range(100005)]
dpbackR = [-1 for i in range(100005)]
global ip
N = input()
ip = map(int,raw_input().split())
x = N-1
for x in range(N-1,-1,-1) :
if (x == N-1) :
dpbackR[x] = 0
continue
if (ip[x] <= 1):
dpbackR[x... | vfc_69313 | {
"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": "5\n2 1 2 1\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 2 3 4 5 6\n",
"output": "19",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
code_contests | verifiable_code | 226_B. Naughty Stone Piles | Solve the following coding problem using the programming language python:
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.
During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and... | ```python
class CodeforcesTask226BSolution:
def __init__(self):
self.result = ''
self.n = 0
self.piles = []
self.q = 0
self.variants = []
def read_input(self):
self.n = int(input())
self.piles = [int(x) for x in input().split(" ")]
self.q = int(in... | vfc_69317 | {
"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\n2 3 4 1 1\n2\n2 3\n",
"output": " 9 8\n",
"type": "stdin_stdout"
},
{
"fn_nam... |
code_contests | verifiable_code | 24_E. Berland collider | Solve the following coding problem using the programming language python:
Recently the construction of Berland collider has been completed. Collider can be represented as a long narrow tunnel that contains n particles. We associate with collider 1-dimensional coordinate system, going from left to right. For each parti... | vfc_69321 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 3\n2 3\n3 3\n4 -3\n5 -1\n6 -100\n",
"output": "0.0291262135922\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-5 9\n0 1\n5 -1\n",
"output": "0.9999999999945\n",
"type"... | |
code_contests | verifiable_code | 275_A. Lights Out | Solve the following coding problem using the programming language python:
Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider... | ```python
matrix=[[1]*3 for i in range(3)]
togg=[[0]*3 for i in range(3)]
for i in range(3):
togg[i]=list(map(int,input().split()))
for i in range(3):
for j in range(3):
if togg[i][j]%2!=0:
matrix[i][j]=int(not matrix[i][j])
if i-1>=0:
matrix[i-1][j]=int(not matr... | vfc_69325 | {
"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": "1 0 0\n0 0 0\n0 0 1\n",
"output": "001\n010\n100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0 1\n8 8 8\n2 0 3\n",
"output": "010\n011\n100\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 298_C. Parity Game | Solve the following coding problem using the programming language python:
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then ... | ```python
a=input()
b=input()
tot1=0
tot2=0
for i in a:
tot1+=int(i)
for i in b:
tot2+=int(i)
if tot1+tot1%2>=tot2:
print("YES")
else:
print("NO")
``` | vfc_69329 | {
"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": "0011\n1110\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "01011\n0110\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 345_F. Superstitions Inspection | Solve the following coding problem using the programming language python:
You read scientific research regarding popularity of most famous superstitions across various countries, and you want to analyze their data. More specifically, you want to know which superstitions are popular in most countries.
The data is give... | vfc_69337 | {
"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": "Ukraine\n* Friday the 13th\n* black cat\n* knock the wood\nUSA\n* wishing well\n* friday the 13th\nHolland\nFrance\n* Wishing Well\n",
"output": "friday the 13th \nwishing well \n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 391_C2. The Tournament | Solve the following coding problem using the programming language python:
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.
Manao decided to pursue a fighter's c... | ```python
m = 301000
ns = [0] * m
es = [0] * m
c = [0] * m
b = [0] * m
t = [0] * m
P = 0
def add(b, k):
k = t[k]
while k:
e = es[k]
if b[-1] > e: b[-1] = e
b[e] += 1
k = ns[k]
def delete(b):
for i in range(b[m - 1], m + 1):
if b[i]:
b[i] -= 1
b[-... | vfc_69345 | {
"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 2\n1 1\n1 4\n2 2\n",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 413_C. Jeopardy! | Solve the following coding problem using the programming language python:
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and ... | ```python
n, m = tuple(map(int, str.split(input())))
a = tuple(map(int, str.split(input())))
mi = tuple(map(int, str.split(input())))
ms = sorted(map(lambda i: a[i - 1], mi), reverse=True)
points = 0
for i, ai in enumerate(a):
if i + 1 not in mi:
points += ai
for m in ms:
if m > points:
po... | vfc_69349 | {
"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": "4 1\n1 3 7 5\n3\n",
"output": " 18",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n100 200\n1 2\n",
"output": " ... |
code_contests | verifiable_code | 43_E. Race | Solve the following coding problem using the programming language python:
Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For ever... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, s = map(int, input().split())
data = [dict() for _ in range(n)]
for i in range(n):
k, *a = map(int, input().split())
cur = 0
for j in range(0, 2 * k, 2):
data[i][cur... | vfc_69353 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5\n",
"output": " 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2... |
code_contests | verifiable_code | 462_B. Appleman and Card Game | Solve the following coding problem using the programming language python:
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you shou... | ```python
n,k=map(int,input().split())
s=input()
di=dict()
for i in s:di[i]=di.get(i,0)+1
ans=0
se=list(set(s))
se.sort(key=lambda x:di[x],reverse=1)
for i in se:
ans+=min(k,di[i])*min(di[i],k)
k-=min(di[i],k)
if not k:break
print(ans)
``` | vfc_69357 | {
"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 4\nYJSNPI\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 486_A. Calculating Function | Solve the following coding problem using the programming language python:
For a positive integer n let's define a function f:
f(n) = - 1 + 2 - 3 + .. + ( - 1)nn
Your task is to calculate f(n) for a given integer n.
Input
The single line contains the positive integer n (1 ≤ n ≤ 1015).
Output
Print f(n) in a singl... | ```python
if __name__=="__main__":
n=int(input())
if(n&1):
print(-1*(n+1)//2)
else:
print(n//2)
``` | vfc_69361 | {
"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": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "-3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "29906716\n... |
code_contests | verifiable_code | 534_B. Covered Path | Solve the following coding problem using the programming language python:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2 meters per second. We know that this section of the route took exactly t second... | ```python
from collections import Counter,defaultdict,deque
import heapq as hq
from itertools import count, islice
#alph = 'abcdefghijklmnopqrstuvwxyz'
#from math import factorial as fact
import math
import sys
input=sys.stdin.readline
#print=sys.stdout.write
#tt = int(input())
#total=0
#n = int(input())
#n,m,k = [int... | vfc_69369 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 10\n10 0\n",
"output": "100\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 559_B. Equivalent Strings | Solve the following coding problem using the programming language python:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:
1. They are equal.
2. If we split string a into two halves of the s... | ```python
def equal(s):
if len(s)%2==1 : return s
m = len(s)//2
a=equal(s[:m])
b=equal(s[m:])
return a+b if a<b else b+a
print("YES" if equal(input())==equal(input()) else 'NO')
``` | vfc_69373 | {
"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": "aabb\nabab\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 584_E. Anton and Ira | Solve the following coding problem using the programming language python:
Anton loves transforming one permutation into another one by swapping elements for money, and Ira doesn't like paying for stupid games. Help them obtain the required permutation by paying as little money as possible.
More formally, we have two ... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = {}
for i in range(n):
c[b[i]] = i
b = []
for i in range(n):
a[i] = c[a[i]]
print(sum(abs(a[i] - i) for i in range(n)) >> 1)
while True:
for i in range(n):
if a[i] < i:
for j in range(a[... | vfc_69377 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 2 1 3\n3 2 4 1\n",
"output": "3 2 \n3 4\n1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n2 1\n",
"output": "1 1 \n1 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 628_E. Zbazi in Zeydabad | Solve the following coding problem using the programming language python:
A tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).
The country Zeydabad is a rectangular table consisting of n rows and m columns. Each cell on the country is either 'z' or '.'.
The tourist knows this country is na... | ```python
#!/usr/bin/env python3
from __future__ import division, print_function
def least_significant_bit(i):
return ((i) & -(i))
class FenwickTree():
def __init__(self, n):
# 1-indexed
self.n = n + 1
self.data = [0,] * self.n
def add(self, index, value):
# 1-indexe... | vfc_69385 | {
"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": "4 4\nzzzz\nzzz.\n.z..\nzzzz\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 4\nz.z.\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
code_contests | verifiable_code | 652_F. Ants on a Circle | Solve the following coding problem using the programming language python:
n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counter... | vfc_69389 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 8 6\n6 R\n5 L\n1 R\n8 L\n",
"output": "7 4 2 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 8 2\n1 R\n5 L\n6 L\n8 R\n",
"output": "3 3 4 2\n",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 678_D. Iterated Linear Function | Solve the following coding problem using the programming language python:
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n ... | ```python
import sys
import bisect
from bisect import bisect_left as lb
input_=lambda: sys.stdin.readline().strip("\r\n")
from math import log
from math import gcd
from math import atan2,acos
from random import randint
sa=lambda :input_()
sb=lambda:int(input_())
sc=lambda:input_().split()
sd=lambda:list(map(int,input_(... | vfc_69393 | {
"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 4 1 1\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 700_D. Huffman Coding on Segment | Solve the following coding problem using the programming language python:
Alice wants to send an important message to Bob. Message a = (a1, ..., an) is a sequence of positive integers (characters).
To compress the message Alice wants to use binary Huffman coding. We recall that binary Huffman code, or binary prefix c... | vfc_69397 | {
"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": "7\n1 2 1 3 1 2 1\n5\n1 7\n1 3\n3 5\n2 4\n4 4\n",
"output": "10\n3\n3\n5\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 3 5 1 4\n15\n3 5\n1 1\n4 4\n3 4\n1 3\n4 5\n5 5\n1 4\n3 3\n2 ... | |
code_contests | verifiable_code | 722_F. Cyclic Cipher | Solve the following coding problem using the programming language python:
You are given n sequences. Each sequence consists of positive integers, not exceeding m. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the i-th sequence is ki.
Each second intege... | vfc_69401 | {
"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 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3\n",
"output": "3\n1\n4\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4\n",
"output": "2\n1\n3\n2\n... | |
code_contests | verifiable_code | 768_A. Oath of the Night's Watch | Solve the following coding problem using the programming language python:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the... | ```python
nb_steward = int(input())
strengths = [int(x) for x in input().split()]
mins = strengths.count(min(strengths))
maxs = strengths.count(max(strengths))
print(max(0, nb_steward - mins - maxs))
``` | vfc_69409 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 791_E. Bear and Company | Solve the following coding problem using the programming language python:
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he ... | ```python
# http://codeforces.com/contest/771/problem/D
"""
DP-solution.
For each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x
axes and check that
dp[future_state] = min(dp[future_state], dp[state] + cost_of_move)
Hence this implicitly reults in the one with least cost.
V, K, X are arrays th... | vfc_69413 | {
"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\nLIMAK\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\nVKVKVVVKVOVKVQKKKVVK\n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 812_B. Sagheer, the Hausmeister | Solve the following coding problem using the programming language python:
Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.
Th... | ```python
n, m = list(map(int, input().split()))
m += 2
l = []
do = False
for i in range(n):
s = input().strip()
if s.find('1') != -1 or do:
do = True
l.append(s)
n = len(l)
if n == 0:
print(0)
exit()
dp = []
for i in range(n):
dp.append([None] * 2)
for i in range(n):
R = 0
for j in range(m):
if l[i][j]... | vfc_69417 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n001000\n000010\n000010\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n0010\n0100\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn... |
code_contests | verifiable_code | 838_B. Diverging Directions | Solve the following coding problem using the programming language python:
You are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2n - 2. The graph's edges can be split into two parts.
* The first n - 1 edges will form a rooted ... | vfc_69421 | {
"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": "5 9\n1 3 1\n3 2 2\n1 4 3\n3 5 4\n5 1 5\n3 1 6\n2 1 7\n4 1 8\n2 1 1\n2 1 3\n2 3 5\n2 5 2\n1 1 100\n2 1 3\n1 8 30\n2 4 2\n2 2 4\n",
"output": "0\n1\n4\n8\n100\n132\n10\n",
"type": "stdin_stdout"
},
{
"fn_nam... | |
code_contests | verifiable_code | 858_E. Tests Renumeration | Solve the following coding problem using the programming language python:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the fi... | ```python
import random
def genTemp():
sl = ""
firstTime = True
while firstTime or sl in pre or sl in post:
sl = ""
firstTime = False
for i in range(6):
sl += chr(random.randint(ord("a"), ord("z")))
return sl
n = int(input())
e = 0
pre = set()
post = set()
for i in... | vfc_69425 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n",
"output": "5\nmove 1 3\nmove 11 1\nmove 111 4\nmove 1111 2\nmove 11111 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 0\n2 1\n",
"out... |
code_contests | verifiable_code | 883_K. Road Widening | Solve the following coding problem using the programming language python:
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!
The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Mor... | ```python
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
s = []
g = []
forwardBound = []
backwardBound = []
for _ in range(n):
sCur,gCur = map(int,input().split())
s.append(sCur)
g.append(gCur)
forwardBound.append(s[0] + g[0])
for i in range(1,n):
if forwardB... | vfc_69429 | {
"difficulty": "17",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 100\n100 1\n1 100\n100 1\n",
"output": "202\n101 101 101 101 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1\n100 100\n1 1\n",
"output": "-1\n",
"type": "stdin_std... |
code_contests | verifiable_code | 907_F. Power Tower | Solve the following coding problem using the programming language python:
Priests of the Quetzalcoatl cult want to build a tower to represent a power of their god. Tower is usually made of power-charged rocks. It is built with the help of rare magic by levitating the current top of tower and adding rocks at its bottom... | vfc_69433 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1000000000\n1 2 2 3 3 3\n8\n1 1\n1 6\n2 2\n2 3\n2 4\n4 4\n4 5\n4 6\n",
"output": "1\n1\n2\n4\n256\n3\n27\n597484987\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 1\n688064407 427303... | |
code_contests | verifiable_code | 928_C. Dependency management | Solve the following coding problem using the programming language python:
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity.
A project in Vaja has its... | ```python
def scan_project():
name, version_str = input().split()
return (name, int(version_str))
n = int(input())
projects, depends = [], {}
for i in range(n):
if i > 0:
input()
project = scan_project()
projects.append(project)
depends[project] = [scan_project() for j in range(int(inpu... | vfc_69437 | {
"difficulty": "9",
"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\nabc 1\n2\nabc 3\ncba 2\n\nabc 3\n0\n\ncba 2\n0\n",
"output": "1\ncba 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n \ncommons 2\... |
code_contests | verifiable_code | 957_E. Contact ATC | Solve the following coding problem using the programming language python:
Arkady the air traffic controller is now working with n planes in the air. All planes move along a straight coordinate axis with Arkady's station being at point 0 on it. The i-th plane, small enough to be represented by a point, currently has a ... | vfc_69441 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n-3 2\n-2 2\n-1 2\n1 -2\n2 -2\n3 -2\n",
"output": " 9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1\n-3 2\n-3 3\n-1 ... | |
code_contests | verifiable_code | 982_E. Billiard | Solve the following coding problem using the programming language python:
Consider a [billiard table](https://en.wikipedia.org/wiki/Billiard_table) of rectangular size n × m with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture).
<image>
There is one ball a... | ```python
from functools import reduce
import math
def bezout(a, b):
if a == 0:
return (0, 1)
else:
x, y = bezout(b % a, a)
return y - (b//a) * x, x
def lcm(a, b):
return abs(a*b) // math.gcd(a, b)
def CRT(a1, m1, a2, m2):
g = math.gcd(m1, m2)
if (a1-a2) % g != 0:
... | vfc_69445 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 2 0 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | a-game-for-soft-drinks | Solve the following coding problem using the programming language python:
Ashima's mid term exams are just over. Since, its raining heavily outside, she can't go shopping.
So, she and her best friend Aishwarya have now decided to chill out by eating pizza, chocolates, biscuits, etc.. and playing some indoor games.
The... | ```python
t = input()
for x in range(0,t):
a ,b ,c = map(int,raw_input().split())
if int(a)%2!= 0:
print "Ashima"
elif int(b)%2!=0:
print "Ashima"
elif int(c)%2!=0:
print "Ashima"
else:
print "Aishwarya"
``` | vfc_69449 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 1\n2 2 0\n2 1 1\n\nSAMPLE",
"output": "Ashima\nAishwarya\nAshima\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1272\n4 65 35\n5 47 2\n0 59 20\n2 41 14\n2 30 17\n2 26 22\n3 44 6\n4... |
code_contests | verifiable_code | bio-4 | Solve the following coding problem using the programming language python:
Ben was playing with the Omnitrix in free time. He screwed up once again. Not knowing what he was doing, he accessed the DNA analysis and modification subroutine of the watch and accidentally manipulated the DNA of an alien.
While fighting wit... | ```python
T = int(input())
for t in range(T):
A1 = raw_input()
A2 = raw_input()
l1 = len(A1)
l2 = len(A2)
maximum = 0
for offset in range(l1-l2+1):
#print "offset =", offset
counter = 0
for i in range(l2):
#print "i =", i
if A1[i+offset]==A2[i]:
#print "comparing", A1[i+offset], A2[i]
counter+... | vfc_69453 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nABCDEFZQT\nBPFZQ\nATTCG\nATTCK\n\nSAMPLE",
"output": "2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nMBNMVBDSJFHDFJDHFAKFHAKLFHFLKFURIFRFRYGRIFDYFIDFHYAIFAHFIAHFAIFHAFAKFGAFLJGAF... |
code_contests | verifiable_code | crack-the-code | Solve the following coding problem using the programming language python:
Rufus wants to go to the Lily's birthday party to surprise Lily. But Lily's party invitation has a unique code on it which is in the form X-Y(e.g. 123-456). So Rufus need a invitation but he fails to get the invitation.
So he decided to make a ... | ```python
f=[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025]
for i in xrange(input()):
a,b=map(int,raw_input().split())
c=0
for i in f:
if a<=i<=b:c+=1
if c&1:print("INVALID")
else:print("VALID")
``` | vfc_69457 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 10\n2 8\n\nSAMPLE",
"output": "INVALID\nVALID\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 10\n1 8\n\nSAMPLE",
"output": "INVALID\nVALID\n",
"type": "stdin_stdout"... |
code_contests | verifiable_code | fixing-of-file | Solve the following coding problem using the programming language python:
On Unix computers, data is stored in directories. There is one root directory, and this might have several directories contained inside of it, each with different names. These directories might have even more directories contained inside of them... | ```python
t = input()
mkdir_a = []
for i in range(t):
paths = dict()
temp = []
inp = raw_input()
inp = inp.split()
for j in range(int(inp[0])):
temp = raw_input()
folder = []
c = 0
parent = 0
par = ""
path =""
while c != len(temp):
if temp[c] == '/' or (c + 1) == len(temp):
if parent ==... | vfc_69461 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0 2\n/home/gcj/finals\n/home/gcj/quals\n2 1\n/chicken\n/chicken/egg\n/chicken\n\nSAMPLE",
"output": "Case #1: 4\nCase #2: 0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n0 2\n/home/g... |
code_contests | verifiable_code | jacks-dilemma | Solve the following coding problem using the programming language python:
Jack stays in a n-storey hostel. His dorm room is on the jth floor. Every morning, he is in so much hurry for classes that he cannot not decide whether to take Lift or Stairs to reach ground-floor. He asks you to help him choose either Stairs or... | ```python
import os
import sys
import random
import math
def main():
t=int(raw_input())
for i in range(t):
inp=str(raw_input()).split(" ")
n=int(inp[0])
j=int(inp[1])
l=int(inp[2])
if inp[3]=="U":
stairst=j*10
if l==n and j==n:
liftt=10+n*5+10;
elif l>j:
liftt=(n-l)*5+10+(n-j)*5+10+j*5+10;... | vfc_69465 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n30 10 20 U\n10 10 10 U\n80 60 60 D\n\nSAMPLE",
"output": "Stairs 100\nLift 70\nLift 320",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "32\n10 5 5 U\n10 5 5 D\n10 3 3 D\n10 9 9 U\n10 10 1... |
code_contests | verifiable_code | micro-and-block-game-3 | Solve the following coding problem using the programming language python:
Micro's midsem exams are finally over. When they were going on, instead of studying he would spend time making list of things that he wanted to do after the exams. But, now when they are over, he has lost the list. He was feeling very low, so hi... | ```python
Size=int(raw_input())
N=map(str,raw_input().split())
#print N
def comp(x,y):
return int(x+y) - int(y+x)
L=sorted(N,reverse=True,cmp=comp)
ans=''
for i in L:
ans+=i
print ans
``` | vfc_69469 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n12 2 3\n\nSAMPLE",
"output": "3212",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p-4 | Solve the following coding problem using the programming language python:
Ramesh and Suresh are now given One Last Task, to distribute tickets to all the students as their admissions are finalized. Sounds simple, but there's one twist, they are supposed to give 1 ticket to the first student, 2 tickets to the second st... | ```python
for _ in xrange(input()):
n=input()
if n==100000000:
print "987459712"
continue
t=(n*(n+1))
t//=2
print t
``` | vfc_69473 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n\nSAMPLE",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n... |
code_contests | verifiable_code | recursion | Solve the following coding problem using the programming language python:
Problem :
Bajirao asks Avni out on a date. However, Avni will go out with him only on one condition :
Bajirao has to tell her all possible N - digit numbers such that all the digits of every number he tells her are distinct , non-zero and l... | ```python
t=int(raw_input());
import itertools;
while t!=0:
t-=1;
n=int(raw_input());
l=[i for i in range(1,n+1)];
l=list(itertools.permutations(l));
for i in l:
s='';
for j in i:
s+=str(j);
print s,
print
``` | vfc_69477 | {
"difficulty": "0",
"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\n\nSAMPLE",
"output": "1 \n12 21 \n123 132 213 231 312 321 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n3\n\nELPMAS",
"output": "1\n12 21\n123 132 213 231 312... |
code_contests | verifiable_code | softsort-7 | Solve the following coding problem using the programming language python:
Let us define an easy Sorting Algorithm called SoftSort. SoftSort Sorting algorithm involves use of IF and ELSE decision statements only. For example :
To sort two numbers a and b. SoftSort Algorithm's Code is given below.
void print(int a,i... | ```python
dic = {0:1}
i=1
while i<10**6+1:
dic[i] = (i*dic[i-1])%(10**9 + 7)
i += 1
x = int(raw_input())
for elem in range(x):
y = int(raw_input())
n = (3*dic[y] + 3) % (10**9 + 7)
print n
``` | vfc_69481 | {
"difficulty": "0",
"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\n\nSAMPLE",
"output": "6\n9\n21\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1\n2\n3\n\nSALPME",
"output": "6\n9\n21\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | times-pal-1 | Solve the following coding problem using the programming language python:
A palindrome is a string that is the same whether it is read from left to right or from right to left. Chota Bheem likes palindromes a lot. As a birthday gift he received two strings A and B. Now he is curious if there is a way to insert string ... | ```python
'''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = long(raw_input());
while ( t ):
a= raw_input();
b= raw_input();
c = 0L;
s= a+b;
if ( s == s[::-1] ):
c+=1;
for i in range (0,len(a)) :
s = a[0:i]+b+a[i:];
... | vfc_69485 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\naba\nb\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\nabb\nb\n\nSAMPLE",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00115 Starship UAZ Advance | Solve the following coding problem using the programming language python:
Stellar history 2005.11.5. You are about to engage an enemy spacecraft as the captain of the UAZ Advance spacecraft. Fortunately, the enemy spaceship is still unnoticed. In addition, the space coordinates of the enemy are already known, and the ... | ```python
# -*- coding: utf-8 -*-
import sys
import os
import math
import random
# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/
def det(a, b, c):
return + a[0] * b[1] * c[2] \
+ a[2] * b[0] * c[1] \
+ a[1] * b[2] * c[0] \
- a[2] * b[1] * c[0] \
... | vfc_69533 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-10 6 6\n10 6 6\n0 10 0\n0 10 10\n0 0 10",
"output": "MISS",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-10 0 0\n10 0 0\n0 10 0\n0 10 10\n0 0 10",
"output": "HIT",
"type": "st... |
code_contests | verifiable_code | p00429 String | Solve the following coding problem using the programming language python:
Given a string consisting of only numbers from 0 to 9, consider the operation of creating a new string from that string according to the following rules. Read the given string one character at a time from the left end. Go, if the same number a c... | ```python
def change(x) :
i = 0
ans = []
while True :
if i >= len(x) : break
cnt = 1
j = 1
while True :
if i+j >= len(x) or x[i+j] != x[i] :
ans = ans + list(str(cnt))
ans.append(x[i])
i += cnt
break
... | vfc_69541 | {
"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\n11\n5\n11\n0",
"output": "13112221\n13112221",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n11\n5\n21\n0",
"output": "13112221\n1113213211\n",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | p00625 Frisbee Dogs | Solve the following coding problem using the programming language python:
Klein is trying to get her dog Jack into the Frisbee Dog Tournament. But she's not sure if Jack will get a good grade. For her, she simulates the tournament to get Jack's grade. I want you to create a program to estimate.
The tournament is held... | vfc_69545 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n12 5 3\n0 17 3\n0 0 2 2\n2 3\n2 0 2\n100 100 2\n0 0 -1 0\n-2 -5 0 3\n100 100 1 1\n0 0",
"output": "1 0\n2 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n12 5 1\n0 17 3\n0 0 2 2\... | |
code_contests | verifiable_code | p00769 Hierarchical Democracy | Solve the following coding problem using the programming language python:
Hierarchical Democracy
The presidential election in Republic of Democratia is carried out through multiple stages as follows.
1. There are exactly two presidential candidates.
2. At the first stage, eligible voters go to the polls of his/her e... | ```python
N = int(input())
def rec ():
global now,l
if s[now].isdigit():
res = 0
while (now < l and s[now].isdigit()):
res = ((10 * res) + int(s[now]))
now += 1
return (res+1)//2
else:
g = []
while(now < l and s[now] == '['):
now += 1
g.append(rec())
now += 1
g.sort()
return sum(g[:(len(... | vfc_69549 | {
"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\n[[123][4567][89]]\n[[5][3][7][3][9]]\n[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]\n[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]\n[[[[9][... |
code_contests | verifiable_code | p00900 Captain Q's Treasure | Solve the following coding problem using the programming language python:
You got an old map, which turned out to be drawn by the infamous pirate "Captain Q". It shows the locations of a lot of treasure chests buried in an island.
The map is divided into square sections, each of which has a digit on it or has no digi... | vfc_69553 | {
"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": "5 6\n*2.2**\n..*...\n..2...\n..*...\n*2.2**\n6 5\n.*2*.\n..*..\n..*..\n..2..\n..*..\n.*2*.\n5 6\n.1111.\n**...*\n33....\n**...0\n.*2**.\n6 9\n....1....\n...1.1...\n....1....\n.1..*..1.\n1.1***1.1\n.1..*..1.\n9 9\n*********\n*4*4*4*... | |
code_contests | verifiable_code | p01166 So Sleepy | Solve the following coding problem using the programming language python:
You have an appointment to meet a friend of yours today, but you are so sleepy because you didn’t sleep well last night.
As you will go by trains to the station for the rendezvous, you can have a sleep on a train. You can start to sleep as soon... | vfc_69561 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n1 09:00 3 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3 2\n1 09:00 1 10:00\n3\n1 09:10\n2 09:30\n3 09:40\n3\n3 09:20\n2 09:30\n1 10:00\n1 0\n1 09:00 1 10:00\n1 0\n1 10:00 1 09:00\n3 1\n1 09:00 3 09:35\n3\n1 09:10\n2 09:30\n3 09:40\n4... | |
code_contests | verifiable_code | p01303 Petting Cats | Solve the following coding problem using the programming language python:
Many cats live on the campus of a school. Natsume's daily routine is to pet those cats. However, the cats may be capricious and go for a walk off campus.
The campus site is a rectangle with each side parallel to the x-axis or y-axis and is surr... | ```python
for _ in range(int(input())):
x, y, w, h = map(int,input().split())
c = 0
for _ in range(int(input())):
a, b = map(int,input().split())
if x <= a and a <= x + w and y <= b and b <= y + h:c += 1
print(c)
``` | vfc_69565 | {
"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\n1 3 20 10\n4\n21 13\n1 15\n10 10\n25 10\n1 3 20 10\n4\n21 13\n1 15\n10 10\n25 10",
"output": "2\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 3 20 10\n4\n21 13\n1 15\n10 10\n41 ... |
code_contests | verifiable_code | p01472 Game | Solve the following coding problem using the programming language python:
Problem statement
Two players are playing the game. The rules of the game will be described below.
There is a board of $ N × N $ squares, and each square has the number $ X_ {i, j} $ ($ 1 \ leq i, j \ leq N $) written on it. The first move and... | vfc_69569 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5\n3 4\n7 6",
"output": "Draw\n4",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01784 Parentheses | Solve the following coding problem using the programming language python:
Example
Input
3
()(()((
))()()(()
)())(())
Output
Yes
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
def solve():
N = int(input())
T0 = []
T1 = []
su = 0
for i in range(N):
s = input()
a = 0
for c in s:
if c == '(':
a += 1
elif a > 0:
a -= 1
b = 0
for c in reversed(s):
if c == ')':
... | vfc_69577 | {
"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": "3\n()(()((\n))()()(()\n)())(())",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n()(()((\n))()(((()\n)())(())",
"output": "No\n",
"type": "stdin_stdout"
},... |
code_contests | verifiable_code | p01919 Country in Distortion | Solve the following coding problem using the programming language python:
D: Country In Distortion-
story
Alice was completely bored. This is because the White Rabbit, who is always playing with him, is out to Trump Castle. (Ah, I wish I had gone out with him in this case.) Alice thought. However, this is a country ... | ```python
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
inf = float('inf')
n,m = map(int,input().split())
pathT = [{} for _ in range(n)]
for i in range(m):
x,y,t = map(int,input().split())
x -= 1
y -= 1
pathT[x][y] = t
pathT[y][x] = t
import heapq
def Dijkstra(edge,start):
... | vfc_69581 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 267386880,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 2 3\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 6",
"output": "34",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 3 3\n2 3 1\n2 4 5\n3 4 2\n5\n4 5 6",
"output": "38\n",
"type": "s... |
code_contests | verifiable_code | p02057 MOD Rush | Solve the following coding problem using the programming language python:
F: MOD Rush
problem
Given a positive integer sequence A of length N and a positive integer sequence B of length M.
For all (i, j) (1 \ leq i \ leq N, 1 \ leq j \ leq M), find the remainder of A_i divided by B_j and output the sum of them.
In... | ```python
from collections import Counter
from itertools import accumulate
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = max(A)
table = [0]*(K+1)
table[0] = M
for b, v in Counter(B).items():
for j in range(b, K+1, b):
table[j] -= b*v
for j... | vfc_69585 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n5 1 6\n2 3 4",
"output": "9",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p02353 RSQ and RUQ | Solve the following coding problem using the programming language python:
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:
* $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.
* $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.
Note that ... | ```python
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def set_depth(depth):
global DEPTH, SEGTREE_SIZE, NONLEAF_SIZE
DEPTH = depth
SEGTREE_... | vfc_69593 | {
"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": "6 7\n0 1 3 1\n0 2 4 -2\n1 0 5\n1 0 1\n0 3 5 3\n1 3 4\n1 0 5",
"output": "-5\n1\n6\n8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 7\n0 1 3 1\n0 2 4 -2\n1 0 4\n1 0 1\n0 3 5 3\n1 3 4\n1 0... |
code_contests | verifiable_code | and | Solve the following coding problem using the programming language python:
You are given a sequence of N integer numbers A. Calculate the sum of Ai AND Aj for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined as in here.
Input
The first line of input consists of the integer N... | ```python
import fileinput
import math
foundN = False
for line in fileinput.input():
if not foundN:
N = int(line)
foundN = True
continue
number_list = map(int, line.split())
bit_count = [0]*31
for number in number_list:
for i in range(31):
if numbe... | vfc_69597 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5",
"output": "9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chocolat | Solve the following coding problem using the programming language python:
Balajiganapathi and Bipin are brothers. They have saved their money to buy Dairy Milk for their respective girlfriend on this Valentine's day. Balaji managed to buy M chocolates and Bipin managed to buy N chocolates.
They have made a bet as if... | ```python
t=int(raw_input())
for i in range(t):
n,m=map(int,raw_input().split())
if m>n:
print "Balaji",m-n
elif n>m:
print "Bipin",n-m
else:
print "No Winner"
``` | vfc_69601 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 6\n8 1",
"output": "Balaji 2\nBipin 7",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | epi02 | Solve the following coding problem using the programming language python:
Once upon a time, a king and a few of his soldiers were caught by an enemy king in a war.
He puts them in a circle. The first man in the circle has to kill the second man, the third man has to kill the fourth, fifth man to kill the sixth and ... | ```python
N,i=input(),1;
while i<=N:
i*=2;
i/=2; print 1+2*(N-i);
``` | vfc_69605 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9",
"output": "3",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | kjcc07 | Solve the following coding problem using the programming language python:
Chef is known to have friends as well as enemies. Chef has a habit of communicating with friends through encrypted messages. But recently some of his enemies found the way to decrypt and get the original message. You need to write a program that... | ```python
def findOccurences(s, ch):
return [i for i, letter in enumerate(s) if letter == ch]
def fibo(n):
a=0
b=1
fibon=[0,1]
while(b<n):
c=a+b
fibon.append(c)
a=b
b=c
return fibon
n=int(raw_input())
i=0
stri=[]
singlelist=[]
finalsingle=[]
alphabet=['a','b','... | vfc_69609 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nazfjybgbxnpyatfgcaxqylbxd\ngzbbbgaxnfatxqdjfaypgcyafl\nyjbfpcygxlgznyfbgxtqgxydaaa\nxxyyxxyyxdlbqffctpbngggjz\ncbkumuwlwkmtt_zwksa!!",
"output": "kjscecodecell_rocks!!",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | packband | Solve the following coding problem using the programming language python:
Did you know that the yummy golden triangle was introduced in India as early as 13th century ? By the way, I'm referring to the popular South Asian snack, Samosa. I guess its hard to code while thinking of Samosa, especially if you are very hung... | ```python
import sys
from operator import itemgetter
num_tests = int(sys.stdin.readline())
def search(bands, box, lo, hi):
if lo == hi:
return None
mid = lo + (hi - lo) / 2
band = bands[mid][1]
if not mid:
return mid
if bands[mid - 1][1] < box and band >= box:
return mi... | vfc_69613 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4\n10 20 34 55\n4\n7 14\n7 21\n14 21\n7 35",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1006_D. Two Strings Swaps | Solve the following coding problem using the programming language python:
You are given two strings a and b consisting of lowercase English letters, both of length n. The characters of both strings have indices from 1 to n, inclusive.
You are allowed to do the following changes:
* Choose any index i (1 ≤ i ≤ n) ... | ```python
n = int(input())
a = input()
b = input()
l = 0; r = n-1; ans = 0
while l < r:
x1 = a[l]; x2 = a[r]
y1 = b[l]; y2 = b[r]
if (x1 == y1 and x2 == y2) or (x1 == y2 and x2 == y1) or (x1 == x2 and y1 == y2):
ans += 0
elif (x1 == y1 or x2 == y2) or (x1 == y2 or x2 == y1) or (y1 == y2):
... | vfc_69621 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nabacaba\nbacabaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\nzcabd\ndbacz\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 102_C. Homework | Solve the following coding problem using the programming language python:
Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains ar... | ```python
import itertools
import math
import time
def timer(f):
def tmp(*args, **kwargs):
t = time.time()
res = f(*args, **kwargs)
print("Время выполнения функции: %f" % (time.time()-t))
return res
return tmp
#n = int(input())
s = input()
n = int(input())
array = [[0, chr(i... | vfc_69625 | {
"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": "abcdefgh\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaa\n4\n",
"output": "1\naaaaa",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1051_C. Vasya and Multisets | Solve the following coding problem using the programming language python:
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into... | ```python
n = int(input())
s = list(map(int, input().split()))
d = {}
mt = False
mti = -1
for i in range(len(s)):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
if d[s[i]] > 2:
mt = True
mti = i
good = []
for i in d.keys():
if d[i] == 1:
good.append(... | vfc_69629 | {
"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": "4\n3 5 7 1\n",
"output": "YES\nABAB",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 5 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1073_D. Berland Fair | Solve the following coding problem using the programming language python:
XXI Berland Annual Fair is coming really soon! Traditionally fair consists of n booths, arranged in a circle. The booths are numbered 1 through n clockwise with n being adjacent to 1. The i-th booths sells some candies for the price of a_i burle... | ```python
from sys import stdin
input = stdin.readline
n, t = map(int, input().split())
lst = list(map(int, input().split()))
s = sum(lst)
x = min(lst)
candy = n * (t // s)
t -= s * (t // s)
while t >= x:
s, c = 0, 0
for i in lst:
if i <= t - s:
c += 1
s += i
candy += c * (... | vfc_69633 | {
"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 38\n5 2 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 21\n2 4 100 2 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 1095_D. Circular Dance | Solve the following coding problem using the programming language python:
There are n kids, numbered from 1 to n, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as p_1, p_2, ..., p_n (all these numbers are from 1 to n and are distinct, so p is a permutation). Let the next ... | ```python
n = int(input())
p = [(None, None)]
for _ in range(n):
p.append(list(map(int, input().split())))
if n==3:
print("1 2 3")
else:
for idx, (a, b) in enumerate(p[1:], 1):
if a in p[b]:
p[idx] = [b]
elif b in p[a]:
p[idx] = [a]
return_val = [p[1][0]]
n-=1
while n:
return_val.append(p[r... | vfc_69637 | {
"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\n3 5\n1 4\n2 4\n1 5\n2 3\n",
"output": "1 5 3 2 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3\n3 1\n1 2\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 1114_E. Arithmetic Progression | Solve the following coding problem using the programming language python:
This is an interactive problem!
An arithmetic progression or arithmetic sequence is a sequence of integers such that the subtraction of element with its previous element (x_i - x_{i - 1}, where i ≥ 2) is constant — such difference is called a c... | vfc_69641 | {
"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\n\n0\n\n1\n\n14\n\n24\n\n9\n\n19\n\n",
"output": "? 1\n? 2\n? 3\n? 4\n! 0 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n999999999 1000000000\n",
"output": "? 1\n? 2\n! 99999... | |
code_contests | verifiable_code | 1143_A. The Doors | Solve the following coding problem using the programming language python:
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then o... | ```python
def the_doors(arr,n):
count_1 = 0
count_0 = 0
for i in arr:
if i == 0:count_0 += 1
else:count_1 += 1
check_1 = 0
check_0 = 0
for i in range(n):
if arr[i] == 0:
check_0 += 1
else:
check_1 += 1
if count_0 == check_0:
... | vfc_69645 | {
"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 0 0 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0 1 0 0\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1163_B1. Cat Party (Easy Edition) | Solve the following coding problem using the programming language python:
This problem is same as the next one, but has smaller constraints.
Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one f... | ```python
'''input
5
10 2 5 4 1
'''
n = int(input())
arr = list(map(int,input().split()))
count = [0]*10
ans = 1
for i in range(n):
count[arr[i]-1]+=1
cp_count = list.copy(count)
cp_count.sort()
r =0
for j in range(1,10):
if cp_count[j]!=cp_count[j-1]:
r+=1
if (r==0 and cp_count[0]==1):
ans = i+1
elif (r=... | vfc_69649 | {
"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 1 2 2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n3 2 1 1 4 5 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1183_G. Candy Box (hard version) | Solve the following coding problem using the programming language python:
This problem is a version of problem D from the same contest with some additional constraints and tasks.
There are n candies in a candy box. The type of the i-th candy is a_i (1 ≤ a_i ≤ n).
You have to prepare a gift using some of these candi... | ```python
from collections import defaultdict
from sys import stdin, stdout
q = int(stdin.readline())
for it in range(q):
n = int(stdin.readline())
d = [0]*n
f = [0]*n
for i in range(n):
t, b = map(int, stdin.readline().split())
d[t-1]+=1
if b == 1:
f[t-1] += 1
... | vfc_69653 | {
"difficulty": "13",
"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\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n",
"output": "3 3\n3 3\n9 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 1219_A. BubbleReactor | Solve the following coding problem using the programming language python:
You are in charge of the BubbleReactor. It consists of N BubbleCores connected with N lines of electrical wiring. Each electrical wiring connects two distinct BubbleCores. There are no BubbleCores connected with more than one line of electrical ... | vfc_69661 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n0 1\n0 3\n0 4\n0 9\n1 2\n2 3\n2 7\n4 5\n4 6\n7 8\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n1 2\n3 2\n2 4\n4 5\n5 6\n6 2\n5 7\n5 0",
"output": "30\n",
... | |
code_contests | verifiable_code | 1243_B1. Character Swap (Easy Version) | Solve the following coding problem using the programming language python:
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house agai... | ```python
t=int(input())
for ti in range(t):
n=int(input())
lia=[]
lib=[]
a=list(input())
b=list(input())
ctr=0
for i in range(n):
if a[i]!=b[i]:
lia.append(a[i])
lib.append(b[i])
ctr+=1
if ctr>2:
print("No")
break
... | vfc_69665 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n",
"output": "Yes\nNo\nNo\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n11\nartiovnldnp\nartiovsldsp\n2\naa\nzz\n2\naa\nx... |
code_contests | verifiable_code | 1261_F. Xor-Set | Solve the following coding problem using the programming language python:
You are given two sets of integers: A and B. You need to output the sum of elements in the set C = \\{x | x = a ⊕ b, a ∈ A, b ∈ B\} modulo 998244353, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR... | vfc_69669 | {
"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": "1\n1 9\n2\n2 4\n2 10\n",
"output": "120\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1284_C. New Year and Permutation | Solve the following coding problem using the programming language python:
Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permut... | ```python
n, m = map(int, input().split())
fac = [1]
for i in range(1, n + 1):
fac.append(i * fac[i - 1] % m)
ans = 0
for i in range(1, n+1):
ans += (n - i + 1) * fac[i] * fac[n - i + 1]
ans %= m
print(ans)
``` | vfc_69673 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 993244853\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2020 437122297\n",
"output": "265955509\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
code_contests | verifiable_code | 1303_E. Erase Subsequences | Solve the following coding problem using the programming language python:
You are given a string s. You can build new string p from s using the following operation no more than two times:
1. choose any subsequence s_{i_1}, s_{i_2}, ..., s_{i_k} where 1 ≤ i_1 < i_2 < ... < i_k ≤ |s|;
2. erase the chosen subseque... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from math import inf,isinf
def solve(s,t):
if len(t) == 1:
if s.count(t[0]):
return 'YES'
return 'NO'
for i in range(1,len(t)):
dp = [[-inf]*(i+1) for _ in ran... | vfc_69677 | {
"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\nababcd\nabcba\na\nb\ndefi\nfed\nxyz\nx\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nababc\nabcba\nfeded\ndefed\nababcfeded\nabcdebafed\n",
"o... |
code_contests | verifiable_code | 1327_F. AND Segments | Solve the following coding problem using the programming language python:
You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m).
Calculate the number of distinct arrays a, consisting of n integers such that:
* 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n;
* bitwise AN... | ```python
def main():
import sys
input = sys.stdin.buffer.readline
mod = 998244353
N, K, M = map(int, input().split())
cond = []
for _ in range(M):
cond.append(tuple(map(int, input().split())))
ans = 1
for k in range(K):
one = [0] * (N+1)
zero_cond = [0] * (N+1)
... | vfc_69681 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 3\n1 3 2\n2 5 0\n3 3 3\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 2\n1 3 3\n3 4 6\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1346_H. Game with Segments | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game (yet again).
They have two sequences of segments of the coordinate axis: a sequence of n initial segments: [l_1, r_1], [l_2, r_2], ..., [l_n, r_n], and a sequence of m terminal segments: [L_1, R_1], [L_2, R_2], ... | vfc_69685 | {
"difficulty": "14",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n4 7\n4 7\n",
"output": "\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n2 5\n2 4\n3 5\n",
"output": "\n-1\n",
"type": "stdin_stdout"
},
{
"fn_name":... | |
code_contests | verifiable_code | 1368_F. Lamps on a Circle | Solve the following coding problem using the programming language python:
This is an interactive problem.
John and his imaginary friend play a game. There are n lamps arranged in a circle. Lamps are numbered 1 through n in clockwise order, that is, lamps i and i + 1 are adjacent for any i = 1, …, n - 1, and also lamp... | ```python
from sys import stdout, exit
from traceback import format_exc
def main():
n = int(input())
on = [False] * n
def query(ll):
res = 0
pvals = [i+1 for i in ll]
print(len(ll), ' '.join(map(str,pvals)))
stdout.flush()
for i in ll:
if not on[i]:
... | vfc_69689 | {
"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": "3\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 138_A. Literature Lesson | Solve the following coding problem using the programming language python:
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letter... | ```python
n,k=list(map(int,input().split()))
def z(a,b):
global k
c=0
d=''
for i in range(len(a)-1,-1,-1):
d+=a[i]
if a[i] in ['a','e','i','o','u']:
c+=1
if c==k:
break
f=c==k
c=0
e=''
for i in range(len(b)-1,-1,-1):
e+=b[i]
... | vfc_69693 | {
"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": "1 1\nday\nmay\ngray\nway\n",
"output": "aaaa\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 140_E. New Year Garland | Solve the following coding problem using the programming language python:
As Gerald, Alexander, Sergey and Gennady are already busy with the usual New Year chores, Edward hastily decorates the New Year Tree. And any decent New Year Tree must be decorated with a good garland. Edward has lamps of m colors and he wants t... | vfc_69697 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1000\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3 1000\n2 2\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 1431_B. Polycarp and the Language of Gods | Solve the following coding problem using the programming language python:
Polycarp has just finished writing down the lecture on elvish languages. The language this week was "VwV" (pronounced as "uwu"). The writing system of this language consists of only two lowercase Latin letters: 'v' and 'w'.
Unfortunately, Polyc... | vfc_69701 | {
"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\nvv\nv\nw\nvwv\nvwvvwv\n",
"output": "\n1\n0\n1\n1\n3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1505_F. Math | Solve the following coding problem using the programming language python:
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 ≤ a ≤ 100).
Output
Output the result – an integer number.
Example
Input
1
Output
1
The input will be giv... | ```python
s=int(input())
print(2-s**2)
``` | vfc_69713 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "\n1\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1528_F. AmShZ Farm | Solve the following coding problem using the programming language python:
To AmShZ, all arrays are equal, but some arrays are more-equal than others. Specifically, the arrays consisting of n elements from 1 to n that can be turned into permutations of numbers from 1 to n by adding a non-negative integer to each elemen... | vfc_69717 | {
"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": "2 2\n",
"output": "\n8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000000 10000\n",
"output": "\n883232350\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
code_contests | verifiable_code | 15_E. Triangles | Solve the following coding problem using the programming language python:
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf,... | ```python
a,b,c,m=1,2,4,10**9+9
n=int(input())
for i in range(1,n//2):
c=c*a%m
b=(b+c)%m
a=(2*a+3)%m
print((b*b+1)*2%m)
``` | vfc_69721 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "74\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 17_B. Hierarchy | Solve the following coding problem using the programming language python:
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the ... | ```python
import sys
import math
import collections
import heapq
input=sys.stdin.readline
n=int(input())
l=[int(i) for i in input().split()]
m=int(input())
s=0
d={}
for i in range(m):
a,b,c=(int(i) for i in input().split())
if(b in d):
d[b]=min(d[b],c)
else:
d[b]=c
c1=0
for i in range(1,n+1)... | vfc_69725 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 64000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 3\n2\n3 1 2\n3 1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5\n",
"output": "11\n",
"type": "stdin_stdou... |
code_contests | verifiable_code | 202_C. Clear Symmetry | Solve the following coding problem using the programming language python:
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which i... | ```python
'''input
3
'''
from sys import stdin
import math
def make_dp():
dp = [0] * 1001
dp[1] = 1
dp[3] = 5
for i in range(5, 100, 2):
dp[i] = dp[i - 2] + i + i - 2
return dp
# main starts
x = int(stdin.readline().strip())
if x == 3:
print(5)
exit()
dp = make_dp()
for i in range(1, len(dp)):
if x <= d... | vfc_69729 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "61\n",
"o... |
code_contests | verifiable_code | 227_B. Effective Approach | Solve the following coding problem using the programming language python:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that ... | ```python
def editorial(n, a, m, b):
c = [None] * n
for i, x in enumerate(a):
c[x - 1] = i + 1
vasya = 0
petya = 0
for x in b:
i = c[x - 1]
vasya += i
petya += n - i + 1
return (vasya, petya)
if __name__ == '__main__':
n = int(input())
a = [int(x) for x ... | vfc_69733 | {
"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": "3\n3 1 2\n3\n1 2 3\n",
"output": "6 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1\n1\n1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
code_contests | verifiable_code | 250_E. Mad Joe | Solve the following coding problem using the programming language python:
Joe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.
Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is an empty cell), or has a brick or ... | ```python
n, m = [int(i) for i in input().split()]
current_floor = list(input())
x, t, direction = 0, 0, 1
for i in range(n-1):
floor = list(input())
l, r = x, x
wall = 0
while True:
t += 1
if floor[x] == '.':
break
if (x + direction == m) or (x + direction < 0) or ... | vfc_69737 | {
"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 5\n..+.#\n#+..+\n+.#+.\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 10\n...+.##+.+\n+#++..+++#\n++.#++++..\n.+##.++#.+\n",
"output": "42\n",
"type": "s... |
code_contests | verifiable_code | 276_A. Lunch Rush | Solve the following coding problem using the programming language python:
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.
The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized b... | ```python
n, k = map(int,input().split())
f = t = 0
maxf = -1000000000
for i in range(n):
f, t = map(int,input().split())
if t > k: f -= (t - k)
if f > maxf: maxf = f
print(maxf)
``` | vfc_69741 | {
"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 5\n3 3\n4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 5\n1 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
code_contests | verifiable_code | 299_C. Weird Game | Solve the following coding problem using the programming language python:
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game.
Roman leaves a word for each of them. Each word consists of 2·n binary characters "... | ```python
#!/usr/bin/python3
n = int(input())
s = list(input())
l = list(input())
a = len([_ for _ in zip(s, l) if _ == ('1', '1')])
b = len([_ for _ in zip(s, l) if _ == ('1', '0')])
c = len([_ for _ in zip(s, l) if _ == ('0', '1')])
f = b + (a + 1) // 2
s = c + a // 2
if f > s:
print('First')
elif f + 1 < s:
... | vfc_69745 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n01100000\n10010011\n",
"output": "Second",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n01010110\n00101101\n",
"output": "First",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 322_A. Ciel and Dancing | Solve the following coding problem using the programming language python:
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule... | ```python
n, m = map(int, input().split())
print(n + m - 1)
for i in range (1, n + 1): print(i, 1)
for i in range (1, m): print(1, i + 1)
``` | vfc_69749 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 1\n",
"output": "2\n1 1\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "3\n1 1\n1 2\n2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 346_D. Robot Control | Solve the following coding problem using the programming language python:
The boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in the directed graph. This behavior has been... | vfc_69753 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 6, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 2\n2 1\n1 3\n2 4\n3 4\n1 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 6\n1 2\n2 1\n1 3\n3 1\n2 4\n3 4\n1 4\n",
"output": "1\n",
"type": "stdin_st... | |
code_contests | verifiable_code | 391_E2. Three Trees | Solve the following coding problem using the programming language python:
This problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points.
A tree is an undirected connected graph containing no cycles. The distance between two nod... | vfc_69761 | {
"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": "2 2 3\n1 2\n1 2\n1 2\n2 3\n",
"output": "56",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 4\n1 2\n2 5\n3 4\n4 2\n1 2\n1 3\n1 4\n",
"output": "151",
"type": "stdin_stdout"
... | |
code_contests | verifiable_code | 414_C. Mashmokh and Reverse Operation | Solve the following coding problem using the programming language python:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programmin... | ```python
def main():
n = int(raw_input())
aa = list(map(int, raw_input().split()))
raw_input()
res = []
if n < 2:
l, f = ("01"[aa[0] > aa[-1]], "01"[aa[0] < aa[-1]]), False
for q in raw_input()[::2]:
f ^= q == '1'
res.append(l[f])
print('\n'.join(res)... | vfc_69765 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1 4 3\n4\n1 2 0 2\n",
"output": "0\n6\n6\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1 2\n3\n0 1 1\n",
"output": "0\n1\n0\n",
"type": "stdin_stdout"
},
{... |
code_contests | verifiable_code | 441_A. Valera and Antique Items | Solve the following coding problem using the programming language python:
Valera is a collector. Once he wanted to expand his collection with exactly one antique item.
Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Val... | ```python
r = lambda: list(map(int, input().split()))[1:]
n,c = map(int, input().split())
d = []
for _ in range(n):
for i in r():
if i<c:
d.append(str(_+1))
break
print (len(d))
print (' '.join(d))
``` | vfc_69769 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n",
... |
code_contests | verifiable_code | 463_B. Caisa and Pylons | Solve the following coding problem using the programming language python:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with ... | ```python
n=int(input())
s=list(map(int,input().split()))
m,h,d=0,0,0
for i in range(n):
m+=h-s[i]
if(m<0):
d-=m
m=0
h=s[i]
print(d)
``` | vfc_69773 | {
"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\n3 4 3 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | 487_A. Fight the Monster | Solve the following coding problem using the programming language python:
A monster is attacking the Cyberland!
Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).
During the battle, every second the monste... | ```python
from math import *
#from bisect import *
#from collections import *
#from random import *
#from decimal import *"""
#from heapq import *
#from random import *
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(3*(10**5))
global flag
def inp():
return int(input())
def st():
return input().rstri... | vfc_69777 | {
"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 100\n1 1 1\n1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1\n1 100 1\n1 100 100\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 50_E. Square Equation Roots | Solve the following coding problem using the programming language python:
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
x2 + 2bx + c = 0 where b, c are natural numbers.
Petya noticed that some equations have two real roots, some of them ha... | vfc_69781 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n",
"output": " 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3\n",
"output": " ... | |
code_contests | verifiable_code | 535_A. Tavas and Nafas | Solve the following coding problem using the programming language python:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he ha... | ```python
l=['','-one','-two','-three','-four','-five','-six','-seven','-eight','-nine']
l1=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
l2=['twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
l3=['zero','one','two','three','four','five','six',... | vfc_69785 | {
"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": "6\n",
"output": "six\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n",
"output": "twenty\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99\... |
code_contests | verifiable_code | 55_B. Smallest number | Solve the following coding problem using the programming language python:
Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two ... | ```python
import math,sys
from itertools import permutations
from collections import defaultdict,deque
import bisect as bi
def yes():print('YES')
def no():print('NO')
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(sys.stdin.readline()))
def In():return(map(int,sys.stdin.readline... | vfc_69789 | {
"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 2 2 2\n* * +\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 1 1\n+ + *\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 585_E. Present for Vitalik the Philatelist | Solve the following coding problem using the programming language python:
Vitalik the philatelist has a birthday today!
As he is a regular customer in a stamp store called 'Robin Bobin', the store management decided to make him a gift.
Vitalik wants to buy one stamp and the store will give him a non-empty set of the... | vfc_69793 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 2\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.