code stringlengths 46 24k | language stringclasses 6
values | AST_depth int64 3 30 | alphanumeric_fraction float64 0.2 0.75 | max_line_length int64 13 399 | avg_line_length float64 5.01 139 | num_lines int64 7 299 | task stringlengths 151 14k | source stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|
INF = 10000000000.0
max_n = 50
max_k = 2000
def main():
(n, s, k) = map(int, input().split())
s -= 1
buf = [''] * (max_n + 1)
dp = [[0 for i in range(max_n + 1)] for j in range(max_k + 1)]
r = list(map(int, input().split()))
c = input()
answer = INF
for i in range(len(c)):
buf[i] = c[i]
for i in range(k, -1... | python | 24 | 0.500559 | 63 | 20.829268 | 41 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
(n, s, k) = map(int, input().split())
s -= 1
r = list(map(int, input().split()))
INF = float('inf')
c = input()
dp = [[] for i in range(n)]
def calc(u):
if dp[u]:
return
dp[u] = [0] * (r[u] + 1) + [INF] * (k - r[u])
for i in range(n):
if c[u] != c[i] and r[i] > r[u]:
calc(i)
d = abs(u - i)
for j in ran... | python | 17 | 0.472656 | 49 | 19.48 | 25 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
import math
def solve():
(n, s, k) = map(int, input().split())
s -= 1
r = list(map(int, input().split()))
c = input()
inf = int(1000000000.0)
dp = [[inf for j in range(n)] for i in range(k + 1)]
for i in range(0, k + 1):
for j in range(0, n):
if i == 0 or i <= r[j]:
dp[i][j] = 0
continue
for K i... | python | 21 | 0.495741 | 64 | 20.740741 | 27 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
INF = 100000
(n, s, k) = list(map(int, input().split()))
r = list(map(int, input().split()))
c = input().rstrip()
dp = [[INF for j in range(k + 1)] for i in range(n)]
s -= 1
for i in range(n):
dp[i][k - r[i]] = abs(s - i)
for j in range(k, -1, -1):
for i in range(n):
if dp[i][j] >= INF:
continue
for f in range... | python | 15 | 0.516522 | 62 | 22 | 25 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
(n, s, k) = map(int, input().split())
r = list(map(int, input().split()))
s -= 1
c = input()
best = [[0 for i in range(n)] for j in range(k + 1)]
for i in range(1, k + 1):
for j in range(n):
if i <= r[j]:
best[i][j] = abs(j - s)
else:
good = float('inf')
for l in range(n):
if c[j] != c[l] and r[j] > r... | python | 21 | 0.498943 | 53 | 23.894737 | 19 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
import sys
sys.setrecursionlimit(1000)
def rec(r, c, s, K, k, dp):
if (k, s) in dp:
return dp[k, s]
if k <= 0:
return 0
n = len(r)
besttime = 10 ** 10
for i in range(n):
if r[i] > r[s] and c[i] != c[s] or k == K:
timetakenbelow = rec(r, c, i, K, k - r[i], dp)
timetaken = timetakenbelow + abs(s - i)
... | python | 14 | 0.569672 | 51 | 20.529412 | 34 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
INF = 10000000000.0
(n, s, k) = map(int, input().split())
r = list(map(int, input().split()))
r.append(0)
col = input()
mat = []
for i in range(n + 1):
adj = {}
for j in range(n):
if i == n:
adj[j] = abs(s - 1 - j)
elif col[i] != col[j] and r[i] < r[j]:
adj[j] = abs(i - j)
mat.append(adj)
mem = [{} for i i... | python | 14 | 0.525424 | 40 | 18.175 | 40 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
import sys
def minp():
return sys.stdin.readline().strip()
dp = [None] * 50
for j in range(50):
dp[j] = [None] * 2001
(n, s, k) = map(int, minp().split())
a = [None] * n
i = 0
s -= 1
for j in map(int, minp().split()):
a[i] = (j, i)
i += 1
i = 0
for j in minp():
a[i] += ('RGB'.find(j),)
i += 1
a.sort()
r = 10 ** ... | python | 17 | 0.46384 | 46 | 16.434783 | 46 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
inf = 10000
(n, s, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(input())
for i in range(n):
if b[i] == 'R':
b[i] = 0
elif b[i] == 'G':
b[i] = 1
else:
b[i] = 2
boxes = [[a[i], b[i], i] for i in range(n)]
boxes.sort()
l = boxes[-1][0] * n + 1
s -= 1
dp = [[[inf, s, -1] for j in ran... | python | 18 | 0.484536 | 87 | 22.658537 | 41 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
(n, s, k) = list(map(int, input().split()))
amounts = list(map(int, input().split()))
colors = list(input())
dp = [[-1 for j in range(k + 1)] for i in range(n)]
def getAns(nth, left):
if left <= 0:
return 0
if dp[nth][left] >= 0:
return dp[nth][left]
ret = 999999999
for i in range(n):
if amounts[i] <= amount... | python | 14 | 0.595 | 61 | 25.086957 | 23 | There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is ... | taco |
def sub(maxs, mins):
for i in range(len(maxs)):
if maxs[i] != mins[i]:
if i == len(maxs) - 1:
return int(maxs[i]) - int(mins[i])
if i == len(maxs) - 2:
return int(maxs[i:i + 2]) - int(mins[i:i + 2])
return 10
return 0
def checkEqual(S):
ans = 8
for k in range(1, len(S)):
if len(S) % k != 0:
... | python | 16 | 0.523995 | 50 | 19.837838 | 37 | If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your ... | taco |
n = input()
length = len(n)
ans = 10
lst = []
ind = 0
while ind < length:
if n[ind] == '1' and ind + 1 <= length - 1:
lst.append(int(n[ind:ind + 2]))
ind += 2
else:
lst.append(int(n[ind]))
ind += 1
if len(lst) >= 2:
ans = min(ans, max(lst) - min(lst))
divisors = []
for i in range(1, length // 2 + 1):
if len... | python | 13 | 0.557809 | 44 | 19.541667 | 24 | If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your ... | taco |
import heapq
from math import sqrt
import operator
import sys
inf_var = 0
if inf_var == 1:
inf = open('input.txt', 'r')
else:
inf = sys.stdin
input = inf.readline
def read_one_int():
return int(input().rstrip('\n'))
def read_list_of_ints():
res = [int(val) for val in input().rstrip('\n').split(' ')]
return res
... | python | 14 | 0.605769 | 60 | 20.185185 | 54 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
for _ in range(t):
n = int(input())
p = list(map(int, input().split()))
ans = []
p1 = [-1] * (n + 1)
for i in range(n):
p1[p[i]] = i
i = n
while i:
while i > 0 and p1[i] == -1:
i -= 1
else:
if i:
k = 0
for j in range(p1[i], n):
ans.append(p[j])
p1[p[j]] = -1
k ... | python | 16 | 0.427441 | 36 | 14.791667 | 24 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
def get_list_string():
return list(map(str, sys.stdin.readline().strip().split()))
def get_string():
return sys.stdin.readline().strip()
def get_int():
r... | python | 15 | 0.568918 | 60 | 18.303571 | 56 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
from heapq import heappop, heappush
import sys
class MinMaxSet:
def __init__(self):
self.min_queue = []
self.max_queue = []
self.entries = {}
def __len__(self):
return len(self.entries)
def add(self, val):
if val not in self.entries:
entry_min = [val, False]
entry_max = [-val, False]
heappush(... | python | 14 | 0.601681 | 49 | 20.25 | 56 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
w = list(map(int, input().split()))
d = [0] * (n + 1)
for (i, j) in enumerate(w):
d[j] = i
(a, x) = ([], n)
for i in range(n, 0, -1):
if d[i] < x:
a.extend(w[d[i]:x])
x = d[i]
print(' '.join(map(str, a)))
| python | 13 | 0.501629 | 36 | 20.928571 | 14 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
def argmax(a):
m = 0
res = []
for j in range(len(a)):
if a[j] > m:
m = a[j]
res.append(j)
res.reverse()
return res
def find():
end = int(input())
mas = list(map(int, input().split()))
for j in argmax(mas):
for k in range(j, end):
print(mas[k], end=' ')
end = j
print()
for i in range(int(input()... | python | 13 | 0.548193 | 38 | 15.6 | 20 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
for i in range(t):
n = int(input())
p = list(map(int, input().split()))
p_ord = p.copy()
p_ord.sort()
k = n - 1
r = list()
for j in range(n - 1, -1, -1):
while p_ord[k] == 0:
k -= 1
maximo = p_ord[k]
p_ord[p[j] - 1] = 0
if p[j] == maximo:
r.extend(p[j:])
del p[j:]
print(' '.joi... | python | 13 | 0.485119 | 36 | 18.764706 | 17 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
A = []
def test_case():
n = int(input())
a = [int(i) for i in input().split()]
mp = dict()
for i in range(n):
mp[a[i]] = i
(ans, last) = ([], n)
for i in range(n, 0, -1):
if mp[i] <= last:
ans.extend(a[mp[i]:last])
last = mp[i]
A.append(ans)
for _ in range(int(input())):
test_case()
for a in A:
prin... | python | 13 | 0.518405 | 38 | 17.111111 | 18 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
while t > 0:
t -= 1
n = int(input())
ar = [int(op) for op in input().split()]
ans = []
y = [0 for i in range(n)]
mx = n
nmx = n
ops = n
while not nmx == 0:
for i in reversed(range(ops)):
if y[i] == 0:
mx = i + 1
y[i] = 1
ops = i
break
for i in reversed(range(nmx)):
if... | python | 15 | 0.488565 | 41 | 16.814815 | 27 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
look = [0] * n
maxx = arr[0]
for i in range(n):
maxx = max(arr[i], maxx)
look[i] = maxx
j = n
ans = []
for i in range(n - 1, -1, -1):
if look[i] == arr[i]:
ans.append(arr[i:j])
j = i
for i in ans:
print(*i, end='... | python | 13 | 0.510511 | 38 | 18.588235 | 17 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
N = int(input())
for _ in range(N):
out = []
n = int(input())
l = [int(e) for e in input().split()]
i = 0
for j in range(i, n):
if l[j] > l[i]:
out += l[i:j][::-1]
i = j
out += l[i:n][::-1]
print(' '.join([str(e) for e in out[::-1]]))
| python | 13 | 0.452 | 45 | 19.833333 | 12 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
from collections import OrderedDict
import heapq as hq
def show(l):
for i in l:
print(i, end=' ')
for _ in range(int(input())):
n = int(input())
r = []
l = list(map(int, input().split()))
t = [(j, i) for (i, j) in enumerate(l)]
t.sort(reverse=True)
od = OrderedDict(t)
idx = n
for e in l[::-1]:
m = next(it... | python | 13 | 0.56391 | 40 | 18 | 21 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import math
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = {}
ans = []
for i in range(n):
b[a[i]] = i
flag = n
for j in range(n, 0, -1):
if b[j] <= flag:
for k in range(b[j], flag):
ans.append(a[k])
flag = b[j]
print(*ans)
| python | 13 | 0.515789 | 36 | 18 | 15 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
from collections import deque
t = int(input())
for _ in range(t):
c = int(input())
stack = list(map(int, input().split()))
ans = deque()
flag = 0
greatest = stack[0]
for i in range(1, c):
if greatest < stack[i]:
ans.extendleft(reversed(stack[flag:i]))
flag = i
greatest = stack[i]
ans.extendleft(revers... | python | 14 | 0.631579 | 42 | 23.066667 | 15 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
while t > 0:
t -= 1
n = int(input())
a = list(map(int, input().split()))
ans = []
r = [0] * (n + 1)
for i in range(n):
r[a[i]] = i
k = n
for i in range(n, 0, -1):
if r[i] <= k:
for j in range(r[i], k):
ans.append(a[j])
k = r[i]
print(*ans)
| python | 13 | 0.457143 | 36 | 16.5 | 16 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split(' ')))
ans = []
temp = []
Greater = [arr[0]]
for k in range(1, n):
if Greater[k - 1] > arr[k]:
Greater.append(Greater[k - 1])
else:
Greater.append(arr[k])
for j in range(len(arr) - 1, -1, -1):
if arr[j] != Greater[... | python | 13 | 0.536036 | 41 | 21.2 | 20 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
quant_testes = int(input())
for c in range(quant_testes):
output = ''
tam = int(input())
seq = [int(n) for n in input().split()]
posicoes = [None] * tam
for i in range(len(seq)):
posicoes[-seq[i]] = i
for pos in posicoes:
if pos + 1 <= tam:
output += str(seq[pos])
output += ' '
for i in range(pos + 1... | python | 14 | 0.553398 | 40 | 21.888889 | 18 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
T = int(input())
for t in range(T):
n = int(input())
pi = list(map(int, input().split()))
r = []
t = [0] * len(pi)
t[0] = pi[0]
for i in range(1, len(pi)):
t[i] = max(t[i - 1], pi[i])
index = len(pi) - 1
lastIndex = len(pi)
while index >= 0:
while index >= 0 and pi[index] != t[index]:
index -= 1
if pi... | python | 13 | 0.531178 | 45 | 21.789474 | 19 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
li = list(map(int, input().split()))
bigs = [0]
current_max = li[0]
for i in range(1, n):
if li[i] > current_max:
current_max = li[i]
bigs.append(i)
bigs = reversed(bigs)
ans = []
for start in bigs:
for j in range(sta... | python | 13 | 0.601604 | 37 | 19.777778 | 18 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
import os.path
from collections import *
import math
import bisect
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
else:
input = sys.stdin.readline
t = int(input())
while t:
t -= 1
n = int(input())
p = [int(x) for x in input().split()]
arr = [0] ... | python | 11 | 0.615234 | 43 | 20.333333 | 24 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
n = int(input())
for i in range(n):
m = int(input())
a = list(map(int, input().split()))
maxrest = [0 for i in range(m)]
for j in range(1, m):
if a[j] > a[maxrest[j - 1]]:
maxrest[j] = j
else:
maxrest[j] = maxrest[j - 1]
rest = m
while rest != 0:
newrest = maxrest[rest - 1]
for j in range(newrest, r... | python | 13 | 0.558583 | 36 | 21.9375 | 16 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
for j in range(t):
ans = dict()
k = int(input())
d = list(map(int, input().split()))
ma = d[0]
ans[0] = ma
for i in range(1, k):
if d[i] > ma:
ma = d[i]
ans[i] = ma
ans = list(reversed(ans.keys()))
b = []
end = len(ans)
for i in range(end):
p = ans[i]
b += d[p:k]
k = p
print(*b... | python | 13 | 0.496894 | 36 | 15.947368 | 19 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
input = sys.stdin.readline
def solve():
n = int(input())
arr = list(map(int, input().split()))
S = set()
mv = n
tmp = []
ans = []
for i in range(n - 1, -1, -1):
tmp.append(arr[i])
S.add(arr[i])
if arr[i] == mv:
while tmp:
ans.append(tmp.pop())
while mv in S:
mv -= 1
return ans
fo... | python | 14 | 0.547945 | 38 | 16.380952 | 21 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for s in [*open(0)][2::2]:
(*l,) = map(int, s.split())
a = []
j = len(l)
a = []
L = [0]
for i in range(1, j):
if l[L[-1]] < l[i]:
L += [i]
else:
L += [L[-1]]
while j:
i = L[j - 1]
a += l[i:j]
j = i
print(*a)
| python | 13 | 0.37069 | 28 | 13.5 | 16 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
li = list(map(int, input().split()))
tmp = [0] * (n + 1)
res = []
for i in range(n):
tmp[li[i]] = i
k = n
for i in range(n, 0, -1):
if tmp[i] <= k:
for j in range(tmp[i], k):
res.append(li[j])
k = tmp[i]
print(*res)
| python | 13 | 0.494737 | 37 | 19.357143 | 14 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
from sys import stdin
lst = list(map(int, stdin.read().split()))
_s = 0
def inp(n=1):
global _s
ret = lst[_s:_s + n]
_s += n
return ret
def inp1():
return inp()[0]
t = inp1()
for _ in range(t):
n = inp1()
c = inp(n)
new = []
for i in range(n):
if len(new) and c[i] < new[-1][0]:
new[-1].append(c[i])
el... | python | 13 | 0.535714 | 42 | 14.555556 | 27 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
a = [0] * n
t = []
for i in range(n):
a[arr[i] - 1] = i
f = n + 1
for i in range(len(a) - 1, -1, -1):
if a[i] > f:
continue
t.append(arr[a[i]:f])
f = a[i]
for i in range(len(t)):
for j in range(len(t[i])):
print... | python | 13 | 0.488506 | 38 | 19.470588 | 17 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
def take_second(elem):
return elem[0]
q = int(input())
while q > 0:
n = int(input())
a = input().split()
a = [int(x) for x in a]
list = []
i = 0
while i < n:
if i == 0 or a[i] > a[i - 1]:
list.append([a[i]])
list[-1].append(i)
i += 1
list = sorted(list, key=take_second)
b = [0 for i in range(n)]
ans... | python | 13 | 0.493359 | 37 | 16.566667 | 30 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
def solve(arr, size):
positions = [0] * size
for j in range(size):
positions[arr[j] - 1] = j
K = [positions[size - 1]]
for j in range(size - 2, -1, -1):
if positions[j] < K[-1]:
K.append(positions[j])
result = [0] * size
right = size
pos = 0
for left in K:
for j in range(right - left):
result[pos] =... | python | 11 | 0.564547 | 38 | 20.625 | 24 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
asc = set(a)
e = n
o = []
for i in range(n, 0, -1):
if i in asc:
for j in range(e - 1, -1, -1):
if a[j] == i:
for k in a[j:e]:
asc.remove(k)
... | python | 16 | 0.497396 | 47 | 20.333333 | 18 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
look = [0] * n
look[0] = a[0]
for i in range(1, n):
look[i] = max(look[i - 1], a[i])
j = n
ans = []
for i in range(n - 1, -1, -1):
if look[i] == a[i]:
ans.extend(a[i:j])
j = i
print(*ans)
| python | 13 | 0.489655 | 36 | 19.714286 | 14 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import sys
input = sys.stdin.readline
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque
def ceil(U, V):
return (U + V - 1) // V
def modf1(N, MOD):
return (N - 1) % MOD + 1
inf = int(1e+18)
mod = int(1000000000.0 + 7)
t = in... | python | 13 | 0.619808 | 51 | 19.866667 | 30 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
import os
import sys
from io import BytesIO, IOBase
def main():
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
p = [a[0]]
for i in range(1, n):
p.append(max(p[-1], a[i]))
b = [0] * (n + 1)
for (i, v) in enumerate(a):
b[v] = i
ans = []
i = n - 1
while p:
j... | python | 17 | 0.627209 | 72 | 25.671429 | 70 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = []
c = [0 for j in range(n)]
d = n
e = n
for j in range(n - 1, -1, -1):
c[a[j] - 1] = 1
if a[j] == d:
b += a[j:e]
e = j
while d > 0 and c[d - 1] == 1:
d -= 1
b += a[:e]
print(*b)
| python | 13 | 0.424658 | 36 | 17.25 | 16 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
k = []
d = {}
for i in range(len(l)):
d[l[i]] = i
t = int(n)
for i in range(n, 0, -1):
if d[i] <= t:
for j in range(d[i], t):
k.append(l[j])
t = d[i]
print(*k)
| python | 13 | 0.471698 | 36 | 17.928571 | 14 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
def card(n, arr):
ind = [0] * n
temp = n
ans = []
for i in range(n):
ind[arr[i] - 1] = i
for i in ind[::-1]:
if i < temp:
ans += arr[i:temp]
temp = i
return ans
for i in range(int(input())):
a = int(input())
lst = list(map(int, input().strip().split()))
print(*card(a, lst))
| python | 15 | 0.530612 | 46 | 18.6 | 15 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
dic = {}
result = []
for i in range(n):
dic[l[i]] = i
temp = n
for i in range(n, 0, -1):
if dic[i] < temp:
result.extend(l[dic[i]:temp])
temp = dic[i]
print(*result)
| python | 13 | 0.539326 | 36 | 19.538462 | 13 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
t = int(input())
for _ in range(t):
n = int(input())
dec = list(map(int, input().split()))
dic = {}
for i in range(n):
dic[dec[i]] = i
covered_till = n
new_dec = []
for i in range(n, 0, -1):
if dic[i] < covered_till:
new_dec += dec[dic[i]:covered_till]
covered_till = dic[i]
print(*new_dec)
| python | 13 | 0.563107 | 38 | 21.071429 | 14 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
from collections import defaultdict
for _ in range(int(input())):
n = int(input())
v = list(map(int, input().split()))
cnt = 0
j = n - 1
i = n - 1
cur_max = n
temp = []
while cnt < n:
while v[i] != cur_max:
temp.append(v[i])
i -= 1
temp.append(v[i])
temp.sort(reverse=True)
flag = 1
for x in rang... | python | 14 | 0.504505 | 36 | 18.588235 | 34 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
for _ in range(int(input())):
n = int(input())
ps = list(map(int, input().split()))
dp = [ps[0]]
for i in range(1, n):
dp.append(max(dp[-1], ps[i]))
res = []
j = n - 1
temp = [ps[-1]]
for i in range(n - 2, -1, -1):
if dp[i] == dp[i + 1]:
temp.append(ps[i])
else:
res += temp[::-1]
temp = [ps[i]]
... | python | 13 | 0.481481 | 37 | 19.647059 | 17 | You have a deck of $n$ cards, and you'd like to reorder it to a new one.
Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bottom card, $p_n$ is the top card.
In each step you pick some integer $k > 0$... | taco |
End of preview. Expand in Data Studio
This dataset contains deduplicated solution data from TACO dataset, 107k LeetCode problem solutions and an additional 73k CodeForces solutions in Python, Java, C++ from this link.
Filtering strategy:
- AST parsability: we extracted only the AST parsable codes
- AST Depth: only samples with depth from 2.0 to 31.0
- Maximum Line Length: only samples with a maximum of 12.0 to 400.0 characters
- Average Line Length: only samples with 5.0 to 140.0 characters on average
- Alphanumeric Fraction of samples greater than 0.2 and less than 0.75
- Number of Lines: from 6.0 to 300.0
- Language Filter: samples whose docstring scores an English language confidence greater than 99% by the
lingualanguage detector - Deduplication: samples MinHash deduplicated using a shingle size of 8 and a similarity threshold of 0.8
- Downloads last month
- 6