description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
t = int(input()) for _ in range(t): q, t = map(int, input().split()) questions = [int(i) for i in input().split()] time = [int(i) for i in input().split()] d = {} for j in range(len(questions)): d[j] = [questions[j], time[j], questions[j] + time[j]] d = dict(sorted(d.items(), key=lambda ...
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR ...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) l = [] for f in range(n): l.append([a[f], b[f]]) l.sort(key=lambda x: (sum(x), x[0])) mx = 0 su = 0 i = 0 while i < n: if l[i][0]...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR V...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
def getSolution(n, k, a): mx = 0 sum = 0 i = 0 while i < n: if a[i][0] + a[i][1] + sum >= k: break else: sum += a[i][0] + a[i][1] mx = max(mx, a[i][1]) i += 1 temp = [0] * n kk = n - 1 while kk >= 0: if kk == n - 1: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_O...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
for _ in range(int(input())): n, t = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [[a[i], b[i], a[i] + b[i]] for i in range(len(a))] c.sort(key=lambda x: x[2]) i = 0 aux = [] while i < len(c) and t >= c[i][2]: t -= c[i][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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_C...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
t = int(input()) for i in range(t): n, s = map(int, input().split(" ")) a = input().split(" ") b = input().split(" ") c = [] for j in range(n): c.append((int(a[j]), int(b[j]), int(a[j]) + int(b[j]))) c1 = sorted(c, key=lambda l: l[2]) add = True k = 0 sum = 0 while add an...
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 FUNC_CALL VAR STRING ASSIGN 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 VAR VAR VAR BI...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
def solve(): m = [] for i in range(n): m.append([a[i], b[i]]) m.sort(key=lambda x: x[0] + x[1]) mx = 0 sum = 0 i = 0 while i < n: if m[i][0] + m[i][1] + sum <= k: sum += m[i][0] + m[i][1] mx = max(mx, m[i][1]) i += 1 else: ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_C...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
for tcase in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ab = [(ai + bi, ai, bi) for ai, bi in zip(a, b)] ab.sort() t0, m0, i, ans = 0, 0, 0, 0 for i in range(n): t1, m1 = t0 + ab[i][0], max(m0, ab[i][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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
from sys import stdin, stdout input = stdin.readline r_int = lambda: int(input()) m_int = lambda: map(int, input().split()) l_int = lambda: list(map(int, input().split())) def solve(): n, k = m_int() a = l_int() b = l_int() l = [(x + y, x, y) for x, y in zip(a, b)] l.sort() acc = 0 n_ex =...
ASSIGN VAR VAR 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VA...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
for _ in range(int(input())): n, k = map(int, input().split()) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] arr = [(A[x] + B[x], A[x]) for x in range(n)] arr.sort() ans = 0 pre = [0] * n for i in range(n): pre[i] = arr[i][0] + (pre[i - 1] if i > 0 e...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBE...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
for _ in range(int(input())): n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = [] for i in range(n): ans.append([a[i] + b[i], a[i]]) ans.sort() res = 0 i = 0 last = -1 while i < n: if ans[i][0] <=...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 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 LIST...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
t = int(input()) while t: N, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) T = list() for i in range(0, N): T.append((A[i] + B[i], i)) T.sort() ans = 0 maxs = 0 for i in range(0, N): if T[i][0] > K: b...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
T = int(input()) for _ in range(T): N, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [(A[i], B[i]) for i in range(N)] C.sort(key=sum) ans = 0 for i in range(N): if sum(C[i]) <= K: ans += 1 K -= sum(C[...
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL ...
Chef came across a new online judge that has N problems, and decided that he wants to solve them. Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it. That is, Chef will solve a problem, then take a break. Solve another problem, then t...
from sys import stdin input = stdin.readline def solve(N, K, A, B): problem = sorted([(a + b, b, i) for i, (a, b) in enumerate(zip(A, B))]) seen = set() answer = 0 count = 0 maxwait = 0 while answer < N: if count + problem[answer][0] <= K: count += problem[answer][0] ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_C...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys INF = 10**10 def main(): n = get_int() st = input() mini = st ans = 1 for k in range(1, n + 1): a = st[: k - 1] if (n - k + 1) % 2 != 0: a = a[::-1] s = st[k - 1 :] + a if s < mini: ans = k mini = s print("".join(m...
IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR N...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
T = int(input()) for _ in range(T): n = int(input()) a = input() k = [] s = a[0] for i in range(1, n): if a[i] < s: k = [i] s = a[i] elif a[i] == s: k.append(i) b = a s = b k1 = 1 if n % 2 == 0: fo = 0 else: fo =...
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 ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() MAX = s ans = 1 for i in range(n): tmp = s[0:i] now = s[i:n] + tmp[:: (-1) ** (n - i)] if now < MAX: MAX = now ans = i + 1 print(MAX) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXP...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) a = input() b = sorted(a) indices = [i for i, x in enumerate(a) if x == b[0]] ans = a set1 = {} for j in indices: if (n - j) % 2 == 0: s1 = a[j:n] + a[0:j] else: s1 = a[j:n] + a[0:j][::-1] if set1....
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBE...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) a = input() x = a s = sorted(a)[0] p = 1 if n == 1: print(a, "\n", n, sep="") else: for i in range(1, n): if a[i - 1] == s: c = a[i - 1 :] + (a[: i - 1][::-1] if not (n - i) % 2 else a[: i - 1]) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): l = int(input()) s = input() cmp = s res = s count = 1 for i in range(2, l + 1): if l % 2 == i % 2: new = s[i - 1 :] + s[: i - 1][::-1] if cmp > new: count = i res = new cmp = new ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() ch = s[0] for i in range(1, n): if ch > s[i]: ch = s[i] ks = [] for i in range(n): if s[i] == ch: ks.append(i + 1) low = -1 for k in ks: rev = False if (n - k + 1) % 2 == 1:...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input().rstrip() mi = s[:] l = 1 for k in range(2, n + 1): z = s[k - 1 :] + s[: k - 1][::-1] if n % 2 == k % 2 else s[k - 1 :] + s[: k - 1] if mi > z: mi = z[:] l = k print(mi) print(l)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for you in range(t): n = int(input()) s = input() pref = [(0) for i in range(n)] suffer = [(0) for i in range(n)] real = [(0) for i in range(n)] sumi = "" suf = "" reo = "" for i in range(n): sumi = s[n - i - 1] + sumi pref[n - 1 - i] = sumi s...
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 ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) while t > 0: t = t - 1 n = int(input()) s = input() li = [] for k in range(n - 1): if (n - k + 2) % 2 == 0: li.append((s[k:] + s[:k], k + 1)) else: li.append((s[k:] + s[:k][::-1], k + 1)) li.append((s[::-1], n)) s, k = min(li) prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EX...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = input() tmp = a[0:] ans = -1 for i in range(n): cnt = n - i if cnt % 2 == 0: if a[i:n] + a[0:i] < tmp: tmp = a[i:n] + a[0:i] ans = i eli...
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 VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def modified(s, n, k): result_prefix = s[k - 1 :] result_suffix = s[: k - 1] if n % 2 == k % 2: result_suffix = result_suffix[::-1] return result_prefix + result_suffix for _ in range(int(input())): n = int(input()) s = input() best_s = modified(s, n, 1) best_k = 1 for i in...
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = str(input()) X = [] for k in range(1, n + 1): p = s[k - 1 :] q = s[0 : k - 1] if (n - k - 1) % 2 == 1: t = p + q[::-1] else: t = p + q X.append([t, k]) X.sort() print(X[0][0])...
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NU...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def f(): n = int(input()) s = input() rk = 0 rs = s for k in range(1, n): if (n - k) % 2: cur = s[k:] + s[:k][::-1] else: cur = s[k:] + s[:k] if cur < rs: rs = cur rk = k print(rs) print(rk + 1) t = int(input()) for i ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def main(): for _ in range(int(input())): n = int(input()) s = list(input()) k = 1 ans = s for i in range(2, n + 1): if (n - i - 1) % 2 == 1 and s[i - 1 : n] + s[i - 2 :: -1] < ans: k = i ans = s[i - 1 : n] + s[i - 2 :: -1] ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NU...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = 1 t = int(input()) while t: t -= 1 n = int(input()) s = input() minStr, minIdx = s[:], 0 for i in range(n): comp = s[i:] + s[:i] if (n - i) % 2 == 0 else s[i:] + s[:i][::-1] if comp < minStr: minStr = comp minIdx = i print(minStr) print(minIdx + 1)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() ls = min(s) i = s.find(ls) candidates = [] while i != -1: if i == n - 1: candidates.append((s[::-1], n)) break if (n - i) % 2 == 0: candidates.append((s[i:] + s[:i], i + 1)) ...
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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EX...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def check(k, st): n = len(st) if (n - k + 1) % 2 == 0: return st[k - 1 : n : 1] + st[0 : k - 1 : 1] else: return st[k - 1 : n : 1] + st[k - 2 :: -1] def process(n, st): s = st result = 1 for k in range(1, n + 1): kq = check(k, st) if kq < s: s = kq ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) while t: n = int(input()) s = input() m = s mk = 1 for k in range(2, n + 1): tmp = s[k - n - 1 :] + (s[k - 2 :: -1] if (n - k + 1) % 2 == 1 else s[: k - 1]) if tmp < m: m = tmp mk = k print(m) print(mk) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMB...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def swap(s, n, k): if (n - k + 1) % 2 == 0: return s[k - 1 :] + s[: k - 1] return s[k - 1 :] + s[: k - 1][::-1] for _ in range(int(input())): n = int(input()) s = input() a = [] c = "" m = s k = 0 for i in "abcdefghijklmnopqrstuvwxyz": if i in s: c = i ...
FUNC_DEF IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIG...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline tc = int(input()) def newallswap(x, k): n = len(x) if k == 1: return x if k == len(x): return x[::-1] b = n % 2 a = x[k - 2 :: -1] if k % 2 == b else x[: k - 1] y = x[k - 1 :] + a return y for _ in range(tc): n = int(input()) ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR IF VAR FUNC_CALL VAR VAR RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
testCases = int(input()) for i1 in range(testCases): length = int(input()) sequence = input() ans = 1 result = sequence for k in range(length): if k % 2 == length % 2: new = sequence[k:] + sequence[0:k] else: new = sequence[k:] + sequence[0:k][::-1] if...
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 ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() l = [] for k in range(1, n + 1): if (n - k) % 2 == 1: l.append((s[k - 1 :] + s[: k - 1], k)) else: l.append((s[k - 1 :] + s[: k - 1][::-1], k)) ans = min(l) print(ans[0]) print(ans[1])
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def do(s, k): l = len(s) t = s k = k - 1 if l % 2 == 0: if k % 2 == 0: return t[k:] + t[:k] else: return t[k:] + t[-l + k - 1 : -l - 1 : -1] elif k % 2 == 1: return t[k:] + t[:k] else: return t[k:] + t[-l + k - 1 : -l - 1 : -1] t = int(in...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR VAR VAR VAR RETURN BIN_OP ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
test = int(input()) for i in range(test): strLen = int(input()) s = input() best = s k = 0 temp = "" for i in range(1, strLen + 1): p = s[i:strLen] ss = "" if (i + strLen) % 2: ss = s[0:i][::-1] else: ss = s[0:i] temp = p + ss ...
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 ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBE...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline t = int(input()) while t: t -= 1 n = int(input()) a = input().rstrip() p = 200 k = 1 res = a ma = a[:] for i in range(n): if (n - i - 2) % 2 == 0: s = a[i + 1 :] + a[: i + 1][::-1] else: s = a[i + 1 :] + a[: i...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def lexi(a, b): lenof = len(a) for i in range(lenof): if a[i] == b[i]: continue elif a[i] < b[i]: return True else: return False return False def gift(): for _ in ...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) S = list(ord(s) - 97 for s in input()) C = S ans = 1 for i in range(2, n + 1): N = [0] * n for j in range(i - 1, n): N[j - (i - 1)] = S[j] for j in range(i - 1): if (n - i + 1) % 2 == 0: ...
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 BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_O...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline def main(): for _ in range(int(input())): n = int(input()) s = input().strip() ret = s ret_idx = 0 for k in range(1, n): if (n - k) % 2 == 0: tmp = s[k:] + s[:k] else: tmp = s[k:]...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
e = int(input()) p = [] f = [] for ee in range(e): n = int(input()) s = str(input()) sr = s words = [] er = [] er.append(s) words.append(s) for k in range(2, n + 1): j = "" j = s[k - 1 :] if (len(s) - k + 1) % 2 == 0: j = j + s[: k - 1] else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIG...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for i in range(t): n = int(input()) s = input() a = dict() a[s] = 1 for j in range(1, n + 1): if j == 1: continue u = n - j + 1 z = s[0 : j - 1] if u % 2 == 1: z = z[::-1] s1 = s[j - 1 :] + z if s1 in a: ...
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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def sim(s, t): if len(s) == t: return s[::-1] if (len(s) - t) % 2 == 0: return s[t:] + s[:t] else: return s[t:] + s[:t][::-1] def f(s): n = len(s) t = min([(sim(s, i), i) for i in range(0, n + 1, 1)], key=lambda x: x[0]) return t[0], t[1] + 1 for i in range(int(input(...
FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN BIN_OP VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBE...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) while t > 0: dic = {} t -= 1 n = int(input()) STR = input() arr = [0] * n for i in range(n): arr[i] = ord(STR[i]) m_val = 10000000 for i in range(n): if arr[i] < m_val: m_val = arr[i] arr2 = [] for i in range(n): if arr[i] == m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR DICT VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def krev(s, k): l = list(s) for i in range(len(s) - k + 1): l[i : i + k] = l[i : i + k][::-1] return "".join(l) def rrev(s, k): left = s[k - 1 :] right = s[: k - 1] if len(s) % 2 == k % 2: right = right[::-1] return left + right def solve(n, s): minc = min(s) I = ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER A...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for k in range(t): n = int(input()) aString = input() aStringRev = aString[::-1] a = [] for i in range(n): if (n - i) % 2 == 0: a.append(aString[i:n] + aString[0:i]) else: a.append(aString[i:n] + aStringRev[n - i : n]) minStrID = 0 for...
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 ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def swap(s, i): num_moves = len(s) - i parity = (len(s) - i) % 2 return s[i:] + (s[:i] if parity == 0 else s[:i][::-1]) def main(): T = int(rl()) numchar = lambda c: ord(c) - 97 for _ in range...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FU...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
numTests = int(input()) minLexIx = 0 answers = [] for i in range(numTests): strLen = int(input()) word = input() results = [] for ix in range(0, strLen): res = word[ix:strLen] rhs = word[0:ix] if ix % 2 == 0 and strLen % 2 == 1 or ix % 2 == 1 and strLen % 2 == 0: rhs ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
T = int(input()) for test in range(T): n = int(input()) lst = list(input()) a = [] a.append(("".join(lst), 1)) for i in range(1, n): string = "" string += "".join(lst[i:]) if i % 2 == 0 and n % 2 == 1 or i % 2 == 1 and n % 2 == 0: string += "".join(list(reversed(l...
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 ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING VAR FUNC_CALL STRING VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() mi, m1 = s, 1 for i in range(2, n + 1): s1 = "" if (n - i) % 2 == 0: s1 = s[i - 1 :] + s[: i - 1][::-1] else: s1 = s[i - 1 :] + s[: i - 1] if s1 < mi: mi, m1 = s1, i p...
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 ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() assert len(s) == n def vasya(s, k): if (n - k) % 2 == 0: suffix = s[k - 2 :: -1] else: suffix = s[: k - 1] return s[k - 1 :] + suffix best = s, 1 for k in range(2, n + 1): v...
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 VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): s = [input() for i in "aa"][1] idx = [i for i in range(len(s)) if s[i] == min(s)] ss = [ (s[i:] + s[:i][::-1] if (len(s) + i) % 2 != 0 else s[i:] + s[:i]) for i in idx ] print(min(ss), idx[ss.index(min(ss))] + 1, sep="\n")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
T = int(input()) while T: T -= 1 n = int(input()) s = input() ret = s k = 1 for i in range(1, n): if (n - i) % 2: t = s[i:] + s[0:i][::-1] else: t = s[i:] + s[0:i] if ret > t: ret = t k = i + 1 t = s[::-1] if ret > t...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR IF VAR VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
T = int(input()) def compare(n, l, k, best): l1 = [] l2 = [] if (best + n) % 2 == 1: for i in range(n): l1.append(l[(best - 1 + i) % n]) else: for i in range(best - 1, n): l1.append(l[i]) for i in range(best - 2, -1, -1): l1.append(l[i]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER N...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for t in range(int(input())): n = int(input()) s = input() dic, se = {s: 1}, {s} for k in range(2, n): p = s[k - 1 :] + (s[: k - 1], s[: k - 1][::-1])[n % 2 == k % 2] if p not in dic: dic[p] = k se.add(p) if s[::-1] not in dic: dic[s[::-1]] = n ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR DICT VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() c = "" k = 0 for i in range(n + 1): t = s[i:] if i % 2 != n % 2: t += s[:i][::-1] else: t += s[:i] if not c or t < c: c = t k = i print(c) print(k + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) string = input() ans = 0 result = string for i in range(0, n): choti = string[0:i] if n % 2 == (i + 1) % 2: choti = choti[::-1] new = string[i:] + choti if new < result: result = new ...
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 ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for mo in range(1, t + 1): l = [] n = int(input()) s = input() for i in range(1, n + 1): if (n - i + 1) % 2 and i >= 2: l.append((s[i - 1 :] + s[i - 2 :: -1], i)) elif (n - i + 1) % 2: l.append((s, i)) else: l.append((s[i - 1 :...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() r = s d = 0 for i in range(1, n): if (n - i) % 2 == 1: a = s[i:] + s[:i][::-1] else: a = s[i:] + s[:i] if a < r: r = a d = i print(r) print(d + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) while t > 0: n = int(input()) s = input() mem = [] lst = list(s) for i in range(0, n): if i == 0: mem.append([s[i:], i + 1]) elif i < n - 1: if (n - i) % 2 == 0: mem.append([s[i:] + s[:i], i + 1]) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER N...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) R = lambda: map(int, input().split()) for i in range(t): n = int(input()) s = input() ans = [] for i in range(1, n + 1): if i == n: temp = s[::-1] ans.append((temp, i)) continue if (n - i - 1) % 2 == 0: temp = s[i - 1 :] + ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_O...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() x = min(s) k = [] for i in range(n): if s[i] == x: k.append(i + 1) pos = [] for kvalue in k: r = (n - kvalue + 1) % 2 s2 = s[: kvalue - 1] if r: s2 = "".join(reversed(s2)) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER A...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys t = int(input()) for x in range(t): n = int(input()) s = input() ind = 0 mini = min(s) d = [] for i in range(n): if s[i] == mini: d.append(i) maxi = s n1 = len(d) for i in range(n1): s1 = "" cnt = 0 s1 += s[d[i] :] if (n...
IMPORT 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() l1 = [] l2 = [] min_ = min(s) for i in range(n): if s[i] == min_: l1.append(i) for i in l1: s1 = s[i:] if (n - i) % 2 == 0: s1 += s[:i] else: s1 += s[:i][::-1] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() ans = [] for i in range(1, n + 1): if i == n: temp = s[-1::-1] elif (n - i + 1) % 2 == 0: temp = s[i - 1 :] + s[: i - 1] else: temp = s[i - 1 :] + s[: i - 1][::-1] ans.append([t...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): l = int(input()) s = input() ans = s ansl = 1 for i in range(l): ns = s[i:] + s[:i][:: -1 if l - i & 1 else 1] if ns < ans: ans = ns ansl = i + 1 print(ans) print(ansl)
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 ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for i in range(t): n = int(input()) s = input() ans = s val = 1 for k in range(1, n + 1): if k == n: tmp = s[::-1] else: ss = s[: k - 1] if n % 2 != k % 2: tmp = s[k - 1 :] + ss else: tmp...
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 ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() z = [] for i in range(n): if (n - i) % 2: z.append([s[i:] + s[:i][::-1], i]) else: z.append([s[i:] + s[:i], i]) z.sort() print(z[0][0]) print(z[0][1] + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): Map = {} n = int(input()) s = list(input()) Map["".join(s)] = 1 for k in range(1, n): st = "".join(s[k:]) if (n - k) % 2 == 0: st += "".join(s[:k]) else: rev = s[:k] rev.reverse() st += "".join(rev)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL STRING VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() k = 1 z = "" a = [s] b = [] while k < n: z = s[k:n] if n % 2 == k % 2: z += s[0:k] else: z += s[0:k][::-1] a.append(z) b.append(k) k += 1 print(min(a)) t...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR LIST VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CAL...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): a = input() s = input() lex = ["z"] lexmax = 1 lent = len(s) for i in range(1, len(s) + 1): if (lent - i + 1) % 2 == 0: u = s[: i - 1] else: u = s[: i - 1][::-1] temp = s[i - 1 :] + u lex.append(temp) i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASS...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def maximizescore(x, y): return min(sum(x), y) def modifystring(x): y = min(x) z = "{" l = 1 for i in range(len(x)): if x[i] == y: if (len(x) - i) % 2 == 0: if z > x[i:] + x[:i]: z = x[i:] + x[:i] l = i + 1 eli...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = input().rstrip() words = [] for i in range(n): if (n - i) % 2 == 0: words.append((s[i:] + s[:i], i + 1)) else: words.append((s[i:] + s[:i][::-1], i + 1)) words.sort...
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 VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() ans = [(s, 1), (s[::-1], n)] for i in range(2, n): if (n - i + 1) % 2: x = "".join((s[i - 1 :], s[i - 2 :: -1])) ans.append((x, i)) else: x = "".join((s[i - 1 :], s[: i - 1])) ...
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 ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBE...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for j in range(t): n = int(input()) a = input() g = a b = 0 for i in range(n): d = a[:i] if (n - i) % 2 == 0: c = a[i:] + d else: c = a[i:] + d[::-1] if c < g: g = c b = i + 1 print(g) if b == 0:...
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 ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for i in range(t): le = int(input()) s = list(input()) mg = s[:] i1 = 1 co = 0 for k in range(le): if le % 2 != 0: if k % 2 == 0: l = s[0:k] r = s[k:le] l.reverse() ne = r + l if ...
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 ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
from sys import stdin def inp(): return next(ss.rstrip() for ss in stdin) def itg(): return int(inp()) def mpint(): return map(int, inp().split()) for case in range(itg()): n = itg() s = inp() min_char = min(s) kk = [(i + 1) for i in range(n) if s[i] == min_char] results = [] ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys inp = sys.stdin.readline def input(): return inp().strip() def iin(): return int(input()) def lin(): return list(map(int, input().split())) def main(): T = iin() while T: T -= 1 n = iin() s = list(input()) ans = [] for i in range(1, n + 1):...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
from sys import stdin, stdout Pi = lambda x: stdout.write(str(x) + "\n") S = lambda x: x * (x + 1) // 2 R = lambda: stdin.readline() Ri = lambda x: map(int, x.split()) def main(): t = int(R()) for i in range(t): n = int(R()) s = R().strip("\n") v = [0] * 26 for c in s: ...
ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF 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 FUNC_CA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for i in range(t): n = int(input()) s = input() ans = "" ansk = -1 for k in range(1, n + 1): hilu = s[: k - 1] if n % 2 == 0 and k % 2 == 0: hilu = hilu[::-1] if n % 2 != 0 and k % 2 != 0: hilu = hilu[::-1] yo = s[k - 1 :] + hi...
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 ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def f(L, K): L = list(L) a = L[: K - 1] ans = L[K - 1 :] if K % 2 == len(L) % 2: a = a[::-1] ans += a return "".join(ans) for _ in range(int(input())): N = int(input()) L = input() ans = "z" * 6000 ak = -1 for k in range(1, 1 + N): x = f(L, k) if x <...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR RETURN FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def ii(): return int(input()) def mii(): return map(int, input().split()) def lmii(): return list(mii()) def main(): for _ in range(ii()): n = ii() s = input() r = [] x = [] y = [] pt = [] for i in range(n): r.append(s[i]) ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = lambda: sys.stdin.readline().rstrip() t = int(input()) while t: t -= 1 n = int(input()) a = input() poss = [] for i in range(n): if n - i & 1 and i != 0: poss.append([a[i:] + a[i - 1 :: -1], i]) else: poss.append([a[i:] + a[:i], i]) ans...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER V...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for j in range(t): n = int(input()) s = input() S = s m = min(s) result = -1 x = True l = [] lst = [] while x == True: result = s.find(m, result + 1) if result not in l and result != -1: l.append(result) else: break ...
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 ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = input() t = s[::-1] can = [] for i in range(n): tmp = s[i:] if i == 0: can.append([s, 1]) continue if i % 2 != n % 2: tmp += t[-i:] else: tmp += s[:i] can....
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 ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) st = "" for _ in range(t): n = int(input()) s = input() l = [s + "0000"] for i in range(1, n): if n - i & 1: st = s[i:] + s[:i][::-1] + "{:04d}".format(i) else: st = s[i:] + s[:i] + "{:04d}".format(i) l.append(st) l.sort() print(l[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_CALL STRING VAR ASSIG...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
q = int(input()) for i in range(q): minn = "z" * 5000 n = int(input()) s = input() for j in range(n): step = 1 if (n - j) % 2 == 1: step = -1 st = s[j:] + s[:j][::step] if st < minn: minn = st k = j + 1 print(minn) print(k)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def reverse(s): return s[::-1] t = int(input()) for i in range(t): n = int(input()) s = input() p = sorted(s)[0] arr = [] for i in range(len(s)): if s[i] == p: arr.append(i) lis = [] for i in arr: if (n - i) % 2 == 0: lis.append((s[i:] + s[0:i], ...
FUNC_DEF RETURN VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = 0 t = int(input()) for q in range(t): n = int(input()) str = "" str = input() ans_str = "" ans_ind = 0 for i in range(n): if (n - i + 1) % 2 == 0: new_str = str[i:n] + str[0:i][::-1] else: new_str = str[i:n] + str[0:i] if i == 0: an...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = list(input()) if len(set(s)) == 1: print("".join(s)) print(1) else: m = min(s) ans = s[:] ind = 1 for i, c in enumerate(s): fs = s[i:] + s[:i][:: -1 if (i + n) % 2 == 1 else 1] if f...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
inf = int(10000000000.0) t = int(input()) for _ in range(t): n = int(input()) lis = input() if n == 1: print(lis) print(1) else: m = min(lis) index = [] for i in range(n): if lis[i] == m: index.append(i) z = "z" * n maxx...
ASSIGN VAR FUNC_CALL VAR NUMBER 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 IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) s = input().strip() tmp = [] for i in range(n): b, c = s[:i], s[i:] if (n - i) % 2: b = b[::-1] tmp.append((c + b, i + 1)) tmp.sort() x, y = tmp[0] print(x) pri...
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 VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VA...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) f = input() k = 1 an = f for i in range(1, n + 1): if i == n: s = f[::-1] elif (n - i + 1) % 2 == 0: s = f[i - 1 :] + f[: i - 1] else: s = f[i - 1 :] + f[: i - 1][::-1] if s < an: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): input() s = input() n = len(s) ans = s final = 1 for k in range(n): if n % 2: if k % 2: temp = s[k:] + s[0:k] else: temp = s[k:] + s[0:k][::-1] elif k % 2 == 0: temp = s[k:] + s[0:k]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF BIN_...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = input() for _ in range(int(t)): n = int(input()) s = input() mn = min(s) ind = [] for i in range(n): if s[i] == mn: ind.append(i) ans = "z" * (n + 1) k = -1 parity_len = n % 2 for i in ind: parity_curr = i % 2 front = s[i : i + n] rest ...
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
t = int(input()) for _ in range(t): n = int(input()) s = list(input()) curr = "".join(s) ind = 1 m = min(s) for i in range(len(s)): if s[i] == m: prev = curr if (n - i) % 2 == 1: curr = min(curr, "".join(s[i:] + list(reversed(s[:i])))) ...
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 ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUM...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
def main(): n = int(input()) string = list(str(input())) index = 0 res = "".join(string) for i in range(1, n): string2 = "" if (i + 1) % 2 != n % 2: string2 = "".join(string[i:n] + string[:i]) else: string2 = "".join(string[i:n] + string[i - 1 :: -1]) ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING IF BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR...
Vasya has a string $s$ of length $n$. He decides to make the following modification to the string: Pick an integer $k$, ($1 \leq k \leq n$). For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes t...
for _ in range(int(input())): n = int(input()) s = input() k = 1 res = s[:] for i in range(1, n): n_res = s[i:] if n % 2 == i % 2: n_res += s[:i] else: n_res += s[i - 1 :: -1] if n_res < res: res = n_res[:] k = i + 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR ...