zccneil/codelingua_dataset huggingface dataset:
assistant: import random
input()
A = [int(_) for _ in input().split()]
A = [A[0]] + [j for i, j in zip(A, A[1:]) if i >= j]
N = len(A)


def cut(array, index):
    if index < 1:
        return []
    if index <= array[0][0]:
        return [(index, array[0][1])]
    for _ in range(len(array) - 1, 0, - 1):
        if array[_ - 1][0] < index:
            return array[: _] + [(index, array[_][1])]


def is_possible(K):
    dp = [(A[0], 0)]
    for a in A[1:]:
        if a <= dp[- 1][0]:
            dp = cut(dp, a)
        else:
            dp += [(a, 0)]
        is_added = False
        for j in range(len(dp) - 1, - 1, - 1):
            if dp[j][1] < K - 1:
                dp = cut(dp, dp[j][0] - 1) + [(dp[j][0], dp[j][1] + 1)]
                if dp[- 1][0] < a:
                    dp += [(a, 0)]
                is_added = True
                break
        if not is_added:
            return False
    return True


def bis(x, y):
    if y == x + 1:
        return y
    elif is_possible((x + y) // 2):
        return bis(x, (x + y) // 2)
    else:
        return bis((x + y) // 2, y)


print(bis(0, N))


user: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.TreeMap;

public class atcoder_AGC029_C {
    private int n;
    private int[] a;
    private TreeMap<Integer, Integer> s;

    public static void main(String[] args) {
        atcoder_AGC029_C m = new atcoder_AGC029_C();
        m.solve();
    }

    private void set() {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            n = Integer.parseInt(br.readLine());
            a = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            s = new TreeMap<>();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void solve() {
        set();
        int ng = 0;
        int ok = n;
        while (ok - ng > 1) {
            int k = (ng + ok) / 2;
            if (isPossible(k)) {
                ok = k;
            } else {
                ng = k;
            }
        }
        System.out.println(ok);
    }

    private boolean isPossible(int k) {
        s.clear();
        int current = 0;
        for (int ai : a) {
            if (ai <= current) {
                if (k == 1) return false;
                while (!s.isEmpty() && s.lastKey() >= ai) s.pollLastEntry();
                int p = ai - 1;
                while (true) {
                    if (p < 0) return false;
                    int sp = s.getOrDefault(p, 0) + 1;
                    s.put(p, sp);
                    if (sp == k) {
                        s.remove(p);
                        p--;
                    } else {
                        break;
                    }
                }
            }
            current = ai;
        }
        return true;
    }
}
assistant: import numpy as np
h, w = map(int, input().split())
graph = [[0 if i == '#' else float('inf')
          for i in list(input())] for _ in range(h)]
graph = np.array(graph)
for x in range(w - 1):
    graph[:, x + 1] = np.minimum(graph[:, x] + 1, graph[:, x + 1])
for x in range(w - 1, 0, - 1):
    graph[:, x - 1] = np.minimum(graph[:, x] + 1, graph[:, x - 1])
for y in range(h - 1):
    graph[y + 1, :] = np.minimum(graph[y, :] + 1, graph[y + 1, :])
for y in range(h - 1, 0, - 1):
    graph[y - 1, :] = np.minimum(graph[y, :] + 1, graph[y - 1, :])
print(int(np.max(graph)))


user: import java.util.*;

public class atcoder_AGC033_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] A = new char[H][W];
        Queue<int[]> queue = new ArrayDeque<int[]>();
        for (int i = 0; i < H; i++) {
            String row = sc.next();
            for (int j = 0; j < W; j++) {
                A[i][j] = row.charAt(j);
                if (A[i][j] == '#') {
                    int[] start = {i, j, 0};
                    queue.add(start);
                }
            }
        }
        int[][] flag = new int[H][W];
        int ans = 0;
        int[] dx = {1, -1, 0, 0};
        int[] dy = {0, 0, 1, -1};
        loop:
        while (!queue.isEmpty()) {
            int[] temp = queue.remove();
            int y = temp[0];
            int x = temp[1];
            int depth = temp[2];
            for (int i = 0; i < 4; i++) {
                if (0 <= y + dy[i] && y + dy[i] <= H - 1 && 0 <= x + dx[i] && x + dx[i] <= W - 1) {
                    if (flag[y + dy[i]][x + dx[i]] == 0 && A[y + dy[i]][x + dx[i]] == '.') {
                        flag[y + dy[i]][x + dx[i]] = 1;
                        int[] queue_add = {y + dy[i], x + dx[i], depth + 1};
                        queue.add(queue_add);
                        ans = depth + 1;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}
assistant: H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()
Judge = False
S_L, S_R, S_U, S_D = 0, 0, 0, 0
T_L, T_R, T_U, T_D = 0, 0, 0, 0
for x in range(N):
    if S[x] == 'L':
        S_L += 1
        if S_L - T_R - s_c == 0:
            Judge = True
    elif S[x] == 'R':
        S_R += 1
        if s_c + (S_R - T_L) == W + 1:
            Judge = True
    elif S[x] == 'U':
        S_U += 1
        if S_U - T_D - s_r == 0:
            Judge = True
    elif S[x] == 'D':
        S_D += 1
        if s_r + (S_D - T_U) == H + 1:
            Judge = True
    if T[x] == 'L':
        if S_R - T_L + s_c != 1:
            T_L += 1
    if T[x] == 'R':
        if s_c + (T_R - S_L) != W:
            T_R += 1
    if T[x] == 'U':
        if S_D - T_U + s_r != 1:
            T_U += 1
    if T[x] == 'D':
        if s_r + (T_D - S_U) != H:
            T_D += 1
if Judge:
    print('NO')
else:
    print('YES')


user: import java.util.*;

public class atcoder_AGC033_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int n = scanner.nextInt();
        int sr = scanner.nextInt();
        int sc = scanner.nextInt();
        String s = scanner.next();
        String t = scanner.next();
        boolean end = false;
        int usafe = 1;
        int dsafe = h;
        for (int i = n - 1; i >= 0; i--) {
            if (s.charAt(i) == 'U') {
                usafe++;
            } else if (s.charAt(i) == 'D') {
                dsafe--;
            }
            if (usafe > dsafe) {
                end = true;
                break;
            }
            if (i > 0) {
                if (t.charAt(i - 1) == 'U') {
                    dsafe = Math.min(dsafe + 1, h);
                } else if (t.charAt(i - 1) == 'D') {
                    usafe = Math.max(usafe - 1, 1);
                }
            }
        }
        int lsafe = 1;
        int rsafe = w;
        for (int i = n - 1; i >= 0; i--) {
            if (s.charAt(i) == 'L') {
                lsafe++;
            } else if (s.charAt(i) == 'R') {
                rsafe--;
            }
            if (lsafe > rsafe) {
                end = true;
                break;
            }
            if (i > 0) {
                if (t.charAt(i - 1) == 'L') {
                    rsafe = Math.min(rsafe + 1, w);
                } else if (t.charAt(i - 1) == 'R') {
                    lsafe = Math.max(lsafe - 1, 1);
                }
            }
        }
        if (sr >= usafe && sr <= dsafe && sc >= lsafe && sc <= rsafe && !end) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}
assistant: import sys
import math
import collections
import heapq
import itertools


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b


def solve():
    s = input()
    t = ""
    i = 0
    while i < len(s):
        if s[i] == "A":
            t += "A"
            i += 1
        elif s[i] == "B":
            if i < len(s) - 1:
                if s[i + 1] == "C":
                    t += "D"
                    i += 2
                else:
                    t += "X"
                    i += 1
            else:
                t += "X"
                i += 1
        else:
            t += "X"
            i += 1
    total = 0
    numA = 0
    for i in range(len(t)):
        if t[i] == "X":
            numA = 0
        else:
            if t[i] == "A":
                numA += 1
            else:
                total += numA
    print(total)
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    return 0


if __name__ == "__main__":
    solve()


user: import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class atcoder_AGC034_B {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BABC solver = new BABC();
        solver.solve(1, in, out);
        out.close();
    }

    static class BABC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next().replaceAll("BC", "D");
            long cnt = 0;
            long tmp = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'A') {
                    tmp++;
                } else if (s.charAt(i) == 'D') {
                    cnt += tmp;
                } else {
                    tmp = 0;
                }
            }
            out.println(cnt);
        }
    }
}
assistant: import numpy as np
from collections import deque
import heapq
N, M = map(int, input().split())
edges = [set() for _ in range(N)]
degs = [0 for i in range(N)]
parity = [0 for _ in range(N)]
flag = [False for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    edges[a - 1].add(b - 1)
    edges[b - 1].add(a - 1)
    degs[a - 1] += 1
    degs[b - 1] += 1
if M % 2 != 0:
    print(- 1)
    exit()
Q = []
for i, d in enumerate(degs):
    Q.append((d, i))
heapq.heapify(Q)
while len(Q) > 0:
    _, u = Q[0]
    heapq.heappop(Q)
    if flag[u]:
        continue
    flag[u] = True
    for i, v in enumerate(edges[u]):
        edges[v].remove(u)
        if parity[u] != 0 and i == 0:
            print(u + 1, v + 1)
            parity[u] = 1 - parity[u]
        else:
            print(v + 1, u + 1)
            parity[v] = 1 - parity[v]
        degs[v] -= 1
        heapq.heappush(Q, (degs[v], v))


user: import java.util.*;

public class atcoder_AGC035_B {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numNode = sc.nextInt();
        int numEdge = sc.nextInt();
        connect = new ArrayList[numNode];
        for (int i = 0; i < numNode; i++) {
            connect[i] = new ArrayList<>();
        }
        for (int i = 0; i < numEdge; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            connect[a].add(b);
            connect[b].add(a);
        }
        if (numEdge % 2 != 0) {
            System.out.println(-1);
            return;
        }
        visited = new int[numNode];
        odd = new boolean[numNode];
        print = new StringBuilder();
        dfs(0, -1);
        System.out.println(print);
    }

    static ArrayList<Integer> connect[];
    static int visited[];
    static boolean odd[];
    static StringBuilder print;

    static void dfs(int crt, int parent) {
        visited[crt] = 1;
        ArrayList<Integer> crtConnect = connect[crt];
        for (int child : crtConnect) {
            if (child == parent || visited[child] == 1) {
                continue;
            } else if (visited[child] == 2) {
                print.append((crt + 1) + " " + (child + 1) + "\n");
                odd[crt] = !odd[crt];
            } else {
                dfs(child, crt);
                if (odd[child]) {
                    print.append((child + 1) + " " + (crt + 1) + "\n");
                    odd[child] = !odd[child];
                } else {
                    print.append((crt + 1) + " " + (child + 1) + "\n");
                    odd[crt] = !odd[crt];
                }
            }
        }
        visited[crt] = 2;
    }
}
assistant: N, K = map(int, input().split())
S = input()
aaaa = False
if K >= 15:
    aaaa = True
