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 | 1175_F. The Number of Subpermutations | Solve the following coding problem using the programming language python:
You have an array a_1, a_2, ..., a_n.
Let's call some subarray a_l, a_{l + 1}, ... , a_r of this array a subpermutation if it contains all integers from 1 to r-l+1 exactly once. For example, array a = [2, 2, 1, 3, 2, 3, 1] contains 6 subarrays... | ```python
#import sys
import math
#input=sys.stdin.readline
#sys.setrecursionlimit(1000000)
mod=int(1000000007)
i=lambda :map(int,input().split())
n=int(input())
a=[int(x) for x in input().split()]
t=[[0]*21 for i in range(300005)]
for i in range(n):
t[i][0]=a[i]
def build(n):
for j in range(1,20):
f... | vfc_43417 | {
"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": "8\n2 4 1 3 4 2 1 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 2 1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
code_contests | verifiable_code | 1194_E. Count The Rectangles | Solve the following coding problem using the programming language python:
There are n segments drawn on a plane; the i-th segment connects two points (x_{i, 1}, y_{i, 1}) and (x_{i, 2}, y_{i, 2}). Each segment is non-degenerate, and is either horizontal or vertical — formally, for every i ∈ [1, n] either x_{i, 1} = x_... | vfc_43421 | {
"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 5 1 0\n0 1 5 1\n5 4 0 4\n4 2 4 0\n4 3 4 5\n",
"output": " 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n-1 4 -1 -2... | |
code_contests | verifiable_code | 1211_B. Traveling Around the Golden Ring of Berland | Solve the following coding problem using the programming language python:
The Golden Ring is the special tourist route in Berland. This route consists of n cities and the cyclic railway route. Cities are numbered from 1 to n so that:
* the next city for 1 is the city 2,
* the next city for 2 is the city 3,
* ... | vfc_43425 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 0 0\n",
"output": "\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 0 2\n",
"output": "\n6\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1234_A. Equalize Prices Again | Solve the following coding problem using the programming language python:
You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs a_i coins.
You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. M... | ```python
import math
for _ in range(int(input())):
k=int(input())
l=list(map(int,input().split()))
k=sum(l)/k
print(math.ceil(k))
``` | vfc_43429 | {
"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\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\n",
"output": "3\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5\n1 2 3 4 5\n3\n1 2 3\n2\n777 778\n",
"output": "3\n2\n778\n",
... |
code_contests | verifiable_code | 1252_K. Addition Robot | Solve the following coding problem using the programming language python:
Adding two numbers several times is a time-consuming task, so you want to build a robot. The robot should have a string S = S_1 S_2 ... S_N of N characters on its memory that represents addition instructions. Each character of the string, S_i, i... | vfc_43433 | {
"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": "5 3\nABAAA\n2 1 5 1 1\n1 3 5\n2 2 5 0 1000000000\n",
"output": "\n11 3\n0 1000000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 131_E. Yet Another Task with Queens | Solve the following coding problem using the programming language python:
A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the ... | ```python
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
impo... | vfc_43445 | {
"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": "10 3\n1 1\n1 2\n1 3\n",
"output": "0 2 1 0 0 0 0 0 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 4\n4 3\n4 8\n6 5\n1 6\n",
"output": "0 3 0 1 0 0 0 0 0\n",
"type": "stdin... |
code_contests | verifiable_code | 1339_B. Sorted Adjacent Differences | Solve the following coding problem using the programming language python:
You have array of n numbers a_{1}, a_{2}, …, a_{n}.
Rearrange these numbers to satisfy |a_{1} - a_{2}| ≤ |a_{2} - a_{3}| ≤ … ≤ |a_{n-1} - a_{n}|, where |x| denotes absolute value of x. It's always possible to find such rearrangement.
Note tha... | ```python
for _ in range(int(input())):
n = int(input())
ls = sorted(list(map(int, input().split())))
mid = n // 2
if n % 2 == 0:
mid -= 1
i = mid - 1
turn = True
j = mid + 1
ar = []
ar.append(ls[mid])
while i >= 0 or j < n:
if turn and j < n:
ar.append(ls[j])
j += 1
elif not turn and i >= 0:
a... | vfc_43449 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6\n5 -2 4 8 6 5\n4\n8 1 4 2\n",
"output": "5 5 4 6 -2 8\n2 4 1 8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n29\n31 16383 15 127 255 3 4095 536870911 7 63 262143 2097151 1 167772... |
code_contests | verifiable_code | 1360_F. Spy-string | Solve the following coding problem using the programming language python:
You are given n strings a_1, a_2, …, a_n: all of them have the same length m. The strings consist of lowercase English letters.
Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally... | ```python
# cook your dish here
#code
import math
import collections
from sys import stdin,stdout,setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2**20)
def strcmp(s1,s2,m):
cnt = 0
for i in range(m):
if(s1[i]!=s2[i]... | vfc_43453 | {
"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\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n",
"output": "zbac\n-1\naaa\nab\na\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 4\nabac\nzbab\n2... |
code_contests | verifiable_code | 1380_G. Circular Dungeon | Solve the following coding problem using the programming language python:
You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the... | ```python
import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ i... | vfc_43457 | {
"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": "2\n1 2\n",
"output": "499122177 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n10 4 3 6 5 10 7 5\n",
"output": "499122193 249561095 249561092 873463811 499122178 124780545 62390... |
code_contests | verifiable_code | 1400_G. Mercenaries | Solve the following coding problem using the programming language python:
Polycarp plays a (yet another!) strategic computer game. In this game, he leads an army of mercenaries.
Polycarp wants to gather his army for a quest. There are n mercenaries for hire, and the army should consist of some subset of them.
The i-... | vfc_43461 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 7, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 0\n1 1\n2 3\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1424_G. Years | Solve the following coding problem using the programming language python:
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting i... | ```python
dct = {}
for i in range(int(input())):
a,b = map(int,input().split())
dct[a] = dct.get(a,0)+1
dct[b] = dct.get(b,0)-1
cnt = curr = y = 0
for i in sorted(dct.keys()):
curr += dct[i]
if curr > cnt :
cnt = curr
y = i
print(y,cnt)
``` | vfc_43465 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 5\n2 4\n5 6\n",
"output": "2 2\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1445_C. Division | Solve the following coding problem using the programming language python:
Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.
To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, suc... | ```python
"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlin... | vfc_43469 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n10 4\n12 6\n179 822\n",
"output": "10\n4\n179\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 146_C. Lucky Conversion | Solve the following coding problem using the programming language python:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a... | ```python
a=input()
b=input()
da={'4':0,'7':0}
db={'4':0,'7':0}
for i in a:
da[i]+=1
for i in b:
db[i]+=1
dif=0
for i in range(len(a)):
if(a[i]!=b[i]):
dif+=1
ans=0
if(da==db):
ans=dif//2
else:
x=abs(da['4']-db['4'])
ans+=x
dif-=x
ans+=(dif//2)
print(ans)
``` | vfc_43473 | {
"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": "47\n74\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "774\n744\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 1495_E. Qingshan and Daniel | Solve the following coding problem using the programming language python:
Qingshan and Daniel are going to play a card game. But it will be so boring if only two persons play this. So they will make n robots in total to play this game automatically. Robots made by Qingshan belong to the team 1, and robots made by Dani... | vfc_43477 | {
"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": "1\n1\n1 1 0 0\n",
"output": "\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 217_D. Bitonix' Patrol | Solve the following coding problem using the programming language python:
Byteland is trying to send a space mission onto the Bit-X planet. Their task is complicated by the fact that the orbit of the planet is regularly patrolled by Captain Bitonix, the leader of the space forces of Bit-X.
There are n stations around... | vfc_43497 | {
"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 60 2\n10 100\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 6 5\n5 4 12 6 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 241_C. Mirror Box | Solve the following coding problem using the programming language python:
Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly sma... | ```python
from math import *
[h1, h2, n] = map(int, raw_input().split())
v = []
x1 = []
x2 = []
b = []
tm = [[-1] * 100001, [-1] * 100001]
for i in xrange(n):
ttt = raw_input().split()
v.append(int(ttt[0]))
x1.append(int(ttt[2]))
x2.append(int(ttt[3]))
for x in xrange(int(ttt[2]), int(ttt[3]) + 1):
... | vfc_43501 | {
"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": "80 72 9\n15 T 8210 15679\n10 F 11940 22399\n50 T 30600 44789\n50 F 32090 36579\n5 F 45520 48519\n120 F 49250 55229\n8 F 59700 80609\n35 T 61940 64939\n2 T 92540 97769\n",
"output": "120",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 266_B. Queue at the School | Solve the following coding problem using the programming language python:
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of ... | ```python
n, t = map(int, input().split())
a = list(input())
for i in range(t):
j = 0
while j < n:
while j < n and a[j] == 'G':
j += 1
while j < n and a[j] == 'B':
j += 1
if j < n:
a[j - 1], a[j] = 'G', 'B'
j += 1
for i in a:
... | vfc_43505 | {
"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 1\nBGGBG\n",
"output": "GBGGB\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\nBGGBG\n",
"output": "GGBGB\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 28_B. pSort | Solve the following coding problem using the programming language python:
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange... | ```python
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[[] for i in range(n)]
for i in range(n):
if i-b[i]>=0:
c[i].append(i-b[i])
c[i-b[i]].append(i)
if i+b[i]<n:
c[i].append(i+b[i])
c[i+b[i]].append(i)
v=[1]*n
def dfs(u):
global v,c
... | vfc_43509 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 4 3 2 1\n1 1 1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 360_A. Levko and Array Recovery | Solve the following coding problem using the programming language python:
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from ... | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if ... | vfc_43521 | {
"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 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"output": "YES\n8 7 4 7 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"o... |
code_contests | verifiable_code | 383_D. Antimatter | Solve the following coding problem using the programming language python:
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter.
Iahub wants to choose so... | ```python
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))
n = int(input())
a = list(map(int, input().split()))
m = sum(a)
M = 10**9+7
dp = [0... | vfc_43525 | {
"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": "4\n1 1 1 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\n",
... |
code_contests | verifiable_code | 404_C. Restore Graph | Solve the following coding problem using the programming language python:
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the... | ```python
from sys import exit
n, k = map(int, input().split())
nodes = [[] for _ in range(n+1)]
edges = []
for node, dist in enumerate(map(int, input().split())):
nodes[dist].append(node)
if len(nodes[0]) != 1 or len(nodes[1]) > k:
print(-1)
else:
for i in range(1, n):
if len(nodes[i])*(k-1) < ... | vfc_43529 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n0 1 1\n",
"output": "2\n1 2\n1 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
code_contests | verifiable_code | 431_D. Random Task | Solve the following coding problem using the programming language python:
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary repre... | ```python
def dfs(n, k, cache = {}):
# if number of bits is bigger than the number's bits of the number's bits is less than 0
if k > n or k < 0: return 0
# if num bits is 0 or num bits is equivalent to the number's bits
if k == 0 or k == n: return 1
# This optimization is not necessary but flips the... | vfc_43533 | {
"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": "1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "286 11\n"... |
code_contests | verifiable_code | 454_A. Little Pony and Crystal Mine | Solve the following coding problem using the programming language python:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the... | ```python
n=int(input())
a=int(n/2)
b=1
for i in range(int(n/2)):
for j in range(a):
print("*",end="")
for j in range(b):
print('D',end="")
b=b+2
for j in range(a):
print("*",end="")
a=a-1
print()
for i in range(b):
print("D",end="")
print()
a=a+1
b=b-2
for i in range... | vfc_43537 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n",
... |
code_contests | verifiable_code | 476_D. Dreamoon and Sets | Solve the following coding problem using the programming language python:
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for a... | ```python
n,k = [int(i) for i in input().split()]
print((6*n-1)*k)
for a in range(n):
val = 6*a
print((val+1)*k,(val+2)*k,(val+3)*k,(val+5)*k)
``` | vfc_43541 | {
"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": "1 1\n",
"output": "5\n1 2 3 5 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "22\n2 4 6 10 \n14 16 18 22 \n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 49_E. Common ancestor | Solve the following coding problem using the programming language python:
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the ... | ```python
#!/usr/bin/env python3
import itertools
import collections
# Read input strings
s1 = input()
s2 = input()
# Read evolution rules, use a mapping from the 2 target characters to the source character
rules = collections.defaultdict(set)
n = int(input())
for i in range(n):
rule = input()
target = rule[-2:]... | vfc_43545 | {
"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": "ababa\naba\n2\nc->ba\nc->cc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ababa\naba\n1\nc->ba\n",
"output": "-1\n",
"type": "stdin_stdout"
}
... |
code_contests | verifiable_code | 524_E. Rooks and Rectangles | Solve the following coding problem using the programming language python:
Polycarpus has a chessboard of size n × m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must... | vfc_43549 | {
"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 3 3 3\n1 1\n3 2\n2 3\n2 3 2 3\n2 1 3 3\n1 2 2 3\n",
"output": "YES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 4 10\n3 1\n4 3\n2 3\n4 1\n2 1 4 2\n2 1 4 3\n1 1 3 2\n1 2 4... | |
code_contests | verifiable_code | 54_E. Vacuum Сleaner | Solve the following coding problem using the programming language python:
One winter evening the Hedgehog was relaxing at home in his cozy armchair and clicking through the TV channels. Stumbled on an issue of «TopShop», the Hedgehog was about to change the channel when all of a sudden he was stopped by an advertiseme... | vfc_43553 | {
"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\n0 0\n1 0\n1 1\n0 1\n",
"output": "0.0000000000\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 577_A. Multiplication Table | Solve the following coding problem using the programming language python:
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task ... | ```python
import sys
n, x = map(int, sys.stdin.readline().split())
s = 0
for i in range(1, n + 1):
if (x % i == 0 and x / i <= n):
s += 1
print(s)
``` | vfc_43557 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 12\... |
code_contests | verifiable_code | 599_D. Spongebob and Squares | Solve the following coding problem using the programming language python:
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in ... | ```python
n,i,t,r=int(input()),0,0,[]
while 1:
i+=1
n-=i*i
if n<0:break
t+=i
m=n//t
r+=[(m+i,i),(i,m+i)][m==0:]*(m*t==n)
print(len(r))
for p in sorted(r):print("%d %d"%p)
``` | vfc_43561 | {
"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": "8\n",
"output": "4\n 1 8\n 2 ... |
code_contests | verifiable_code | 620_C. Pearls in a Row | Solve the following coding problem using the programming language python:
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pear... | ```python
n=int(input())
d={}
b=[]
e=1
a=list(map(int,input().split()))
for i in range(n):
if a[i] in d:
b.append([e,i+1])
e=i+2
d.clear()
else:
d[a[i]]=i+1
if len(b)==0:
print(-1)
exit()
print(len(b))
k=b[-1]
b[-1]=[k[0],n]
for i in b:
print(*i)
``` | vfc_43565 | {
"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\n1 2 3 4 1\n",
"output": "1\n1 5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 641_B. Little Artem and Matrix | Solve the following coding problem using the programming language python:
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That ele... | ```python
import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda: int(input())
lmii = lambda: list(map(int, input().split()))
li = lambda: list(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
def ma... | vfc_43569 | {
"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 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n",
"output": "8 2 \n1 8 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 2\n1 2\n3 2 2 5\n",
"output": "0 0 0 \n0 0 5 \n0 0 0... |
code_contests | verifiable_code | 669_E. Little Artem and Time Machine | Solve the following coding problem using the programming language python:
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multis... | ```python
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
new = lambda xx: (xx|xx-1)+1
def buildBIT(bit,n):
for i in range(1,n+1):
x = new(i)
if x <= n:
bit[x] += bit[i]
def pointUpdate(bit,point,n,diff):
while point <= n:
... | vfc_43573 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 1\n2 2 1\n3 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 715_B. Complete The Graph | Solve the following coding problem using the programming language python:
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were... | ```python
import heapq
from collections import defaultdict
class Graph:
def __init__(self, n):
self.nodes = set(range(n))
self.edges = defaultdict(list)
self.distances = {}
def add_edge(self, from_node, to_node, distance):
self.edges[from_node].append(to_node)
self.edg... | vfc_43581 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 999999999 1 0\n0 1 1000000000\n",
... |
code_contests | verifiable_code | 735_D. Taxes | Solve the following coding problem using the programming language python:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). ... | ```python
def isPrime(n):
i=2
while i*i<=n:
if n%i==0:
return False
i+=1
return True
n=int(input())
if isPrime(n):
print(1)
elif n&1==0:
print(2)
else:
if isPrime(n-2):
print(2)
else:
print(3)
``` | vfc_43585 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "27\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "101\n",
... |
code_contests | verifiable_code | 75_D. Big Maximum Sum | Solve the following coding problem using the programming language python:
Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.
This problem is similar to a st... | ```python
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def prepare(n, *a):
acc = 0
sub_max = -10**9
left_min = 0
left_max = 0
lmin2, lmax2 = 0, -10**9
for i, x in enumerate(a):
acc += x
sub_max = max(sub... | vfc_43589 | {
"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": "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1\n",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3\n",
"ou... |
code_contests | verifiable_code | 780_C. Andryusha and Colored Balloons | Solve the following coding problem using the programming language python:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reac... | ```python
n=int(input())
g=[[] for i in range(n)]
for _ in range(n-1):
x,y=map(int,input().split())
g[x-1].append(y-1)
g[y-1].append(x-1)
l=0
for i in range(n):
l=max(l,len(g[i])+1)
q=[0]
paint=[-1]*n
paint[0]=1
while q:
ver=q.pop()
use=set()
use.add(paint[ver])
for to in g[ver]:
use.add(paint[to])
... | vfc_43593 | {
"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 3\n5 3\n4 3\n1 3\n",
"output": "5\n1 3 2 5 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n2 1\n3 2\n4 3\n5 4\n",
"output": "3\n1 2 3 1 2",
"type": "stdin_stdout"
}... |
code_contests | verifiable_code | 803_G. Periodic RMQ Problem | Solve the following coding problem using the programming language python:
You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
* 1 l r x — for each index i such that l ≤ i ≤ r set ai = x.
* 2 l r — find the minimum among such ai that l ≤ i ≤ r.
... | ```python
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = [0] + list(map(int, stdin.readline().split()))
m = int(stdin.readline())
questions = []
ar = set()
for i in range(m):
questions.append(tuple(map(int, stdin.readline().strip().split())))
ar.add(int(questions[-1][1]))
... | vfc_43597 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 4, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3\n",
"output": "1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6\n",
"output": "1\n5\n1\n... |
code_contests | verifiable_code | 828_E. DNA Evolution | Solve the following coding problem using the programming language python:
Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s in... | vfc_43601 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "GAGTTGTTAA\n6\n2 3 4 TATGGTG\n1 1 T\n1 6 G\n2 5 9 AGTAATA\n1 10 G\n2 2 6 TTGT\n",
"output": "0\n3\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "ATGCATGC\n4\n2 1 8 ATGC\n2 2 6 TTT\n1 4... | |
code_contests | verifiable_code | 899_B. Months and Years | Solve the following coding problem using the programming language python:
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 ... | ```python
a1 = '31 28 31 30 31 30 31 31 30 31 30 31 '
a2 = '31 29 31 30 31 30 31 31 30 31 30 31 '
s = a1 + a1 + a1 + a2 + a1 + a1
n = input()
ss = input().strip()
print(["NO",'YES'][ss in s])
``` | vfc_43613 | {
"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\n31 31 30 31\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n31 31 28\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 976_A. Minimum Binary Number | Solve the following coding problem using the programming language python:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string s.
You can perform two different operations on this stri... | ```python
n=int(input())
a=input()
count1=0
for item in a:
if(item=='1'):
count1=count1+1
if(count1>=1):
print(1,end="")
for i in range(0,len(a)-count1):
print(0,end="")
``` | vfc_43625 | {
"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\n1001\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
code_contests | verifiable_code | 995_E. Number Clicker | Solve the following coding problem using the programming language python:
Allen is playing Number Clicker on his phone.
He starts with an integer u on the screen. Every second, he can press one of 3 buttons.
1. Turn u → u+1 \pmod{p}.
2. Turn u → u+p-1 \pmod{p}.
3. Turn u → u^{p-2} \pmod{p}.
Allen wants t... | vfc_43629 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 3 5\n",
"output": "2\n1 1 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 5\n",
"output": "1\n2 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... | |
code_contests | verifiable_code | balanced-buildings | Solve the following coding problem using the programming language python:
Cat Noku recently picked up construction working as a hobby. He's currently working with a row of buildings and would like to make it beautiful.
There are n buildings in a row. The height of the i-th building is xi.
Cat Noku can modify the bui... | ```python
n,S,M,P=map(int, raw_input().split())
his=map(int, raw_input().split())
maxhi=max(his)
minhi=min(his)
earned={}
act=n-1
for i in xrange(minhi,maxhi+1):
earned[i]=(i-his[act])*M if his[act]>i else (his[act]-i)*P # all neg!
while act>0:
nextearn=earned
maxnext=max(nextearn.values())
earned={}
act-=1
... | vfc_43633 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 2 1\n1 2 1 5 4\n\nSAMPLE",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "328 292351550 594024 614178\n111198 247099 874897 789938 217603 184758 550844 786670 926237 148681... |
code_contests | verifiable_code | email-validator | Solve the following coding problem using the programming language python:
Chinna and Chinnu has recently started developing a website for their startup from scratch. But they found it difficult to validate an Email field for their login forum. Help them build one.
An Email Address is of the form <username>@<hostname>... | ```python
t=input()
while t:
t-=1
e = raw_input()
yes = True
try:
u,h = e.split('@')
except:
print("NO")
continue
else:
if len(u) >16 or len(u) < 1:
yes = False
for x in u:
if not ((x >= 'a' and x <= 'z') or (x >= 'A' and x <= 'Z') or (x >= '0' and x <= '9') or x =='_'):
yes = False
... | vfc_43641 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncoder@mastroes.com\n999@111.blah\n1_1@h-1-g.go\n\nSAMPLE",
"output": "YES\nNO\nYES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\ncoder@mastroes.com\n999@111.blah\n1_1@hg1-g.-o\n\nSAM... |
code_contests | verifiable_code | heartbroken-lala | Solve the following coding problem using the programming language python:
"She loves me", "She loves me not", "She loves me", "She loves me not", OH WAIT, I'm LALA,
"They love me", "They love me not", "They love me", "They love me not". Lala was indeed overwhelmed by the
'runner's high' and the turbulence inside him. ... | ```python
def f(x):
while x%2==0:
x /= 2
return x%4 == 3
for i in range(int(raw_input())):
if f(int(raw_input())):
print(1)
else:
print(0)
``` | vfc_43645 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n10\n\nSAMPLE",
"output": "0\n0\n1\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "64\n159297998\n24435194\n36701392\n69645530\n38591177\n150073105\n171554925\n4769107\n4818618... |
code_contests | verifiable_code | lucky-numbers-8 | Solve the following coding problem using the programming language python:
Lucky numbers are those numbers which are greater than all numbers to its right side.You task is to count all lucky numbers in a given array.
RightMost Element is always lucky Number
INPUT First line contain number of test case T. Each test case... | ```python
import sys
for __ in range(input()) :
n = input()
lists = list(map(int,sys.stdin.readline().split()))
lucky = lists[-1]
ans = 1
for i in range(n-2,-1,-1) :
if lucky < lists[i] :
lucky = lists[i]
ans += 1
print ans
``` | vfc_43649 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n6\n16 17 4 3 5 2\n\nSAMPLE",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n42\n67 34 0 69 24 78 58 62 64 5 45 81 27 61 91 95 42 27 36 91 4 2 53 92 82 21 16 18 95 47 2... |
code_contests | verifiable_code | naughty-subly-3 | Solve the following coding problem using the programming language python:
Subly is a very naughty kid. His father gave a set of numbers to him. In the set no number is repeated and the set has N elements. He wanted Subly to keep that set safe. When his Father was busy watching a new season of his favourite TV series, ... | ```python
test=input()
arr=[]
c=0
arr=raw_input().split()
if len(arr)==test:
print len(arr)-len(set(arr))
``` | vfc_43653 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 6 3 9 6 3\n\nSAMPLE",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27 41 27 73 37 12 69 68 30 83 31 63 24 68 36 30 3 2... |
code_contests | verifiable_code | problem-9-1 | Solve the following coding problem using the programming language python:
There are 'n' coins kept on the table, numbered from 0 to 'n-1'. Initially, each coin is kept tails up. You have to perform two types of operations :
1) Flip all coins numbered between A and B inclusive. This is represented by the command:
0
A
B... | ```python
lst=[0]*input()
for i in range(input()):
a=int(raw_input())
b=int(raw_input())
c=int(raw_input())
c=c+1
if a==0:
for i in range(b,c):
if lst[i]==0:
lst[i]=1
else:
lst[i]=0
else:
count=0
for i in range(b,c):
if lst[i]==1:
count=count+1
print count
``` | vfc_43657 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n3\n0\n3\n5\n1\n0\n6\n1\n3\n4\n\nSAMPLE",
"output": "3\n2",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | sharethefare-1 | Solve the following coding problem using the programming language python:
WizKid went on a trip to Wonderland with his classmates. Now, as you know, going on trips incurs costs including hotel costs, fooding, shopping, etc. And when many people go together, usually one person pays and it is expected that the others wi... | ```python
t=input('')
cnt=0
while int(t)>int(cnt):
d={}
n_person,q_transaction=raw_input('').split(' ')
tourist_name=[]
for i in range(int(n_person)):
tourist_name.append(str(raw_input('')))
d[tourist_name[i]]=[0,0]#expense,paid
for j in range(int(q_transaction)):
payee_name=str(raw_input(''))#who paid fo... | vfc_43661 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 2\nAlice\nBob\nDaniel\nMike\nBob\n97\n1\nAlice\nMike\n24\n2\nAlice\nBob\n\nSAMPLE",
"output": "Alice owes 56\nBob is owed 40\nDaniel neither owes nor is owed\nMike is owed 16\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | the-battle-of-panipat-4 | Solve the following coding problem using the programming language python:
This is 1526 A.D. Third Battle of Panipat between Babur and Ibrahim Lodi, the current ruler of India is going on.
Realising that Lodi has much larger army, Babur planned to attack the cities of India to bring the moral of the soldiers of Lodi ... | ```python
n=int(raw_input())
r=[True]*(n)
G=[[] for i in xrange(n)]
A=[-1]*(n)
B=[-1]*(n)
m=(10**9+7)
for i in xrange(n-1):
u,v=map(int,raw_input().split())
G[u].append(v)
r[v]=False
for i in xrange(0,n):
if r[i]==True:
root=i
def f(x):
#print x
p=1
t=0
if len(G[x])==0:
A... | vfc_43665 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 1\n1 2\n\nSAMPLE",
"output": "7",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | xenny-and-composite-number | Solve the following coding problem using the programming language python:
Today, teacher taught Xenny the chapter 'Prime numbers and Composite numbers'. Xenny liked it and being a studious boy, wanted some homework. So teacher gave him a simple task. The task is to find the smallest composite number greater than given... | ```python
def isprime(n):
for x in xrange(2, int(n**0.5)+1):
if n % x == 0:
return False
return True
t=input()
while(t):
n=input()
flag=1
i=n+1
while(flag):
if not isprime(i):
print i
flag=0
... | vfc_43669 | {
"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\n8\n\nSAMPLE",
"output": "4\n9\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p03978 Kyoto University Programming Contest 2016 - Long Blackboard | Solve the following coding problem using the programming language python:
There is a long blackboard with 2 rows and N columns in a classroom of Kyoto University. This blackboard is so long that it is impossible to tell which cells are already used and which unused.
Recently, a blackboard retrieval device was install... | vfc_43709 | {
"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": "",
"output": "",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p00067 The Number of Island | Solve the following coding problem using the programming language python:
There is a plan view consisting of 12 vertical and 12 horizontal squares showing the terrain. Each square is painted white or black. White represents the sea and black represents the land. When two black squares touch each other vertically or ho... | ```python
c=0
def f(a,x,y):
if 0<=x<12 and 0<=y<12 and a[y][x]=='1':
a[y][x]='0'
for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy)
while 1:
try:
if c:input()
except:break
a = [list(input()) for _ in [0]*12]
c=1;b=0
for i in range(12):
for j in range(12):
... | vfc_43713 | {
"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": "111100001111\n111000001111\n110000001111\n100000001111\n000100010000\n000000111000\n000001111100\n100011111110\n110001111100\n111000111000\n111100010000\n000000000000\n\n010001111100\n110010000010\n010010000001\n010000000001\n01000... |
code_contests | verifiable_code | p00560 Semiexpress | Solve the following coding problem using the programming language python:
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local.
A local train stops at ... | ```python
from heapq import heapify, heappop, heappush
N, M, K = map(int, input().split())
A, B, C = map(int, input().split())
T = int(input())
S = [int(input())-1 for i in range(M)]
def f(rt, rn):
return min(rt // A, rn-1)
ans = 0
que = []
for i in range(M-1):
s0 = S[i]; s1 = S[i+1]
if B*s0 <= T:
... | vfc_43725 | {
"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": "10 3 5\n10 3 5\n30\n1\n6\n10",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3 5\n10 3 3\n30\n1\n6\n10",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | p00713 Circle and Points | Solve the following coding problem using the programming language python:
You are given N points in the xy-plane. You have a circle of radius one and move it on the xy-plane, so as to enclose as many of the points as possible. Find how many points can be simultaneously enclosed at the maximum. A point is considered en... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in ... | vfc_43729 | {
"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\n6.47634 7.69628\n5.16828 4.79915\n6.69533 6.20378\n6\n7.15296 4.08328\n6.50827 2.69466\n5.91219 3.86661\n5.29853 4.16097\n6.10838 3.46039\n6.34060 2.41599\n8\n7.90650 4.01746\n4.10998 4.18354\n4.67289 4.01887\n6.33885 4.28388\n4... |
code_contests | verifiable_code | p00853 Enjoyable Commutation | Solve the following coding problem using the programming language python:
Isaac is tired of his daily trip to his ofice, using the same shortest route everyday. Although this saves his time, he must see the same scenery again and again. He cannot stand such a boring commutation any more.
One day, he decided to improv... | vfc_43733 | {
"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 20 10 1 5\n1 2 1\n1 3 2\n1 4 1\n1 5 3\n2 1 1\n2 3 1\n2 4 2\n2 5 2\n3 1 1\n3 2 2\n3 4 1\n3 5 1\n4 1 1\n4 2 1\n4 3 1\n4 5 2\n5 1 1\n5 2 1\n5 3 1\n5 4 1\n4 6 1 1 4\n2 4 2\n1 3 2\n1 2 1\n1 4 3\n2 3 1\n3 4 1\n3 3 5 1 3\n1 2 1\n2 3 1\n... | |
code_contests | verifiable_code | p01116 For Programming Excellence | Solve the following coding problem using the programming language python:
For Programming Excellence
A countless number of skills are required to be an excellent programmer. Different skills have different importance degrees, and the total programming competence is measured by the sum of products of levels and import... | vfc_43741 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 268435456,
"problem_url": null,
"time_limit": "{'seconds': 8, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 10\n5 4 3\n1 2 3\n1 2\n5 2\n5 40\n10 10 10 10 8\n1 2 3 4 5\n1 1 2 3\n10 10 10 10\n5 10\n2 2 2 5 2\n2 2 2 5 2\n1 1 2 2\n2 1 2 1\n0 0",
"output": "18\n108\n35",
"type": "stdin_stdout"
},
{
"fn_name": null,... | |
code_contests | verifiable_code | p01415 Starting Line | Solve the following coding problem using the programming language python:
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now s... | ```python
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
if _ == N:
d = L
else:
d = int(input())
length = d - l
l = d
while t > 0 or k > 0:
if t > 0:
if t * V >= length:
tmp = (t * V - length) / V
... | vfc_43749 | {
"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": "1 1 1 2 3 100\n50",
"output": "49.500000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1 1 2 3 100\n49\n50\n51",
"output": "48.666666667",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | p01569 Sun and Moon | Solve the following coding problem using the programming language python:
In the year 20XX, mankind is hit by an unprecedented crisis. The power balance between the sun and the moon was broken by the total eclipse of the sun, and the end is looming! To save the world, the secret society called "Sun and Moon" decided t... | vfc_43753 | {
"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\n1 1\n0 -1",
"output": "No",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | p01731 Thread Tree | Solve the following coding problem using the programming language python:
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view.
Like many other bulletin board systems, JAG-channel is thread-based. Here a thread ... | ```python
import sys
sys.setrecursionlimit(1010)
N = int(input())
src = []
for i in range(N):
k = int(input())
s = input()
src.append((s,[]))
if i == 0: continue
src[k-1][1].append(i)
def dfs(i,depth):
s,ch = src[i]
print('.'*depth + s)
for c in ch:
dfs(c,depth+1)
dfs(0,0)
``` | vfc_43757 | {
"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": "1\n0\nicpc",
"output": "icpc",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\nccpi",
"output": "ccpi\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
code_contests | verifiable_code | p01869 28 | Solve the following coding problem using the programming language python:
Problem statement
Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed f... | ```python
import bisect
import sys
sys.setrecursionlimit(10000)
a=[]
def f(a,bin,n):
if bin>n:return
if bin:a+=[bin]
f(a,bin*10+2,n)
f(a,bin*10+8,n)
def g(n,p):
m=-1<<20
x=bisect.bisect_left(a,n)
if x!=len(a) and a[x]==n:m=1
if a[p]**2>n:return m
if n%a[p]==0:m=g(n//a[p],p)+1
re... | vfc_43761 | {
"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": "1",
"output": "-1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "-1",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2",
"out... |
code_contests | verifiable_code | p02006 Santa's Gift | Solve the following coding problem using the programming language python:
Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The size and the price of the $i$-th gift ($1 \leq i \leq N$) are $s_i$ and $p_i$, respectively. The size of the bag is $C$, thus Santa can pack gifts so that th... | vfc_43765 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 536870912,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 2\n1 1",
"output": "1\n0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 3 2\n1 2\n2 10\n3 5",
"output": "17\n24",
"type": "stdin_stdout"
},
{
"fn_name": null... | |
code_contests | verifiable_code | p02291 Reflection | Solve the following coding problem using the programming language python:
For given three points p1, p2, p, find the reflection point x of p onto p1p2.
<image>
Constraints
* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.
Input
xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1
In the firs... | ```python
import math
def equals(a, b):
return abs(a - b) < 1e-10
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def __add__(self, p):
return Point(self.x + p.x, self.y + p.y)
def __sub__(self, p):
return Point(self.x - p.x, self.y - p.y)
def _... | vfc_43773 | {
"difficulty": "0",
"memory_limit": null,
"memory_limit_bytes": 134217728,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 3 4\n3\n2 5\n1 4\n0 3",
"output": "4.2400000000 3.3200000000\n3.5600000000 2.0800000000\n2.8800000000 0.8400000000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0 0 2 0\n3\n-1 1\n0 1\n... |
code_contests | verifiable_code | anuarm | Solve the following coding problem using the programming language python:
N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the r... | ```python
T = input()
for _ in range(T):
n,m = map(int,raw_input().split())
arr = map(int,raw_input().split())
s = min(arr)
l = max(arr)
for i in range(n):
if abs(i-s)>abs(i-l):
print abs(i-s),
else:
print abs(i-l),
``` | vfc_43781 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4 1\n1\n6 2\n2 3",
"output": "1\n0\n1\n2\n3\n2\n1\n1 2 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | chode | Solve the following coding problem using the programming language python:
Once upon a time chef decided to learn encodings. And, obviously, he started with the easiest one (well, actually the easiest after Caesar cypher) – substitution cypher.
But very soon Chef got bored with encoding/decoding, so he started thinking... | ```python
def cmp(tup):
return (tup[1], tup[0])
def get_decoder(text,freqseq):
mymap = {}
for ch in text:
if ch.isalpha():
if ch.lower() in mymap:
mymap[ch.lower()] += 1
else:
mymap[ch.lower()] = 1
v = []
for k in mymap:
v.append((k,mymap[k]))
v = sorted(v,key=cmp)
length = len(v)
lastcu... | vfc_43785 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\nqwrtyuipasdfgjkzxcvbnmheol\ndummy!\nbfgjklmopqrstuwxzhvnicdyea\nabcd b efgd hbi!\nqwrtyuipasdfgjkzxcvbnmheol\nDummy!",
"output": "hello!\nhave a nice day!\nHello!",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | eqidlis | Solve the following coding problem using the programming language python:
Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous ch... | ```python
# your code goes here
# your code goes here
import math
A=[]
t=int(raw_input())
for u in range(0,t):
size=int(raw_input())
A=map(int,raw_input().split())
idli=[0]*(size+1)
count=0
for k in A:
idli[k]+=1
count =count+k
if(count%size!=0):
print("-1")
else:
i=0
j=size
count=0
while i<j:
w... | vfc_43789 | {
"difficulty": "2",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n1 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7",
"output": "1\n-1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n4\n1 2 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7",
"output": "1\n-1\n-1\n",
... |
code_contests | verifiable_code | kjcc08 | Solve the following coding problem using the programming language python:
Clash of clans is a very popular game. Each player in the game is allocated a base with certain hit points the player can train a limited number of troops on the base. There are three types of troops: Barbarian, Archers and Giants. The Cost of t... | ```python
# cook your code here
def hitpoint(a,n,t):
i=0
h=0
while(i<n):
if(a[i]==1):
h+=t*1
elif(a[i]==2):
h+=t*2
else:
h+=t*3
i+=1
return h
#input size of army
n=int(raw_input())
#input the time in mins
t=int(raw_input())
#convertion... | vfc_43793 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n60",
"output": "300",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3\n2475",
"output": "7500",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input":... |
code_contests | verifiable_code | pairclst | Solve the following coding problem using the programming language python:
You are given a weighted graph with N nodes and M edges. Some of the nodes are marked as special nodes. Your task is to find the shortest pairwise distance between any two different special nodes.
Input
The first line of the input contains th... | ```python
INFINITY = 10**9+7
from heapq import *
def dijkstra(s):
global mini
q, seen = [(0, s)], set()
while q:
cost, v1 = heappop(q)
if v1 not in seen:
seen.add(v1)
if cost > mini:
break
if specials[v1] == 1:
if v1 != s:
mini = cost
break
for c, v2 in g[v1]:
if v2 not in seen:... | vfc_43797 | {
"difficulty": "3",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 8\n1 5 19",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 10\n1 5 19",
"output": "7\n",
... |
code_contests | verifiable_code | sque1 | Solve the following coding problem using the programming language python:
Problem description:
There are students in a class fighting for a girl. As she came to know she decided that the boy will win who will help her find out specific characters present in a given string is present either "even" or "odd" number of t... | ```python
testcase = input()
for i in range(0, testcase):
n, q = map(int, raw_input().split())
s = raw_input()
for j in range(0, q):
c, t = raw_input().split()
if(t == "even"):
if(s.count(c)%2 == 0):
print "yes"
else:
print "no"
else:
if(s.count(c)%2 == 1):
print "yes"
else:
print "... | vfc_43801 | {
"difficulty": "6",
"memory_limit": null,
"memory_limit_bytes": 0,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5 2\naaabb\na even\nb odd",
"output": "no\nno\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 2\naaabb\na even\nb odd",
"output": "no\nno\n",
"type": "stdin_stdout"
... |
code_contests | verifiable_code | 1006_E. Military Problem | Solve the following coding problem using the programming language python:
In this problem you will have to help Berland army with organizing their command delivery system.
There are n officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has ... | ```python
"""
Satwik_Tiwari ;) .
30th july , 2020 - Thursday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io impor... | vfc_43805 | {
"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": "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n",
"output": "3\n6\n8\n-1\n9\n4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1\n1 1\n",
"output": "1\n",
"type": "st... |
code_contests | verifiable_code | 102_D. Buses | Solve the following coding problem using the programming language python:
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All ... | ```python
a,b=map(int,input().split())
z=[]
g=10**9+7
def f():
return map(int,input().split())
if b==0:
print (0)
else:
s=set()
for i in range(b):
x,y=f()
z.append((x,y))
s.add(x)
s.add(y)
s.add (0)
s.add (a)
s = sorted(list(s))
a=len(s)-1
s=dict([(s[j... | vfc_43809 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 265000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n0 1\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"fn_... |
code_contests | verifiable_code | 1051_D. Bicolorings | Solve the following coding problem using the programming language python:
You are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white.
Two cells are considered neighbours if they have a common border and share the same color. Two cells A and B belong to the... | ```python
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self... | vfc_43813 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n",
... |
code_contests | verifiable_code | 1073_E. Segment Sum | Solve the following coding problem using the programming language python:
You are given two integers l and r (l ≤ r). Your task is to calculate the sum of numbers from l to r (including l and r) such that each number contains at most k different digits, and print this sum modulo 998244353.
For example, if k = 1 then ... | ```python
import sys
from array import array # noqa: F401
import typing as Tp # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
def main():
l, r, k = map(int, input().split())
valid_bits, is_valid_bits = [], [0] * 1024
for bit in range(1024):
if bin(bit).count(... | vfc_43817 | {
"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": "10 50 2\n",
"output": "1230",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1114_F. Please, another Queries on Array? | Solve the following coding problem using the programming language python:
You are given an array a_1, a_2, …, a_n.
You need to perform q queries of the following two types:
1. "MULTIPLY l r x" — for every i (l ≤ i ≤ r) multiply a_i by x.
2. "TOTIENT l r" — print \varphi(∏ _{i=l}^{r} a_i) taken modulo 10^9+7, whe... | vfc_43825 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 5, 'nanos': 500000000}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n5 9 1 2\nTOTIENT 3 3\nTOTIENT 3 4\nMULTIPLY 4 4 3\nTOTIENT 4 4\n",
"output": "1\n1\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n117 82 55 96\nMULTIPLY 1 3 100\nMULTIPLY 4 4... | |
code_contests | verifiable_code | 1143_B. Nirvana | Solve the following coding problem using the programming language python:
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.
Help Kurt find the maximum possible product of digits among all integers from 1 to n.
Input
The ... | ```python
l = list(int(c) for c in str(int(input())))
def prod(l):
p = 1
for d in l:
p *= max(d, 1)
return p
m = prod(l)
i = len(l) - 1
while i >= 0:
while i >= 0 and l[i] == 9:
i -= 1
if i < 0:
break
l[i] = 9
while i > 0 and l[i - 1] == 0:
l[i - 1] = 9
... | vfc_43829 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n",
"output": "7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000000000\n",
"output": "387420489",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1163_B2. Cat Party (Hard Edition) | Solve the following coding problem using the programming language python:
This problem is same as the previous one, but has larger 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 on... | ```python
n = int(input())
a = list(map(int,input().split()))
if(n == 1 or n == 2):
print(n)
exit()
notpar = 0
occ = [0 for i in range(10**5 + 1)]
base = 1
gotone = False
leader = -1
leadby = 0
best = 0
occ[a[0]] += 1
cnt = 1
at1 = 1
for i in range(1, n):
occ[a[i]] +=1
if(occ[a[i]] == 1):
... | vfc_43833 | {
"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\n10 100 20 200 1\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1201_C. Maximum Median | Solve the following coding problem using the programming language python:
You are given an array a of n integers, where n is odd. You can make the following operation with it:
* Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace it with a_i + 1).
You want to make th... | ```python
n , k =map(int,input().split())
arr = list(map(int,input().split()))
arr.sort()
def check(x):
moves = 0
for i in range(n//2,n):
if x - arr[i] > 0:
moves += x - arr[i]
if moves > k:
return False
if moves <= k:
return True
else:
return Fals... | vfc_43841 | {
"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 3 5\n",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 7\n4 1 2 4 3 4 4\n",
"output": "5",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1219_B. Xor Spanning Tree | Solve the following coding problem using the programming language python:
In the galaxy far far away is the ancient interplanetary republic of Bubbleland, consisting of N planets. Between them, there are M bidirectional wormholes, each connecting a pair of planets. Bubbleland is a very centralized republic, having a c... | vfc_43845 | {
"difficulty": "8",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\n4 1 5\n5 2 1\n6 3 2\n1 2 6\n1 3 3\n2 3 4\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "15 15\n5 6 18\n10 2 111\n8 3 57\n14 3 114\n13 11 84\n4 13 98\n3 2 15\n7 1 7... | |
code_contests | verifiable_code | 1243_B2. Character Swap (Hard Version) | Solve the following coding problem using the programming language python:
This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous p... | ```python
t = int(input())
def equal(s, t):
s = [x for x in s]
t = [x for x in t]
# diff = [x for x in range(len(s)) if s[x] != t[x]]
ans = []
for i in range(len(s)):
for j in range(i+1, len(s)):
if s[i] == s[j]:
s[j], t[i] = t[i], s[j]
ans.append... | vfc_43849 | {
"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\n1\n4 1\nNO\nNO\nYES\n3\n3 3\n3 1\n3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\nsouse\nhouhe\n3\ncat... |
code_contests | verifiable_code | 1263_A. Sweet Problem | Solve the following coding problem using the programming language python:
You have three piles of candies: red, green and blue candies:
* the first pile contains only red candies and there are r candies in it,
* the second pile contains only green candies and there are g candies in it,
* the third pile contai... | ```python
from math import ceil
for T in range(int(input())):
r , g , b = sorted(list(map(int ,input().split())))
t = b -g
if t >= r :
print(r +g)
else :
print(r + g - ceil((r-t)/2))
``` | vfc_43853 | {
"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\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n",
"output": "1\n2\n2\n10\n5\n9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 1 1\n1 2 1\n4 1 1\n7 7 10\n8 1 4\n8 2 8\n",
"output... |
code_contests | verifiable_code | 1284_D. New Year and Conference | Solve the following coding problem using the programming language python:
Filled with optimism, Hyunuk will host a conference about how great this new year will be!
The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i,... | ```python
import sys
input = sys.stdin.readline
import heapq
n=int(input())
C=[tuple(map(int,input().split())) for i in range(n)]
CA=[]
CB=[]
for ind,(a,b,c,d) in enumerate(C):
CA.append((a,0,ind))
CA.append((b,1,ind))
CB.append((c,0,ind))
CB.append((d,1,ind))
CA.sort()
CB.sort()
SMAX=[]
EMIN=[]... | vfc_43857 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 1024000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 2 4\n4 5 6 7\n3 4 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 1346_I. Pac-Man 2.0 | Solve the following coding problem using the programming language python:
Polycarp is developing a new version of an old video game "Pac-Man". Though he really enjoyed playing the original game, he didn't like some aspects of it, so he decided to alter the rules a bit.
In Polycarp's version, you play as Pac-Man and y... | vfc_43869 | {
"difficulty": "15",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 2 1\n3 1 2\n1 2\n2 1\n1 3\n3 1\n5 8\n",
"output": "\n1\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 7 4 2\n1 3 2 2 1\n2 3\n4 2\n3 4\n3 1\n1 4\n5 4\n4 5\n7 14 23 27\n",
"o... | |
code_contests | verifiable_code | 1368_G. Shifting Dominoes | Solve the following coding problem using the programming language python:
Bill likes to play with dominoes. He took an n × m board divided into equal square cells, and covered it with dominoes. Each domino covers two adjacent cells of the board either horizontally or vertically, and each cell is covered exactly once w... | vfc_43873 | {
"difficulty": "13",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 6\nULRUUU\nDUUDDD\nUDDLRU\nDLRLRD\nULRULR\nDLRDLR\n",
"output": "133\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 138_B. Digits Permutations | Solve the following coding problem using the programming language python:
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly.
Then Andrey got bored from looking at the same number and he started to swap digits firs... | ```python
import itertools
def countZeroes(s):
ret = 0
for i in s:
if i != '0':
break
ret += 1
return ret
def stupid(n):
ansMax = 0
bn1 = n
bn2 = n
for n1 in itertools.permutations(n):
for n2 in itertools.permutations(n):
val = str(int(''.joi... | vfc_43877 | {
"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": "500\n",
"output": "500\n500",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "198\n",
"output": "981\n819\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 140_F. New Year Snowflake | Solve the following coding problem using the programming language python:
As Gerald ..., in other words, on a New Year Eve Constantine prepared an unusual present for the Beautiful Lady. The present is the magic New Year snowflake that can make any dream come true.
The New Year snowflake consists of tiny ice crystals... | vfc_43881 | {
"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": "4 2\n0 0\n0 1\n1 0\n1 1\n",
"output": "5\n0.0 0.5\n0.5 0.0\n0.5 0.5\n0.5 1.0\n1.0 0.5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n0 0\n0 1\n1 0\n1 1\n",
"output": "-1\n",
... | |
code_contests | verifiable_code | 1431_C. Black Friday | Solve the following coding problem using the programming language python:
There is a local shop in your area getting prepared for the great holiday of Black Friday. There are n items with prices p_1, p_2, ..., p_n on the display. They are ordered by price, so p_1 ≤ p_2 ≤ ... ≤ p_n.
The shop has a prechosen discount v... | vfc_43885 | {
"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\n5 2\n1 3 4 6 7\n6 3\n1 2 3 4 5 6\n6 3\n3 3 4 4 5 5\n1 1\n7\n4 4\n1 3 3 7\n",
"output": "\n7\n4\n6\n7\n1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 1454_F. Array Partition | Solve the following coding problem using the programming language python:
You are given an array a consisting of n integers.
Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r.
Your task is to choose three positive (greater than 0) integers... | ```python
# Author : nitish420 --------------------------------------------------------------------
import math
import os
import sys
from io import BytesIO, IOBase
# mod=10**9+7
from collections import defaultdict
from bisect import bisect_left
def main():
for _ in range(int(input())):
n=int(input())
arr=list(map... | vfc_43889 | {
"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": "6\n11\n1 2 3 3 3 4 4 3 4 2 1\n8\n2 9 1 7 3 9 4 1\n9\n2 1 4 2 4 3 3 1 2\n7\n4 2 1 1 4 1 4\n5\n1 1 1 1 1\n7\n4 3 4 3 3 3 4\n",
"output": "\nYES\n6 1 4\nNO\nYES\n2 5 2\nYES\n4 1 2\nYES\n1 1 3\nYES\n2 1 4\n",
"type": "stdin... |
code_contests | verifiable_code | 1479_A. Searching Local Minimum | Solve the following coding problem using the programming language python:
This is an interactive problem.
Homer likes arrays a lot and he wants to play a game with you.
Homer has hidden from you a permutation a_1, a_2, ..., a_n of integers 1 to n. You are asked to find any index k (1 ≤ k ≤ n) which is a local minim... | ```python
from collections import deque
from typing import List
from sys import stdout
class ContestParser:
"""Helper module to read/write
Commonly in programming competition input for a problem is given with space separated numbers and strings.
Standard python input() functionality is clunky when dealin... | vfc_43893 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3\n2\n1\n4\n5\n",
"output": "\n? 1\n? 2\n? 3\n? 4\n? 5\n! 3\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 160_A. Twins | Solve the following coding problem using the programming language python:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it... | ```python
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
b = sum(a)//2
sum1 = count = 0
for i in a:
sum1+=i
count+=1
if sum1>b:
break
print(count)
``` | vfc_43905 | {
"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\n3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
code_contests | verifiable_code | 17_C. Balance | Solve the following coding problem using the programming language python:
Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations:
* to take two ad... | vfc_43909 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 128000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nabca\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nab\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | |
code_contests | verifiable_code | 202_D. Guess That Car! | Solve the following coding problem using the programming language python:
A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!".
The game show takes place on a giant parking lot... | ```python
from sys import stdin
def cum():
for i in range(n):
for j in range(m):
memr[i] += mat[i][j]
memc[j] += mat[i][j]
def findx():
x = [float('inf'), float('inf')]
for i in range(0, 4 * n + 1, 4):
tem = 0
for j in range(2, 4 * n + 1, 4):
t... | vfc_43913 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n3 4 5\n3 9 1\n",
"output": "392\n1 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 0 0 0\n0 0 3 0\n0 0 5 5\n",
"output": "240\n2 3",
"type": "stdin_stdout"
},
... |
code_contests | verifiable_code | 227_C. Flying Saucer Segments | Solve the following coding problem using the programming language python:
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).
The flying saucer, on which the brave pioneers set off, consists of three sections. These ... | ```python
def binpow(a,n):
res = 1
while(n>0):
if(n&1):
res = (res*a)%m
a = (a*a)%m
n>>=1
return res
n,m = map(int,input().split())
ans = binpow(3,n)-1
if(ans%m ==0 and ans != 0):
print(m-1)
else:
print(ans%m)
``` | vfc_43917 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 100\... |
code_contests | verifiable_code | 251_A. Points on Line | Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d... | ```python
from sys import stdin
a,b=map(int,stdin.readline().split());a+=1
z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0
r=lambda x:(x*(x+1))//2
while i<a:
if j<=i:j=i
while j<a and abs(z[j]-z[i])<=b:j+=1
if j-i-1>=2:ans+=r(j-i-2)
i+=1
print(ans)
``` | vfc_43921 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n-3 -2 -1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3\n1 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
code_contests | verifiable_code | 276_B. Little Girl and Game | Solve the following coding problem using the programming language python:
The Little Girl loves problems on games very much. Here's one of them.
Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:
* The players move in turns; In one m... | ```python
import sys
#sys.stdin = open('in', 'r')
#sys.stdout = open('out', 'w')
def Out(x):
sys.stdout.write(str(x) + '\n')
def In():
return sys.stdin.readline().strip()
def main():
s = str(input())
Map = {}
for word in s:
if word not in Map:
Map[word] = 1
else:... | vfc_43925 | {
"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": "aba\n",
"output": "First\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "abca\n",
"output": "Second\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
code_contests | verifiable_code | 322_B. Ciel and Flowers | Solve the following coding problem using the programming language python:
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
* To make a "red bouquet", it needs 3 red flowers.
* To make a "green bou... | ```python
a,b,c = map(int,input().split())
max_mix = min(a,b,c)
res = -99999999999999
for i in range (0,min(3,max_mix)+1):
pos = (i+(a-i)//3 + (b-i)//3 + (c-i)//3)
res=max(res,pos)
print(res)
``` | vfc_43933 | {
"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 6 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
code_contests | verifiable_code | 346_E. Doodle Jump | Solve the following coding problem using the programming language python:
In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. — Wikipedia.
It is a very popular game and xiaodao likes it very much. One day when playing the game she wond... | vfc_43937 | {
"difficulty": "11",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 2, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7 4 12 2\n7 1 9 4\n7 4 12 3\n",
"output": "NO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 1 2 1\n1 1 2 2\n1 1 2 3\n",
"output": "YES\nYES\nYES\n",
"type": ... | |
code_contests | verifiable_code | 370_A. Rook, Bishop and King | Solve the following coding problem using the programming language python:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by... | ```python
def benteng(x1,y1,x2,y2):
if(x1==x2 or y1==y2):
return 1
else:
return 2
def mentri(x1,y1,x2,y2):
if(abs(x1-x2)==abs(y1-y2)):
return 1
if((abs(x1-x2)+abs(y1-y2))%2==0):
return 2
return 0
def raja(x1,y1,x2,y2):
a=abs(x1-x2)
b=abs(y1-y2)
if(a>b):
... | vfc_43941 | {
"difficulty": "7",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5 5 6\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 3 1 6\n",
"output": "2 1 3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
code_contests | verifiable_code | 391_F1. Stock Trading | Solve the following coding problem using the programming language python:
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points.
Manao has developed a model to pred... | ```python
import sys
ammount_prices, days_for_trading=map(int, input().split())
stonks=[]
for i in range (0, ammount_prices):
price=int(sys.stdin.readline())
stonks.append(price)
def get_max(days_for_trading, stonks):
size_prices = len(stonks)
if size_prices == 0 or size_prices == 1 or days_for_tradi... | vfc_43945 | {
"difficulty": "12",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n",
"output": "15",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n",
"output": "21",
"type": "stdin_stdout"... |
code_contests | verifiable_code | 414_D. Mashmokh and Water Tanks | Solve the following coding problem using the programming language python:
Mashmokh is playing a new game. In the beginning he has k liters of water and p coins. Additionally he has a rooted tree (an undirected connected acyclic graph) that consists of m vertices. Each vertex of the tree contains a water tank that is e... | vfc_43949 | {
"difficulty": "10",
"memory_limit": null,
"memory_limit_bytes": 512000000,
"problem_url": null,
"time_limit": "{'seconds': 1, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 2 1\n1 2\n1 3\n3 4\n3 5\n2 6\n6 8\n6 7\n9 8\n8 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1000 1000\n1 2\n1 3\n3 4\n3 5\n",
"output": "4\n",
"type... | |
code_contests | verifiable_code | 441_B. Valera and Fruits | Solve the following coding problem using the programming language python:
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on ... | ```python
frukti_po_dnyam = {}
n, resurs =map(int,input().split(' '))
for i in range(n):
den, chislo_fruktov = map(int, input().split(' '))
if den in frukti_po_dnyam:
frukti_po_dnyam[den] += chislo_fruktov
else:
frukti_po_dnyam[den] = chislo_fruktov
if den + 1 not in frukti_po_dnyam:
... | vfc_43953 | {
"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 10\n3 20\n2 20\n1 20\n4 20\n5 20\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 5\n2 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
... |
code_contests | verifiable_code | 463_C. Gargari and Bishops | Solve the following coding problem using the programming language python:
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the... | ```python
import sys
input=sys.stdin.buffer.readline
t=1
for __ in range(t):
a=[]
n=int(input())
for i in range(n):
b=list(map(int,input().split()))
a.append(b)
dr={}
di={}
for i in range(n):
for j in range(n):
dr[i+j]=dr.get(i+j,0)+a[i][j]
di[... | vfc_43957 | {
"difficulty": "9",
"memory_limit": null,
"memory_limit_bytes": 256000000,
"problem_url": null,
"time_limit": "{'seconds': 3, 'nanos': 0}"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n",
"output": "12\n2 2 3 2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.