description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import sys
input = sys.stdin.readline
l = input().split()
n = int(l[0])
k = int(l[1])
curr = 0
hashi = dict()
a = [0]
for i in range(k):
for j in range(i, k):
if j == (i + 1) % k:
continue
if j == i:
a.append(i)
else:
a.append(j)
a.append(i)
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
ans = ""
for i in range(k):
ans += chr(97 + i)
for j in range(i + 1, k):
ans += chr(97 + i)
ans += chr(97 + j)
while len(ans) < n:
ans += ans
print(ans[:n]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def answer(n, k):
a = ""
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(k):
j = i
while True:
a += s[j]
j += 1
if j == k:
break
a += s[i]
m = k * k
return a * (n // m) + a[: n % m]
n, k = map(int, input().split())
pri... | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def dfs(v):
global s0
for u in range(k, 0, -1):
if gr[v][u] == 1:
gr[v][u] = 0
dfs(u)
s0 += [v]
s0 = []
n, k = map(int, input().split())
gr = [[(1) for _ in range(k + 1)] for _ in range(k + 1)]
dfs(1)
s = ""
for i in s0:
s += chr(i + 96)
i = 0
j = 0
while i < n:
if ... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBE... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
ans = ""
for i in range(k):
ans = ans + chr(i + 97)
for j in range(i + 1, k):
ans = ans + chr(i + 97) + chr(j + 97)
n1 = len(ans)
n2 = n // n1
n3 = n % n1
fin = ans * n2
fin = fin + ans[:n3]
print(fin) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
s = ""
for i in range(k):
s += chr(ord("a") + i)
for j in range(i + 1, k):
s += chr(ord("a") + i) + chr(ord("a") + j)
while len(s) < n:
s *= 2
print(s[:n]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR WHILE FUNC_CALL VAR VA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def solvee(n, k):
abc = "abcdefghijklmnopqrstuvwxyz"
if n == 1:
return "a"
if n < k:
return abc[:n]
lis = []
for x in range(0, k):
lis.append(abc[x])
for y in range(x + 1, k):
lis.append(abc[x] + abc[y])
ans = "".join(lis)
rem = n // len(ans)
a... | FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER RETURN STRING IF VAR VAR RETURN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIG... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().rstrip().split(" "))
alpha = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
s = ""
for i in range(k):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | a = list("abcdefghijklmnopqrstuvwxyz")
n, k = map(int, input().split())
if k >= n:
print(*a[0:n], sep="")
else:
ans = ""
for i in range(k):
ans += a[i]
for j in range(i + 1, k):
ans += a[i] + a[j]
while n > len(ans):
ans *= 2
print(ans[0:n]) | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CAL... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
x = []
for i in range(k):
x.append(i)
x.append(i)
for j in range(i + 2, k):
x.append(j)
x.append(i)
for i in range(k - 2, 0, -1):
x.append(i)
y = [chr(i + 97) for i in x]
ans = []
for i in range(n):
ans.append(y[... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = [int(i) for i in input().split()]
ans = ""
for x in range(k):
ans += chr(x + 97) * 2
for i in range(k):
for j in range(k):
tmp = chr(i + 97) + chr(j + 97)
if ans.find(tmp) == -1:
if len(ans) > 0:
if ans.find(ans[-1] + tmp[0]) == -1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
alphabet = "abcdefghijklmnopqrstuvwxyz"
s = ""
for i in range(k):
s += alphabet[i]
for j in range(i + 1, k):
s += alphabet[i] + alphabet[j]
blk = n // len(s)
small = n % len(s)
print(s * blk + s[:small]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR V... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def createks(k):
ks = ["a", "a"]
if k == 1:
return ks
ks = ["a", "a", "b", "b", "a"]
if k == 2:
return ks
msd = 2
while msd < k:
ks.extend([chr(ord("a") + msd), chr(ord("a") + msd - 1), chr(ord("a") + msd)])
for i in range(msd - 1):
ks.extend(chr(ord("... | FUNC_DEF ASSIGN VAR LIST STRING STRING IF VAR NUMBER RETURN VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING VAR NUMBER FUNC_CALL VAR BIN_... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def split(word):
return [char for char in word]
n, k = map(int, input().split())
a = [[] for j in range(26)]
a[0] = "a"
a[1] = "abb"
a[2] = "acbcc"
a[3] = "adbdcdd"
a[4] = "aebecedee"
a[5] = "afbfcfdfeff"
a[6] = "agbgcgdgegfgg"
a[7] = "ahbhchdhehfhghh"
a[8] = "aibicidieifigihii"
a[9] = "ajbjcjdjejfjgjhjijj"
a[10]... | FUNC_DEF RETURN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER S... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
l = []
for i in range(k):
for j in range(i, k):
l.append(chr(97 + i))
if i != j:
l.append(chr(97 + j))
if k == 1:
l.append("a")
a = len(l)
t = n // a
s = "".join(l)
print(s * t + s[: n % a]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def funMin(k):
pref, suff = "", ""
for i in range(ord("a"), ord("a") + k):
pref += chr(i) * 2
for j in range(i + 2, ord("a") + k):
suff += chr(i) + chr(j)
pref += suff
for i in range(ord("a") + k - 2, ord("a") - 1, -1):
pref += chr(i)
return pref
n, k = map(int,... | FUNC_DEF ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR STRING VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CAL... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | x, y = [int(a) for a in input().split()]
ar = [y - 1] * y
i = 0
s = ""
while len(s) < x:
s = s + chr(97 + i)
t = ar[i]
ar[i] = (ar[i] - 1 + y) % y
i = t
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR EXP... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
now = [i for i in range(k)]
ans = [0]
num = 0
for i in range(n - 1):
x = num
num = now[num]
ans.append(num)
now[x] += 1
now[x] %= k
a = ord("a")
ans = [chr(a + i) for i in ans]
print("".join(ans)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, m = list(map(int, input().split()))
ans = ""
kek = 97
bek = kek
while n > 0:
if kek == 97 + m:
kek = 97
if m > 1:
bek = kek + 1
else:
bek = kek
ans += chr(kek)
n -= 1
while n > 0 and bek < 97 + m:
ans += chr(kek)
n -= 1
if n > 0:
ans... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP NUMBER VAR VAR FUNC... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = tuple(map(int, input().split()))
alphabets = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
d = {}
for i in range(k):
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import sys
from sys import stdin
alp = "abcdefghijklmnopqrstuvwxyz"
n, k = map(int, stdin.readline().split())
s = []
for i in range(k):
for j in range(k - 1, i + 1, -1):
s.append(alp[i])
s.append(alp[j])
s.append(alp[i])
s.append(alp[k - 1])
for i in range(k - 2, -1, -1):
s.append(alp[i])
... | IMPORT ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR F... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
s = "abcdefghijklmnopqrstuvwxyz"
s = s[:k]
dic = {}
ans = ""
for i in range(k):
ans += chr(97 + i)
for j in range(i + 1, k):
ans += chr(97 + i) + chr(97 + j)
m = len(ans)
ans = ans * (n // m) + ans[: n % m]
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | s = []
n, k = list(map(int, input().split()))
for i in range(k):
s.append(chr(97 + i))
for j in range(i + 1, k):
s.append(chr(97 + i))
s.append(chr(97 + j))
sz = len(s)
for i in range(n):
print(s[i % sz], end="")
print() | ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
def solve(n, k):
strs = ascii_lowercase[:k]
if k == 1:
return "a" * n
s = ""
for i in range(k):
s += strs[i]
for j in range(i + 1, k):
s += strs[i]
s += strs[j]
len_s = len(s)
t = n // len_s + 1
... | ASSIGN VAR STRING FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER RETURN BIN_OP STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR FUNC_DEF ASSIGN ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
char = []
for i in range(k):
char.append(chr(ord("a") + i))
curr1 = 0
curr2 = 0
ans = ""
i = 0
while i < n:
ans += char[curr1]
curr1 = (curr1 + 1) % k
i += 1
if curr1 == 0:
curr2 = (curr2 + 1) % k
curr1 = curr2
elif i < n:
ans += char[curr... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def evaluate(s):
n = len(s)
res = 0
for i in range(n):
for j in range(i + 1, n - 1):
if s[i : i + 2] == s[j : j + 2]:
res += 1
return res
n, k = map(int, input().split())
alphabet = "abcdefghijklmnopqrstuvwxyz"[:k]
digrams = set()
res = ["a"]
for i in range(1, n):
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR ASSIGN VAR FUNC_CALL VAR... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
print("a", end="")
lis = []
for i in range(k):
ch = chr(ord("a") + i)
lis.append(ch)
for j in range(i - 1, -1, -1):
lis.append(ch)
lis.append(chr(ord("a") + j))
n -= 1
for i in range(n):
print(lis[i % len(lis)], end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = [int(x) for x in input().split()]
count = 0
while True:
for i in range(k):
for j in range(i, k):
if count <= n - 2:
if i != j:
print(chr(i + 97), end="")
count += 1
print(chr(j + 97), end="")
count += ... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBE... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
arr = [set(list(range(k))) for i in range(k)]
ans = [0]
val = "a"
for i in range(1, min(n, k**2)):
x = arr[ans[i - 1]].pop()
ans.append(x)
val += chr(97 + x)
if len(arr[ans[i - 1]]) == 0:
for j in range(len(arr)):
arr[j].discard(ans[i - 1])
val += "a"... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
u = []
for i in range(k):
u.append(i)
for j in range(i + 1, k):
u.append(i)
u.append(j)
L = len(u)
base = "".join(chr(a + ord("a")) for a in u)
s = base * ((n + L - 1) // L)
print(s[:n]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR V... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | def main():
N, K = map(int, input().split())
path = []
cur = [0] * 26
def dfs(u):
while cur[u] < K:
v = cur[u]
cur[u] += 1
dfs(v)
path.append(v)
dfs(0)
print("a", end="")
for i in range(N - 1):
print(chr(path[i % len(path)] + ... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NU... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
pat = []
for i in range(k):
pat.append("a")
for j in range(i, 0, -1):
pat.append(chr(j + ord("a")))
pat.append(chr(i + ord("a")))
ans = []
for i in range(n):
ans.append(pat[i % len(pat)])
print(*ans, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR F... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | rr = input
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))
n, k = rrm()
s = []
for i in range(k):
s.append(chr(97 + i))
for j in range(i + 1, k):
s.append(chr(97 + i))
s.append(chr(97 + j))
s = "".join(s)
loop = len(s)
curr = 0
while curr + loop < n:
print(s, end="")
c... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | from sys import stdin
input = stdin.readline
n, k = map(int, input().split())
st = ""
for i in range(k):
st += chr(97 + i)
for j in range(i + 1, k):
st += chr(97 + i) + chr(97 + j)
st = (st * (n // len(st) + 1))[:n]
print(st) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import itertools
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
string, ans = "abcdefghijklmnopqrstuvwxyz", ""
for i in range(k):
j = i
while True:
ans, j = ans + string[j], j + 1
if j == k:
break
ans += string[i]
while len(ans) < n:
ans *= 2
prin... | IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | from sys import stdin
input = stdin.readline
def solve(n, k):
ans = []
for c in range(k):
ans.append(chr(c + 97))
for i in range(1, k - c):
ans.append(chr(c + 97))
ans.append(chr(c + i + 97))
if len(ans) < n:
ans = ans * (n // len(ans) + 1)
ans = ans[:n... | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
s = ""
for x in range(97, 97 + k):
ch = chr(x)
s = s + ch
for j in range(x + 1, 97 + k):
s += ch + chr(j)
size = len(s)
while size < n:
s += s
size = len(s)
print(s[0:n]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR A... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)
def magic(N=26):
ans = [None] * (N + 1)
ans[1] = [(0, 0)]
for k in range(2, N + 1):
f = [(0, k - 1), (k - 1, k - 1), (k - 1, 0)]
for i, j in ans[k - 1]:
if i == j != 0:
f.a... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
ans = "a"
cycle = 1
tmp = ""
if k == 1:
print("a" * n)
elif k == 2:
tmp = "aabba"
if n <= 5:
print(tmp[:n])
else:
ans = tmp
n -= 5
while n >= 4:
ans += tmp[1:]
n -= 4
if n > 0:
ans += tmp[1 : 1 +... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
C = 97
p = [0] * k
out = ["a"]
F = k + k * (k - 1)
n -= 1
a_forbidden = False
for i in range(2, n + 2):
if not i % F:
a_forbidden = False
cur = ord(out[-1]) - C
if p[cur] == 0 and a_forbidden:
p[cur] += 1
out.append(chr(C + p[cur]))
p[cur] += 1
if... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CA... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | n, k = map(int, input().split())
c = "abcdefghijklmnopqrstuvwxyz"[:k]
unit = ""
for i in range(len(c)):
unit += c[i]
for j in range(i + 1, len(c)):
unit += c[i] + c[j]
for i in range(n // len(unit)):
print(unit, end="")
print(unit[: n % len(unit)]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR ... |
Let's define the cost of a string s as the number of index pairs i and j (1 ≤ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If... | import sys
def putin():
return map(int, sys.stdin.readline().split())
def sol():
n, k = putin()
n -= 1
G = {}
for i in range(k):
G[i] = list(range(k))
cur = 0
cycle = ""
while True:
try:
cycle += chr(ord("a") + (cur + G[cur][0]) % k)
add = G[cu... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR ... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | from sys import stdin
n, m = (int(x) for x in stdin.readline().split())
table = []
for _ in range(n):
table.append([int(x) for x in stdin.readline().split()])
def tr(l):
return list(map(list, zip(*l)))
def need_one_or_zero_swap(l):
swap = 2
for i, item in enumerate(l):
if item != i + 1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF V... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = map(int, input().split(" "))
a = []
for i in range(n):
a.append(list(map(int, input().split(" "))))
p = []
possible = True
col_swap = False
for r in a:
x = []
j = 0
swaps = []
while j < len(r) and len(swaps) < 3:
if r[j] != j + 1:
tmp = r[j]
r[j] = r[tmp - 1]
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CAL... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def chk(matrixx):
for row in matrixx:
count = 0
for i, val in enumerate(row):
if val != i + 1:
count += 1
if count > 2:
return False
return True
n, m = [int(x) for x in input().split()]
matrix = []
for i in range(n):
row = [int(x) for... | FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CAL... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = map(int, input().split())
a = [input().split() for _ in range(n)]
for l in range(m):
for r in range(l, m):
for s in a:
s1 = s.copy()
s1[l], s1[r] = s1[r], s1[l]
if sum(int(s1[i]) != i + 1 for i in range(m)) > 2:
break
else:
print... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = [int(i) for i in input().split()]
matr = []
for i in range(n):
matr.append([int(i) for i in input().split()])
inds = []
wrr = []
to_c = 0
wr_ = []
inds_ = []
wrr_ = []
to_c_ = 0
for i in matr:
ind = []
wr = []
stops = 0
for j in range(m):
if i[j] != j + 1:
ind.append(j + 1... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR LIST ASSIGN V... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = [int(i) for i in input().split()]
a = [[] for i in range(n)]
def sw(row, j1, j2):
tmp = a[row][j1]
a[row][j1] = a[row][j2]
a[row][j2] = tmp
for i in range(n):
a[i] = list(map(int, input().split()))
Can = False
for j in range(m):
for j2 in range(j, m):
fl = True
for ptr in ... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def difference(ln, k, l):
count = 0
line2 = ln[:]
line2[k], line2[l] = ln[l], ln[k]
for i in range(len(ln)):
if line2[i] != i + 1:
count += 1
return count
def difference2(ln):
count = 0
for i in range(len(ln)):
if ln[i] != i + 1:
count += 1
retur... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_C... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | __author__ = "Think"
def parse(row):
count = 0
problems = []
for i in range(1, m + 1):
if i != row[i - 1]:
count += 1
problems.append((i, row[i - 1]))
if count == 0:
return [0]
elif count == 2:
return [2, sorted((problems[0][0], problems[0][1]))]
... | ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER RETURN LIST NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMB... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = list(map(int, input().split()))
a = []
for i in range(n):
a.append(list(map(int, input().split())))
def check(x, y):
for i in range(n):
k = 0
for j in range(m):
if j == x:
if a[i][y] != j + 1:
k += 1
elif j == y:
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBE... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | from itertools import combinations
def main():
from itertools import combinations
n, m = map(int, input().split())
l = []
for _ in range(n):
row = list(map(int, input().split()))
l.append(sorted(range(m), key=row.__getitem__))
for i, j in [(0, 0), *combinations(range(m), 2)]:
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR ... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def no(k):
s = []
for j in range(len(k)):
if k[j] != j + 1:
s.append(j)
return s
def summ(k, n, i):
s = 0
for j in range(n):
s += k[j][i]
return s
def numcol(k, n):
d = 0
s = no(k[0])
for i in s:
if summ(k, n, i) == n * k[0][i]:
d +... | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP V... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def get_perms(perm):
perms = {tuple(perm)}
for i in range(len(perm)):
for j in range(i + 1, len(perm)):
perm_copy = list(perm)
perm_copy[i], perm_copy[j] = perm_copy[j], perm_copy[i]
perms.add(tuple(perm_copy))
return perms
n, m = list(map(int, input().split(" "... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL V... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | read = lambda: map(int, input().split())
n, m = read()
a = [list(read()) for i in range(n)]
b = [a[i][:] for i in range(n)]
flag = True
for i in range(n):
c = sorted(b[i])
d = b[i][:]
dif = sum(c[j] != d[j] for j in range(m))
if dif > 2:
flag = False
if flag:
print("YES")
exit()
for k1 i... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | from sys import exit, stdin, stdout
nm = [int(x) for x in stdin.readline()[:-1].split(" ")]
n = nm[0]
m = nm[1]
matrice = [[] for z in range(n)]
for i in range(n):
matrice[i] = [int(x) for x in stdin.readline()[:-1].split(" ")]
cancomplete = False
a = [[(0) for i in range(n)] for j in range(m)]
for colonna in rang... | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | N, M = map(int, input().split())
in_mat = [list(map(int, input().split())) for _ in range(N)]
orig = [list(range(1, M + 1)) for i in range(N)]
if M == 1:
print("YES")
exit()
def check():
for i in range(N):
cnt = 0
for j in range(M):
if orig[i][j] != in_mat[i][j]:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | I = lambda: map(int, input().split())
R = range
n, m = I()
t = [[] for _ in R(m)]
e = list(R(1, m + 1))
r = "NO"
for _ in R(n):
for i, v in zip(R(m), I()):
t[i] += [v]
for i in R(m):
for j in R(i, m):
t[i], t[j] = t[j], t[i]
if all(3 > sum(t[i][j] != e[i] for i in R(m)) for j in R(n)):
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR LIST VAR FO... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def check(table):
n = len(table)
m = len(table[0])
bits = [[(table[i][j] == j + 1) for j in range(m)] for i in range(n)]
for row in bits:
if row.count(False) > 2:
return False
return True
n, m = list(map(int, input().split()))
table = [list(map(int, input().split())) for i in r... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CAL... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def check(matrix, getindex=False, isfirst=False):
indices = set()
canbe = True
for row in matrix:
count = 0
for i, value in enumerate(row):
if value != i + 1:
indices.update([i])
count += 1
if count > 2:
canbe = False
if... | FUNC_DEF NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR RETURN FUNC_CALL VAR VAR RET... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = map(int, input().split())
iden = list(range(1, m + 1))
b = [[int(x) for x in input().split()] for _ in range(n)]
def run(board):
okay = True
for row in board:
s = 0
for x, y in zip(row, iden):
s += x != y
okay = okay and s in {0, 2}
return okay
okay = run(b)
fo... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | import sys
def swapC(c1, c2):
for r in range(n):
swap(r, c1, c2)
def swap(r, c1, c2):
nums[r][c1], nums[r][c2] = nums[r][c2], nums[r][c1]
def checkRow(r):
bad = []
for i in range(m):
if nums[r][i] != i:
bad.append(i)
if len(bad) == 0:
return True
if len(... | IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def GetListFromInput():
return list(map(int, input().split()))
def CloneMatrix(matrix):
return [list(row) for row in matrix]
def SwapColumns(matrix, i, j):
n = len(matrix)
for row in range(n):
matrix[row][i], matrix[row][j] = matrix[row][j], matrix[row][i]
def CanMatrixBeSorted(matrix):
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP ... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | from sys import stdin, stdout
def check():
global numbers
for z in range(n):
cnt = 0
chal = numbers[z][:]
for j in range(m):
if chal[j] != j + 1:
cnt += 1
for k in range(j + 1, m):
if chal[k] == j + 1:
chal[k],... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = [int(x) for x in input().split()]
L = [[int(x) for x in input().split()] for i in range(n)]
def solve(L):
D = {i: set() for i in range(n)}
for i in range(n):
for j in range(m):
if L[i][j] != j + 1:
D[i].add((min(j + 1, L[i][j]), max(j + 1, L[i][j])))
... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def judge():
n, m = list(map(int, input().split()))
num = [list(map(int, input().split())) for x in range(n)]
for i in range(m):
for j in range(m):
tmp = num[:]
for k in range(n):
tmp[k][i], tmp[k][j] = tmp[k][j], tmp[k][i]
cur = True
f... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASS... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def solve():
n, m = map(int, input().split())
tab = [list(map(int, input().split())) for _ in range(n)]
def ordered(l):
for i in range(len(l) - 1):
if l[i] > l[i + 1]:
return False
return True
def canswap(l):
if ordered(l):
return True
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR RETURN NUMB... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | import sys
n, m = list(map(int, input().split()))
g = [list(map(int, input().split())) for _ in range(n)]
for c1 in range(m):
for c2 in range(c1, m):
ok = True
for row in g:
row[c1], row[c2] = row[c2], row[c1]
cnt = 0
for i in range(m):
if row[i] ... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FU... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | import sys
n, m = list(map(int, input().split()))
inp = [input() for _ in range(n)]
mat = [[] for _ in range(m)]
for row in inp:
r = row.split()
for idx, val in enumerate(r):
mat[idx].append(int(val))
def valid(row):
count = 0
for idx, col in enumerate(mat):
if idx + 1 != col[row]:
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL ... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def batch_sort():
size_matrix = [int(x) for x in input().split(" ")]
matrix = []
for i in range(size_matrix[0]):
matrix.append([int(x) for x in input().split(" ")])
def check(m):
for row in m:
limit = 0
for i in range(size_matrix[1]):
if row[i] - ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def cntmisp(a):
return sum([int(a[i] != i + 1) for i in range(len(a))])
n, m = [int(x) for x in input().split(" ")]
a = []
for i in range(n):
a.append([int(x) for x in input().split(" ")])
cnts = [cntmisp(x) for x in a]
fl = 0
if max(cnts) <= 2:
print("YES")
else:
for p1 in range(m - 1):
for p... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = map(int, input().strip().split(" "))
g = [list(map(int, input().strip().split(" "))) for i in range(n)]
def check(a, b):
for row in g:
row[a], row[b] = row[b], row[a]
mis_placed = 0
for i in range(1, m + 1):
if row[i - 1] != i:
mis_placed += 1
row... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP V... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = list(map(int, input().split()))
table = [list(map(int, input().split())) for _ in range(n)]
everything = True
def swap(t, a, b):
t[a], t[b] = t[b], t[a]
return t
for i in range(m):
for j in range(m):
secend_table = [swap(k[:], i, j) for k in table[:]]
for row in range(n):
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | n, m = list(map(int, input().split()))
def f(a):
nonlocal c, k
c = []
k = 0
for i in range(m):
if a[i] - 1 != i:
k += 1
c.append(i)
c = []
bb = []
cc = []
k = 0
flag1 = True
flag = True
for i in range(n):
b = list(map(int, input().split()))
f(b)
if k > 2:
... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA... |
You are given a table consisting of n rows and m columns.
Numbers in each row form a permutation of integers from 1 to m.
You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ... | def gene(l):
d = {}
for i in range(len(l)):
if l[i] != i + 1:
d[i + 1] = l[i]
return d
def paired(d):
return tuple(sorted(zip(d.keys(), d.values())))
def exchange(d):
if len(d) in (0, 2):
yield paired(d)
for i in d:
if d[i] in d:
if d[d[i]] == ... | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VA... |
You are storing an integer array of length m in a database. To maintain internal integrity and protect data, the database stores n copies of this array.
Unfortunately, the recent incident may have altered the stored information in every copy in the database.
It's believed, that the incident altered at most two elemen... | def solvetestcase():
n, m = [int(e) for e in input().split(" ")]
db = []
for _ in range(n):
db.append([int(e) for e in input().split(" ")])
return solve_helper(n, m, db)
def solve_helper(n, m, db, start=True):
found_candidate = -1
max_diffs = 0
for i in range(1, n):
diffs =... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR ... |
You are storing an integer array of length m in a database. To maintain internal integrity and protect data, the database stores n copies of this array.
Unfortunately, the recent incident may have altered the stored information in every copy in the database.
It's believed, that the incident altered at most two elemen... | N, M = map(int, input().split())
A = []
for i in range(N):
a = list(map(int, input().split()))
for j in range(M):
A.append(a[j])
ans = A[:M]
for i in range(1, N):
cnt = 0
lis = []
for j in range(M):
if ans[j] != A[i * M + j]:
lis.append((j, A[i * M + j]))
cnt ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CA... |
You are storing an integer array of length m in a database. To maintain internal integrity and protect data, the database stores n copies of this array.
Unfortunately, the recent incident may have altered the stored information in every copy in the database.
It's believed, that the incident altered at most two elemen... | def solve():
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
c = []
row = 0
for i in range(1, n):
c1 = []
for j in range(m):
if a[0][j] != a[i][j]:
c1.append(j)
if len(c1) > len(c):
c = c1
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF ... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | import sys
input = sys.stdin.readline
def solve():
n, x = map(int, input().split())
arr = list(map(int, input().split()))
mi, ma = min(arr), max(arr)
if n <= 2:
return max(ma, x) - 1
val = 0
for i in range(n - 1):
val += abs(arr[i] - arr[i + 1])
if mi <= 1 <= x <= ma:
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for t in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
rs = 0
for i in range(n - 1):
rs += abs(a[i + 1] - a[i])
c, d = max(a), min(a)
if x > c:
rs += min(2 * (x - c), x - a[0], x - a[-1])
if 1 < d:
rs += min(2 * ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | t = int(input())
for _ in range(t):
n, x = map(int, input().split())
L = list(map(int, input().split()))
m1 = min(L)
m2 = max(L)
ans = 0
for i in range(1, n):
ans += abs(L[i] - L[i - 1])
ans += min(2 * (m1 - 1), abs(L[0] - 1), abs(L[-1] - 1))
if x > m2:
ans += min(2 * (x ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | t = int(input())
for i in range(t):
n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
min_a = min(a)
max_a = max(a)
cur_sum = 0
for theta in range(n - 1):
cur_sum += abs(a[theta + 1] - a[theta])
if max_a < x:
val1 = 2 * (x - max_a)
val2 = x - ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER V... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for t in range(int(input())):
n, x = map(int, input().split())
L = list(map(int, input().split()))
M = max(L)
m = min(L)
sum = 0
if m <= 1 and M >= x:
L.append(L[-1])
for i in range(n):
sum += abs(L[i + 1] - L[i])
elif m <= 1:
L.append(L[-1])
for i... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL ... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | t = int(input())
for _ in range(t):
n, x = map(int, input().split())
a = list(map(int, input().split()))
dif, mini, maxi = 0, a[0], a[0]
for i in range(n - 1):
dif += abs(a[i] - a[i + 1])
mini = min(mini, a[i + 1])
maxi = max(maxi, a[i + 1])
dif += min(mini * 2 - 2, a[0] - 1,... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | import sys
input = sys.stdin.readline
def solve():
n, x = map(int, input().split())
arr = list(map(int, input().split()))
if n <= 2:
return max(max(arr), x) - 1
val = 0
mi, ma = arr[-1], arr[-1]
for i in range(n - 1):
val += abs(arr[i] - arr[i + 1])
mi = min(arr[i], mi... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | if True:
t = int(input())
for _ in range(t):
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
if a[0] > a[-1]:
a.reverse()
s = 0
for i in range(n - 1):
s += abs(a[i] - a[i + 1])
min_a = min(a)
max_a = max(a... | IF NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR F... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | T = int(input())
for t in range(T):
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
mi, ma, c, p1, p2 = a[0], a[0], 0, 1, 1
for i in range(1, n):
c += abs(a[i] - a[i - 1])
mi = min(mi, a[i])
ma = max(ma, a[i])
if mi == a[0] or mi == a[n - 1]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL ... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for i in range(int(input())):
n, x = map(int, input().split())
A = [int(k) for k in input().split()]
a = min(A)
b = max(A)
d = 0
for k in range(1, n):
d += abs(A[k] - A[k - 1])
C = 0
B = 0
if a > 1:
C = min(abs(A[0] - 1), abs(A[-1] - 1))
C = min(C, 2 * abs(a -... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for time in range(int(input())):
n, x = map(int, input().split())
nums = list(map(int, input().split()))
if n == 1:
print(max(x - 1, nums[0] - 1, x - nums[0]))
continue
s = 0
mini = float("inf")
maxi = 0
for j in range(n - 1):
s += abs(nums[j] - nums[j + 1])
i... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | cases = int(input())
for case in range(cases):
n, x = map(int, input().split())
nums = list(map(int, input().split()))
diff = 0
for i in range(n - 1):
diff += abs(nums[i] - nums[i + 1])
min_val = min(nums)
max_val = max(nums)
if x > max_val:
diff += min((x - max_val) * 2, x -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CA... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | N = int(input())
for _ in range(N):
n, m = input().split(" ")
nums = input().split(" ")
n, m = int(n), int(m)
nums = [int(x) for x in nums]
ans = 0
_min = min(nums)
_max = max(nums)
for i in range(1, n):
ans += abs(nums[i] - nums[i - 1])
if 1 < _min:
ans += min(nums[0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, a = map(int, input().split())
l = list(map(int, input().split()))
d = 0
for i in range(n - 1):
d = d + abs(l[i + 1] - l[i])
x = min(l)
y = max(l)
if n == 1:
if l[0] <= a:
print(a - 1)
... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER V... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for t in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
small = min(a)
large = max(a)
ans = 0
ans += min(abs(a[0] - 1), abs(a[-1] - 1), 2 * abs(small - 1))
if large < x:
ans += min(abs(a[0] - x), abs(a[-1] - x), 2 * abs(large - x))
for i... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | T = int(input())
for cid in range(T):
N, X = map(int, input().split())
A = list(map(int, input().split()))
mn, mx = min(A), max(A)
a = 2 * (mn - 1)
b = max(0, 2 * (X - mx))
F = min(
a + b,
a + min(abs(X - A[0]), abs(X - A[-1])),
b + min(abs(1 - A[0]), abs(1 - A[-1])),
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_O... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | def main():
n, x = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
min_a = min(a)
ans_max = max(0, (x - max_a) * 2)
ans_min = (min_a - 1) * 2
min_ = a[-1]
max_ = a[0]
if a[0] < a[-1]:
min_ = a[0]
max_ = a[-1]
ans_min = min(ans_min, min... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASS... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | for _ in range(int(input())):
n, x = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
co = 0
if n == 1:
co = max(x, l[0]) - 1
else:
a, b = min(l), max(l)
for i in range(1, n):
co += abs(l[i] - l[i - 1])
if a > 1:
co... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CA... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | def solve():
n, x = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
ans = 0
prev = arr[0]
for num in arr[1:]:
ans += abs(num - prev)
prev = num
lowest = min(arr)
highest = max(arr)
if lowest > 1:
ans += min(2 * (lowest - 1), abs(arr[0] - ... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR FUNC_CALL ... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | t = int(input())
while t:
t -= 1
n, x = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = int(1e18)
cur = 0
for i in range(0, len(l) - 1):
cur += abs(l[i] - l[i + 1])
for i in range(2):
mn = abs(l[0] - 1)
ans = min(ans, cur + (x - 1) + abs(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VA... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | t = int(input())
for j in range(t):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ce = min((x - max(a)) * 2, x - a[0], x - a[-1])
pe = min((min(a) - 1) * 2, a[0] - 1, a[-1] - 1)
if ce < 0:
ce = 0
extra = pe + ce
cost = 0
for i in range(len(a) - 1):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CAL... |
You are given a sequence of $n$ integers $a_1, a_2, \dots, a_n$. You are also given $x$ integers $1, 2, \dots, x$.
You are asked to insert each of the extra integers into the sequence $a$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence... | def task(n, x, a):
total = 0
for i in range(n - 1):
total += abs(a[i] - a[i + 1])
mn = min(a)
mx = max(a)
start = a[0]
end = a[-1]
if mn > 1:
total += min(2 * (mn - 1), abs(start - 1), abs(end - 1))
if mx < x:
total += min(2 * (x - mx), abs(x - start), abs(x - end... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.