elif 2 ** K >= N:
    aaaa = True
if aaaa:
    print(min(S) * N)
    exit()


def get_last_dict(s_str):
    U = s_str + s_str[:: - 1]
    c = min(s_str)
    p = U.index(c)
    minindex = p
    p += 1
    while p <= N:
        if U[p] == c:
            if check_normal_dict(U, minindex, p):
                minindex = p
        p += 1
    return U[minindex: minindex + N]


def check_normal_dict(u, pointer1, pointer2):
    for i in range(N):
        if u[pointer1 + i] > u[pointer2 + i]:
            return True
        elif u[pointer1 + i] < u[pointer2 + i]:
            return False
    return False


S = get_last_dict(S)
if K == 1:
    print(S)
else:
    count = 0
    for c in S:
        if c == S[0]:
            count += 1
        else:
            break
    if count * (2 ** (K - 1)) >= N:
        print(S[0] * N)
    else:
        S = S[0] * (count * ((2 ** (K - 1)) - 1)) + S
        print(S[0: N])


user: import java.util.Scanner;

public class atcoder_AGC037_E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            final int N = sc.nextInt();
            int K = sc.nextInt();
            StringBuilder S = new StringBuilder(sc.next());
            boolean firstTime = true;
            int step = 1;
            while (K > 0) {
                StringBuilder T = new StringBuilder(S.toString());
                T.reverse();
                StringBuilder revU = new StringBuilder(S.toString() + T.toString());
                revU.reverse();
                String sDash = S.toString();
                for (int i = N; i >= 0; i -= step) {
                    String tmp = revU.substring(i, i + N);
                    if (sDash.compareTo(tmp) > 0) {
                        sDash = tmp;
                    } else {
                        if (!firstTime) {
                            break;
                        }
                    }
                }
                if (firstTime) {
                    firstTime = false;
                    if (Math.pow(2, K) > N) {
                        char c = sDash.charAt(0);
                        for (int i = 0; i < N; i++) {
                            System.out.print(c);
                        }
                        System.out.println();
                        System.exit(0);
                    }
                } else {
                    step += step;
                }
                K--;
                S = new StringBuilder(sDash);
                S.reverse();
            }
            System.out.println(S.reverse());
        } finally {
            sc.close();
        }
    }
}
assistant: import sys


