description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
n, m = list(map(int, input().split())) s, d, c = list(), list(), list() for i in range(m): si, di, ci = list(map(int, input().split())) s.append(si - 1) d.append(di - 1) c.append(ci) s, d, c, num = zip(*sorted(list(zip(s, d, c, list(range(m)))), key=lambda x: x[1])) exam_num = [(-1) for _ in range(n)] f...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CAL...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
def update(si, ei, di, lst, i, ee): cur = si cnt = 0 while cnt < di and cur < ei: if lst[cur] == 0: lst[cur] = i + 1 cnt += 1 cur += 1 lst[ei] = ee + 1 return True if cnt >= di else False n, e = map(int, input().split()) lst = [0] * n fl = True query = [] fo...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR L...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
rd = lambda: map(int, input().split()) n, m = rd() a = sorted(([*rd()] + [i + 1] for i in range(m)), key=lambda x: x[1]) r = [0] * n for x in a: r[x[1] - 1] = m + 1 for i in range(x[0] - 1, x[1] - 1): if not r[i]: r[i] = x[3] x[2] -= 1 if not x[2]: bre...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
n, m = map(int, input().split()) ls = [(0) for i in range(n)] prep = [] order = [] for i in range(m): s, d, c = map(int, input().split()) ls[d - 1] = m + 1 prep.append([s, d, c]) order.append([d, i]) order.sort() for i in range(n): if ls[i] == 0: for j in range(m): if prep[order[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR LI...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
l = input().split() n = int(l[0]) m = int(l[1]) l = [] hashipapers = dict() curr = [(0) for i in range(m)] for i in range(m): lo = input().split() s = int(lo[0]) d = int(lo[1]) c = int(lo[2]) hashipapers[d - 1] = i, c l.append((d - 1, s - 1, c, i)) l.sort() lfi = [] poss = 1 for i in range(n): ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
def main(): n, m = map(int, input().split()) a = [] ans = [0] * n for i in range(m): x, y, z = map(int, input().split()) ans[y - 1] = m + 1 a.append([y - 1, x - 1, z, i + 1]) a.sort() for i in range(m): count = 0 for j in range(a[i][1], a[i][0]): ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
def sol(): n, m = list(map(int, input().split())) arr = [] for d in range(m): preArr = list(map(int, input().split())) preArr[0] -= 1 preArr[1] -= 1 arr.append(preArr) out = [m] * n for i in range(n): ind = 999999999999999 exm = False exmDate =...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL 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 VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMB...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
f = lambda: map(int, input().split()) n, m = f() t = [] p = [0] * (n + 1) for i in range(1, m + 1): s, d, c = f() if p[d]: exit(print(-1)) p[d] = m + 1 t.append((i, s, d, c)) t.sort(key=lambda q: q[2]) for i, s, d, c in t: while c: if not p[s]: p[s] = i c -= 1...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
from sys import stdin input = stdin.buffer.readline n, m = map(int, input().split()) exams = [] for i in range(m): s, d, c = map(int, input().split()) exams.append((i, s, d, c)) exams.sort(key=lambda x: x[2]) dp = [-1] + [0] * n for i in exams: dp[i[2]] = m + 1 flag = False for exam in exams: s = exam[...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR ...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
n, m = [int(i) for i in input().split()] s = [0] * m d = [0] * m c = [0] * m for i in range(m): s[i], d[i], c[i] = [(int(j) - 1) for j in input().split()] c[i] += 1 if d[i] - s[i] < c[i]: print(-1) quit() ans = [0] * n for i in d: ans[i] = m + 1 exam = [] for i in range(n): exam.appe...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
n, m = map(int, input().split()) res = [] ans = [0] * (n + 1) ind = [0] * (n + 1) for i in range(m): s, d, c = map(int, input().split()) ind[d] = i + 1 res.append([d, s, c]) res.sort() flag = 0 for i in range(m): [d, s, c] = res[i] j = s ex = ind[d] ans[d] = m + 1 while c > 0 and j < d: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR...
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ β€” the day, when questions for the $i$-th exam will be published, $d_...
T = input().split(" ") n = int(T[0]) m = int(T[1]) L = [0] * n M = [] D = [0] * m F = [0] * m for i in range(m): S = input().split(" ") a = int(S[0]) b = int(S[1]) c = int(S[2]) L[b - 1] = m + 1 F[i] = b - 1 M.append((a - 1, b - 2, i + 1)) D[i] = c M.sort() for i in range(n): if L[i]...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input()) for i in range(T): counter = {} string = input().strip() for char in string: counter[char] = counter.get(char, 0) + 1 chars = list(counter.keys()) chars.sort() if len(chars) == 2 and abs(ord(chars[0]) - ord(chars[1])) == 1: print("No answer") elif ( l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_C...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import sys T = int(input()) for t in range(T): q = True s = input() n = len(s) a = [] b = [] x = [] for i in range(n): o = ord(s[i]) if o % 2 == 0: a.append(o) else: b.append(o) if len(a) == 0 or len(b) == 0: print(s) q = F...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input()) for i in range(T): s = list(input()) s.sort() k = len(s) s1 = [] s3 = [] s2 = [0] * 150 pro = True for j in range(k): s2[ord(s[j])] += 1 for j in range(97, 123, 2): if s2[j] > 0: s3 += [chr(j)] * s2[j] for j in range(98, 123, 2): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) ss = [] for i in range(n): ss.append(input()) for i in range(n): s = ss[i] f = [ord(a) for a in s] s_even = sorted([x for x in f if x % 2 == 0]) s_odd = sorted([x for x in f if x % 2 == 1]) if s_even == []: print("".join(map(chr, s_odd))) elif s_odd == []: pr...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input().strip()) for y in range(T): st = input().strip() l = [] for k in range(26): l.append(0) for i in range(0, len(st)): l[ord(st[i]) - ord("a")] += 1 nlist = [] for k in range(26): x = 0 if l[k]: nlist.append(k) if len(nlist) == 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST FOR VAR FUNC_CA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input()) for _ in range(T): s = list(input()) s.sort() groups = [] letter = s[0] count = 1 for c in s[1:]: if letter == c: count += 1 else: groups.append((ord(letter), count)) letter = c count = 1 groups.append((ord(lett...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
alphabetlist = [ "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", ] dic = {i: e for e, i in enumerate(alphabetlist)} for _ in range(int...
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 VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR AS...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): line = input() items = sorted([(x * line.count(x)) for x in set(line)]) for start in range(len(items)): copy = items[:] string = copy.pop(start) while copy: for i in range(len(copy)): if abs(ord(copy[i][0]) - ord(string[-1])) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = sorted(input()) a = b = "" for e in s: if ord(e) % 2: a += e else: b += e f = 0 p = "0" for e in a + b: if abs(ord(e) - ord(p)) == 1: f |= 1 p = e p = "0" for e in b + a: if abs(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def ok(k): t = True for i in range(len(k) - 1): t &= abs(ord(k[i]) - ord(k[i + 1])) != 1 return t n = int(input()) for i in range(n): f = list(input()) odd = [] even = [] h = len(f) for i in range(h): if ord(f[i]) % 2 != 0: odd.append(f[i]) else: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST AS...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): s = input() a = [(0) for j in range(26)] c = [] for x in s: a[ord(x) - 97] += 1 for j in range(len(a)): if a[j] != 0: c.append(j) b = len(c) d = b // 2 if b == 1: print(s) elif b == 2: flag = True ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): s = input() s = sorted(s) t = s[0] k = len(s) - 1 j = 0 cnt = 0 k = 0 asd = len(s) while cnt < asd: if j + 1 >= len(s): break if s[j + 1] == t[-1]: t = t + s[j + 1] j += 1 k = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def parse(): n = int(input()) inp = [] for _ in range(n): inp.append(input()) return inp def recurse(prev, s): s = "".join(s) if len(s) == 1: if not prev or abs(ord(prev) - ord(s)) != 1: return s else: return None for l in s: if not p...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN NONE FOR VAR VAR IF VAR FUNC...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(u): for i in range(len(u) - 1): if abs(ord(u[i]) - ord(u[i + 1])) == 1: return False return True t = int(input()) for _ in range(t): s = input() cnt = {chr(i): (0) for i in range(ord("a"), ord("z") + 1)} for x in s: cnt[x] += 1 s = sorted(list(set(list(s))...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
gi = lambda: list(map(int, input().strip().split())) for k in range(gi()[0]): s = list(input()) ans = [] s.sort() ans.append(s.pop(0)) flag = False while s: flag = True for j in range(len(s)): if abs(ord(s[j]) - ord(ans[-1])) != 1: ans.append(s.pop(j))...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def solve(s): ans = [] c_count = [0] * 26 for c in s: c_count[ord(c) - ord("a")] += 1 conflicts = [ (c_count[i - 1] + c_count[(i + 1) % len(c_count)]) for i in range(len(c_count)) ] conflicts[0] -= c_count[-1] conflicts[-1] -= c_count[0] last = max( range(len(conf...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = input().strip() arr = [(0) for __ in range(26)] for c in s: arr[ord(c) - ord("a")] += 1 s = "" for i in range(26): if arr[i]: s += chr(i + ord("a")) else: s += " " srr = s.split() if len(srr) == 1 and 2 <= len(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR STRING ASSI...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for t in range(int(input())): s = str(input()) l = set(s) p = "" l = list(l) l.sort() i = 0 while i < len(l): p += l[i] i += 2 i = 1 p1 = "" while i < len(l): p1 += l[i] i += 2 ans = "" if len(p) >= 1 and len(p1) >= 1: if abs(ord(p[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): x = input().strip() c = [0] * 26 for i in x: c[ord(i) - ord("a")] += 1 i = 0 s = "" for i in range(0, 26, 2): s += chr(i + ord("a")) * c[i] tf = "" for i in range(1, 26, 2): tf += chr(i + ord("a")) * c[i] if len(tf) == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) a = [] for i in range(t): a.append(input()) for i in a: c = [] for j in i: c.append(j) k = list(set(c)) k.sort() s = "" t = "" for j in range(len(k)): if j % 2 == 0: s += k[j] * c.count(k[j]) else: t += k[j] * c.count(k[j])...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BI...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = input() s = sorted(s) a = "" b = "" for i in s: if ord(i) % 2: a = a + i else: b = b + i if len(a) == 0: print(b) elif len(b) == 0: print(a) elif abs(ord(a[-1]) - ord(b[0])) != 1: print(a + ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EX...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for k in range(int(input())): a = sorted(input()) s1 = "" s2 = "" for i in a: if ord(i) % 2: s1 += i else: s2 += i ans1 = s1 + s2 ans2 = s2 + s1 flag = 0 for i in range(1, len(ans1)): if abs(ord(ans1[i]) - ord(ans1[i - 1])) == 1: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) while t > 0: s = input() l1 = [] l2 = [] l3 = [] for i in range(len(s)): if ord(s[i]) % 2 == 0: l1.append(s[i]) else: l2.append(s[i]) l1.sort() l2.sort() l3 = l2 + l1 l1 = l1 + l2 flag = 0 for i in range(1, len(l1)): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BI...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
from sys import stdin inp = lambda: stdin.readline().strip() t = int(inp()) for _ in range(t): s = inp() alpha = [0] * 26 for i in s: alpha[ord(i) - 97] += 1 current = 0 flag = False for i in range(26): ans = [] ansLen = 0 if alpha[i] > 0: current = i...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = [0] * 26 for i in input(): s[ord(i) - 97] += 1 n = 26 - s.count(0) l = sum(s) def chkMask(mask, n, s, l): p = 0 for i in range(26): if s[i] > 0: for j in range(n): if mask[j] == p: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
alpha = list("abcdefghijklmnopqrstuvwxyz") d = {alpha[i]: i for i in range(26)} def isok(string): L = len(string) if any(abs(d[string[i]] - d[string[i + 1]]) == 1 for i in range(L - 1)): return False return True def solve(): s = list(input()) odd = [] even = [] for i, v in enumer...
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import sys def unique(lst): return dict((o, o) for o in lst).values() class Main: def __init__(self): self.buff = None self.index = 0 def next(self): if self.buff is None or self.index == len(self.buff): self.buff = self.next_line() self.index = 0 ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR F...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = input() x = list(map(lambda t: ord(t) - ord("a"), list(s))) if len(set([(i % 2) for i in x])) == 1: print(s) continue odd = [i for i in x if i % 2 == 0] even = [i for i in x if i % 2 == 1] odd.sort() even.sort() if abs(odd[-1] - even[0]) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for _ in range(t): s = input() s1 = s2 = "" for i in s: if ord(i) % 2 == 0: s1 += i else: s2 += i s1 = sorted(s1) s2 = sorted(s2) if len(s1) == 0: print("".join(s2)) elif len(s2) == 0: print("".join(s1)) elif abs(or...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
numQueries = int(input()) inputArray = [] for i in range(numQueries): inputArray.append(input()) def f(ordNumber, repetition): return chr(ordNumber + 96) * repetition def resultOfQuery(string): numberOfRepitition = {} for c in string: ordC = ord(c) - 96 if ordC in numberOfRepitition:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) si = lambda: input() n = ii() o = [] c = 0 def check(s1, s2): ss = s1 + s2 for i in range(len(ss)): if i != len(ss) - 1: if ord(ss[i]) + 1 == ord(ss[i + 1]) or ord(ss[i]) - 1 == ord(ss[i + 1]): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
testcase = int(input()) for i in range(testcase): string = [int(ord(i)) for i in input()] string.sort() even = [] odd = [] for i in string: if (i - 96) % 2 == 1: odd.append(i) else: even.append(i) if len(odd) == 0: print("".join(map(chr, even))) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(odd, even): count = 0 arr = odd + even for i in range(len(arr) - 1): if abs(ord(arr[i]) - ord(arr[i + 1])) == 1: count += 1 return count q = int(input()) for i in range(q): arr1 = [] arr2 = [] a = input() for h in a: if ord(h) % 2 == 0: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIG...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = sorted(input()) a = [] b = [] for e in s: w = ord(e) if w % 2: a += [w] else: b += [w] f = p = 0 for e in a + b: if abs(e - p) == 1: f |= 1 p = e p = 0 for e in b + a: if...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR VAR NUMBER FOR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR A...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for case in range(int(input())): str = sorted(input()) x = "" y = "" for char in str: if ord(char) % 2 == 0: x += char else: y += char if len(y) == 0: print(x) continue if len(x) == 0: print(y) continue if ( abs(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input()) for i in range(T): s = input() d = {} for c in s: if c in d: d[c] += 1 else: d[c] = 1 a = list(d.keys()) a = sorted(a) if len(a) == 1: print(a[0] * d[a[0]]) continue if len(a) == 2: if ord(a[1]) - ord(a[0]) == 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF FUN...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(s): for i in range(1, len(s)): if abs(ord(s[i]) - ord(s[i - 1])) == 1: return False return True def main(): t = int(input()) for _ in range(t): s = input() odd_str, even_str = [], [] for c in s: if ord(c) % 2: odd_str.ap...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP F...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def solve(s): odd = "" even = "" x = [] y = [] for char in s: if ord(char) % 2 == 1: x.append(char) else: y.append(char) x = sorted(x) y = sorted(y) x.reverse() y.reverse() odd = "".join(x) even = "".join(y) if len(x) == 0: ...
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) c = 26 for _ in range(t): s = list(input()) s.sort() n = len(s) u = [0] * c for i in range(n): u[ord(s[i]) - ord("a")] += 1 w = 0 d = [] p = [] for i in range(c): if u[i] != 0: w += 1 d.append(chr(i + ord("a"))) p.a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(s): s = list(s) s.sort() a1 = [] a2 = [] c = 0 cur = s[0] for i in range(len(s)): if s[i] != cur: c ^= 1 cur = s[i] if c == 0: a1.append(s[i]) else: a2.append(s[i]) a = "".join(a1[::-1] + a2[::-1]) for ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for w in range(t): arr = [(0) for i in range(26)] s = input() l = len(s) for i in range(l): arr[ord(s[i]) - ord("a")] += 1 even = "" for i in range(26): if i % 2 == 0: even += chr(ord("a") + i) * arr[i] for i in range(26): if i % 2 == 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUM...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): s = input() a = [ch for ch in s if ord(ch) % 2 == 1] b = [ch for ch in s if ord(ch) % 2 == 0] a.sort() b.sort() if len(a) == 0 or len(b) == 0: print("".join(a + b)) else: ax = [a, a[::-1]] bx = [b, b[::-1]] done = 0 for x ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL S...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(str): for i in range(0, len(str) - 1): if ( ord(str[i]) + 1 == ord(str[i + 1]) or i > 0 and ord(str[i - 1]) == ord(str[i]) + 1 ): return False return ord(str[-2]) != ord(str[-1]) + 1 def solve_for(str): if len(str) == 1: ret...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DE...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def position(a): if a == "a": return 1 if a == "b": return 2 if a == "c": return 3 if a == "d": return 4 if a == "e": return 5 if a == "f": return 6 if a == "g": return 7 if a == "h": return 8 if a == "i": return...
FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): s = list(input().rstrip()) n = len(s) a = [] b = [] for i in range(n): if ord(s[i]) % 2 == 1: a.append(s[i]) else: b.append(s[i]) a.sort() b.sort() if len(a) == 0 or len(b) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) for _ in range(n): s = input() ans = [] thing = {} for i in s: ans.append(i) ans.sort() chars = [] for i in ans: if i in thing: thing[i] += 1 else: thing[i] = 1 chars.append(i) if len(thing) == 2 and ord(ans[0])...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def func(a): l = len(a) odd = [] even = [] for i in range(l): x = ord(a[i]) - 65 if x % 2 == 0: even.append(a[i]) else: odd.append(a[i]) even.sort() odd.sort() a1 = "".join(even) + "".join(odd) a2 = "".join(odd) + "".join(even) flag = 0...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL STRING VAR FUNC_CALL STRING V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): s = input() n = len(s) d = dict() for j in range(26): d[j] = "" for j in range(n): d[ord(s[j]) - ord("a")] += s[j] s1, s2 = "", "" for j in range(0, 26, 2): s1 += d[j] for j in range(1, 26, 2): s2 += d[j] if s1 == ""...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR STRING STRING FOR VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
q = int(input()) for _ in range(q): word = input() dic = {} for l in word: if l in dic: dic[l] += 1 else: dic[l] = 1 if len(dic) == 1: print(word) elif len(dic) == 2: k = list(dic.keys()) k.sort() if ord(k[0]) + 1 == ord(k[1]): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
from itertools import groupby IMP = "No answer" for _ in range(int(input())): s = input() s1 = ["".join(x[1]) for x in groupby(sorted(s), lambda c: c)] if len(s1) >= 4: print("".join(s1[1::2] + s1[::2])) elif len(s1) == 1: print(*s1) else: s2 = [ord(c1[0]) for c1 in s1] ...
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): string = input() odd = [] even = [] a = ord("a") for j in range(len(string)): if (ord(string[j]) - a) % 2 == 0: even.append(string[j]) else: odd.append(string[j]) even = sorted(even) odd = sorted(odd) if len(even...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def valid(s): n = len(s) if n == 1: return True for i in range(1, n): if abs(ord(s[i]) - ord(s[i - 1])) == 1: return False return True def solve(): result = [] for _ in range(int(input())): s = sorted(input()) half1 = [] half2 = [] tu...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check_condition(string): flag = 0 for i in range(len(string) - 1): diff = abs(ord(string[i]) - ord(string[i + 1])) if diff == 1: flag = 1 break return flag t = int(input()) for i in range(t): even = "" odd = "" string = input() for c in string: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIG...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import itertools t = int(input()) for tt in range(t): s = input() h = {} for c in s: if c in h: h[c] += 1 else: h[c] = 1 res = "" ss = sorted(list(set(s))) l = ss[0 : len(ss) // 2] r = ss[len(ss) // 2 : len(ss)] l_c = 0 r_c = 0 if len(ss) ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
abc = "abcdefghijklmnopqrstuvwxyz" abc2 = abc zyx2 = abc2[::-1] t = int(input()) for query in range(t): s = input() odd = [letter for letter in s if ord(letter) % 2 == 1] even = [letter for letter in s if ord(letter) % 2 == 0] if len(odd) == 0 or len(even) == 0: print(s) else: odd.so...
ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBE...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
from itertools import groupby def solve(ltr): if len(ltr) == 1: print(ltr[0][0] * ltr[0][1]) elif len(ltr) == 2: if ord(ltr[1][0]) == ord(ltr[0][0]) + 1: print("No answer") else: print(ltr[0][0] * ltr[0][1], end="") print(ltr[1][0] * ltr[1][1]) e...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER STRING EXPR FUNC_CALL VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def construct(uniq): cst = [] for i in range(1, len(uniq), 2): cst.append(uniq[i]) for i in range(0, len(uniq), 2): cst.append(uniq[i]) return cst T = int(input()) for t in range(T): s = input() uniq = [] dc = {} for c in s: num = ord(c) if ord(c) in dc:...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) def good(s): for i in range(1, len(s)): if abs(ord(s[i]) - ord(s[i - 1])) == 1: return False return True for i in range(t): s = input() count = {} for c in s: if c not in count: count[c] = 0 count[c] += 1 out = "" alpha = "...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUM...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for _ in range(t): s = input() d = {} for c in s: try: d[c] += 1 except: d[c] = 1 i = "a" an = "" while i <= "z": try: if d[i] > 0: for j in range(d[i]): an += i except: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR STRING IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def solve(s): cs = [x for x in s] cs.sort() r1, r2 = "", "" alpha1 = [chr(x) for x in range(ord("a"), ord("z") + 2, 2)] alpha2 = [chr(x) for x in range(ord("b"), ord("z") + 2, 2)] for c in alpha1: if s.count(c) != 0: r1 += str(c) * s.count(c) for c in alpha2: if s...
FUNC_DEF ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER FOR VAR VAR IF FUNC_...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) while t > 0: t = t - 1 A = input() st1 = "" st2 = "" arr = [0] * 26 for i in range(len(A)): ind = ord(A[i]) - ord("a") arr[ind] += 1 for i in range(0, 26, 2): st1 += chr(ord("a") + i) * arr[i] for i in range(1, 26, 2): st2 += chr(ord("a") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
alp = list("abcdefghijklmnopqrstuvwxyz") t = int(input()) for i in range(t): s = list(input()) dic = {} for item in s: if item not in dic: dic[item] = 1 else: dic[item] += 1 tot = [0] * len(s) tot = [] for j in range(0, 26, 2): if alp[j] in dic: ...
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER I...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(s): return all( ord(s[i]) != ord(s[i - 1]) + 1 and ord(s[i]) != ord(s[i - 1]) - 1 for i in range(1, len(s)) ) for _ in range(int(input())): s = input() n = len(s) s = sorted(s) s1 = "" s2 = "" for i in s: if ord(i) - 97 & 1: s1 += i ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def do(s): if len(s) == 1: print(s[0]) return start = 0 while start < len(s): if start == len(s) - 2: break if abs(ord(s[start + 1]) - ord(s[start])) == 1: start += 1 toreplace = len(s) - 1 s.insert(start, s[toreplace]) ...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
T = int(input()) for i in range(0, T): s = input() temp = 0 pos = [0] * 26 for j in range(0, len(s)): pos[ord(s[j]) - 97] = pos[ord(s[j]) - 97] + 1 st = "" L1 = [] L2 = [] for j in range(0, len(pos), 2): if pos[j] != 0: L1.append((chr(j + 97), pos[j])) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING AS...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): s = input() ch = [] nec = [] for i in range(len(s)): if (ord(s[i]) - ord("a")) % 2 == 0: ch.append(ord(s[i]) - ord("a")) else: nec.append(ord(s[i]) - ord("a")) ch.sort() nec.sort() a = len(ch) b = len(nec) an...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for test in range(t): S = input() L = list(S) Noanswer = 0 L1 = [ord(k) for k in L] D = [[x, L1.count(x)] for x in set(L1)] D.sort(key=lambda x: x[0]) if len(D) > 4: Dleft = [] Dright = [] for k in range(len(D)): if k % 2 == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR L...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) def ok(a, b): if abs(ord(a[len(a) - 1]) - ord(b[0])) == 1: return False else: return True for i in range(n): s = input() par = [] nepar = [] for j in s: if ord(j) % 2 == 0: par.append(j) else: nepar.append(j) par.so...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER E...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
t = int(input()) for i in range(t): x = list(input()) y = {f: x.count(f) for f in x} z = sorted(y.keys()) n = len(z) rer = [""] * n if n == 3: rer = z j = 0 k = 1 if abs(ord(z[1]) - ord(z[2])) != 1: j = 1 k = 2 aide = rer[j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) for _ in range(n): word = sorted(input()) odd_part, even_part = "", "" for i in word: if ord(i) % 2 == 0: even_part += i else: odd_part += i previous = "0" output = 0 for i in odd_part + even_part: if abs(ord(i) - ord(previous)) ==...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
dic = {} te = "abcdefghijklmnopqrstuvwxyz" for i in range(1, 27): dic[te[i - 1]] = i for _ in range(int(input())): st = input() dicount = {} for i in st: dicount[i] = dicount.get(i, 0) + 1 ke = list(dicount.keys()) ke.sort() le = len(ke) if le == 1: print(ke[0] * dicount[...
ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
for _ in range(int(input())): no_ans = False ans = [] s = input() c = list(sorted(set(s))) if len(c) == 1: ans = [c[0]] elif len(c) == 2: if ord(c[1]) - ord(c[0]) == 1: no_ans = True else: ans = [c[0], c[1]] elif len(c) == 3: if ord(c[2...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSI...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
from itertools import groupby as gb Q = int(input()) for _ in range(Q): s = input() g = gb(sorted(list(s))) l = [0] * 26 for k, v in g: l[ord(k) - ord("a")] = len(list(v)) p, q = "", "" for i, j in enumerate(l[1::2]): p += chr(ord("a") + i * 2 + 1) * j for i, j in enumerate(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING STRING FO...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import sys n = int(input()) lines = sys.stdin.readlines() res = [] for line in lines: line = line.strip() odd = dict() even = dict() s = [] fail = False for c in line: if (ord(c) - ord("a")) % 2 == 0: if not even.get(c): even[c] = 0 even[c] += 1 ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VA...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
from itertools import permutations n = int(input()) for _ in range(n): s = list(input()) x = list(set(s)) x.sort() if len(x) < 5: for p in permutations(x): for i, j in zip(p, p[1:]): if abs(ord(j) - ord(i)) == 1: break else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
import sys readline = sys.stdin.buffer.readline read = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep="\n") def solve(): s = list(ns()) o = list() ...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def check(s): for i in range(len(s) - 1): if abs(ord(s[i]) - ord(s[i + 1])) == 1: return 0 return 1 t = int(input()) for _ in range(t): o = list() e = list() s = input() for i in range(len(s)): if ord(s[i]) % 2 == 1: o.append(s[i]) else: ...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
dic = {} tem = "abcdefghijklmnopqrstuvwxyz" for i in range(26): dic[tem[i]] = i for _ in range(int(input())): st = list(input()) fre = {} for i in st: if i in fre: fre[i] += 1 else: fre[i] = 1 se = set(st) se = list(se) se.sort() le = len(se) f...
ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_C...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def getn(): return int(input()) def getns(): return [int(x) for x in input().split()] t = getn() for _ in range(t): mp = [[i, 0] for i in range(26)] s = input() for c in s: mp[ord(c) - ord("a")][1] += 1 mp = [x for x in mp if x[1] > 0] lt = [x[0] for x in mp if x[1] > 0] if l...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) strings = [list(map(lambda e: ord(e), list(input()))) for _ in range(n)] def main(element): result = [] even = [] odd = [] for tt in sorted(element): if tt % 2 == 0: even.append(tt) else: odd.append(tt) if len(odd) == 0 or len(even) == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
q = int(input()) def check(s): for i in range(len(s) - 1): if abs(ord(s[i]) - ord(s[i + 1])) == 1: return False return True for _ in range(q): s = input().strip() evens = [] odds = [] for ch in s: if ord(ch) % 2 == 0: evens.append(ch) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
N = int(input()) for i in range(N): maps = [0] * 26 A = input() for a in A: maps[ord(a) - ord("a")] += 1 L = [] for i, m in enumerate(maps): if m != 0: L += [[i + ord("a"), m]] ans = [] if len(L) > 4 or len(L) == 3 and abs(L[-1][0] - L[-2][0]) != 1: for i ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR LIST LIST BIN_OP VAR FUNC_CALL VAR STRING VAR ASSIGN VAR LIS...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) s = [input() for i in range(n)] alph = "abcdefghijklmnopqrstuvwxyz" to_int = {} to_char = {} for i in range(26): to_int[alph[i]] = i for i in range(n): memo = {} for j in s[i]: if to_int[j] not in memo: memo[to_int[j]] = 1 else: memo[to_int[j]] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL V...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def solve(): s = input() s = sorted(s) kol = [0] * 26 for i in s: kol[ord(i) - ord("a")] += 1 st = set() for i in s: st.add(ord(i) - ord("a")) v = list(st) v = sorted(v) if viv: print("Sorted", v) n = len(v) v2 = list() for i in range(1, n, 2): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
a = int(input()) for i in range(a): s = input() lp = [] li = [] for c in s: if ord(c) % 2 == 0: lp.append(ord(c)) else: li.append(ord(c)) lp.sort() li.sort() linova = [] linova2 = [] for i in range(len(li)): linova.append(li[i]) for...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
n = int(input()) s1 = "" for i in range(n): s = input() s1 = "" for o in range(ord("b"), ord("z") + 1, 2): s1 = s1 + chr(o) * s.count(chr(o)) for o in range(ord("a"), ord("z") + 1, 2): s1 = s1 + chr(o) * s.count(chr(o)) good = True for o in range(ord("b"), ord("z") + 1): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CAL...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
def isNotUgly(s): for _ in range(1, len(s)): if abs(ord(s[_]) - ord(s[_ - 1])) == 1: return False return True def solve(): s = input() even = [] odd = [] for _ in s: if ord(_) % 2 == 0: even.append(_) else: odd.append(_) even.sort...
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β€” "ab" and $(2, 3)$ β€” "ba". Letters 'a' and 'z' aren't considered neig...
class MyError(RuntimeError): pass n = int(input()) for i in range(n): s = input() odd = [] even = [] for ch in s: if ord(ch) % 2 == 0: even.append(ch) else: odd.append(ch) if len(odd) == 0 or len(even) == 0: print(s) else: u = -1 ...
CLASS_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN V...