def solve(H: int, W: int, A: int, B: int):
    answer = [["0"] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if i < B:
                if j < A:
                    answer[i][j] = "0"
                else:
                    answer[i][j] = "1"
            else:
                if j < A:
                    answer[i][j] = "1"
                else:
                    answer[i][j] = "0"
    for i in range(H):
        print(''.join(answer[i]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))
    W = int(next(tokens))
    A = int(next(tokens))
    B = int(next(tokens))
    solve(H, W, A, B)


if __name__ == '__main__':
    main()


user: import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;

public class atcoder_AGC038_A {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int H = sc.nextInt();
        int W = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (W < 2 * A || H < 2 * B) {
            System.out.println(-1);
            return;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i < B && j < A) || (i >= B) && (j >= A)) bw.write("0");
                else bw.write("1");
            }
            bw.newLine();
        }
        bw.flush();
    }
}
assistant: def twos_in_factorial(n):
    return n - bin(n).count('1')


def parity_of_nCr(n, i):
    f = twos_in_factorial
    return f(n) - f(n - i) - f(i) > 0


if __name__ == "__main__":
    n = int(input())
    nums = list(map(lambda x: int(x) - 1, input().strip()))
    no_one = False
    if 1 not in nums:
        nums = [num // 2 for num in nums]
        no_one = True
    is_odd = False
    for i, num in enumerate(nums):
        if not parity_of_nCr(n - 1, i) and num & 1:
            is_odd ^= 1
    if not is_odd:
        print(0)
    else:
        print(1 << no_one)


user: import java.io.*;
import java.util.*;

public class atcoder_AGC043_B {
    private int cal(String s, char c) {
        int n = s.length();
        int m = n - 1;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == c && (m & i) == i) {
                ans ^= 1;
            }
        }
        return ans;
    }

    private void solve() {
        int n = sc.nextInt();
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < n; i++) {
            sb.append(Math.abs(s.charAt(i) - s.charAt(i - 1)));
        }
        if (n == 2) {
            out.println(sb.charAt(0));
            return;
        }
        s = sb.toString();
        if (s.contains("1")) {
            out.println(cal(s, '1'));
        } else {
            out.println(cal(s, '2') * 2);
        }
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new atcoder_AGC043_B().solve();
        out.close();
    }
}
assistant: from math import gcd
x = int(input())
print(360 // gcd(360, x))


user: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class atcoder_AGC046_A {
    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int x = sc.nextInt();
        int count = 0;
        int tmp = x;
        x = 0;
        while (x != 360) {
            x = x + tmp;
            if (x > 360) {
                x = x - 360;
            }
            count++;
        }
        System.out.println(count);
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
assistant: A, B, C, D = map(int, input().split())
m = 998244353
d = [[0] * (D + 1) for _ in range(C + 1)]
d[A][B] = 1
for i in range(A, C + 1):
    for j in range(B, D + 1):
        d[i][j] += (d[i][j - 1] * i + d[i - 1][j] * j -
                    d[i - 1][j - 1] * (i - 1) * (j - 1)) % m
print(d[C][D])


user: import java.io.PrintWriter;
import java.util.Scanner;

public class atcoder_AGC046_B {
    long MOD = 998244353L;
    long[][] dp = new long[3001][3001];

    void solve(Scanner sc, PrintWriter pw) {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        dp[A][B] = 1;
        for (int c = A; c <= C; c++) {
            for (int d = B; d <= D; d++) {
                if (c == A && d == B) {
                    continue;
                }
                long ans = 0;
                if (c > A) {
                    long part = dp[c - 1][d];
                    ans = (part * d);
                }
                if (d > B) {
                    long part = dp[c][d - 1];
                    ans = (ans + (part * c));
                }
                if (c > A && d > B) {
                    ans = (ans - (dp[c - 1][d - 1] * (c - 1) * (d - 1)));
                }
                dp[c][d] = ((ans % MOD) + MOD) % MOD;
            }
        }
        pw.println(dp[C][D]);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new atcoder_AGC046_B().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}