zccneil/codelingua_dataset huggingface dataset:
assistant: def check(lis, k, mid):
    for i in lis:
        if (i % mid == 0):
            k += 1
        k -= (i // mid)
    return k >= 0


n, k = map(int, input().split())
lis = list(map(int, input().split()))
a, b = 1, max(lis)
ans = b
while (a <= b):
    mid = (a + b) // 2
    if (check(lis, k, mid)):
        ans = mid
        b = mid - 1
    else:
        a = mid + 1
print(ans)


user: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class atcoder_ABC174_E {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solution sol = new Solution();
        sol.solve(in, out);
        out.close();
    }

    private static class Solution {
        private void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int[] logsLength = in.readArray(n);
            int min = 1, max = (int) 1e9 + 1000;
            while (min < max) {
                int mid = (min + max) / 2;
                if (nei(mid, logsLength, k)) max = mid;
                else min = mid + 1;
            }
            out.println(min);
        }

        private boolean nei(int mid, int[] logsLength, int k) {
            for (int log : logsLength) k -= (log + mid - 1) / mid - 1;
            return k >= 0;
        }
    }

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        private InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        private String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        private int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = nextInt();
            return a;
        }
    }
}
assistant: import os
from sys import stdin, stdout


def solve(tc):
    a = int(stdin.readline().strip())
    print(1 if a == 0 else 0)


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1


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

public class atcoder_ABC178_A {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = Integer.parseInt(scan.next());
        boolean bool = x == 1 ? true : false;
        int result = !bool ? 1 : 0;
        PrintWriter out = new PrintWriter(System.out);
        out.println(result);
        out.flush();
    }
}
assistant: import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import queue
import copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(- 1, 0), (0, 1), (1, 0), (0, - 1)]
ddn = [(- 1, 0), (- 1, 1), (0, 1), (1, 1),
       (1, 0), (1, - 1), (0, - 1), (- 1, - 1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def main():
    a, b, c, d = LI()
    return max(a * c, b * d, a * d, b * c)


print(main())


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

public class atcoder_ABC178_B {
    static 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 (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static int modPower(int x, int y, int mod) {
        int res = 1;
        x %= mod;
        if (x == 0) return 0;
        while (y > 0) {
            if (y % 2 == 1) {
                res = (res * x) % mod;
            }
            y = y >> 1;
            x = (x * x) % mod;
        }
        return res;
    }

    static class pair<T1, T2> {
        T1 first;
        T2 second;

        pair(T1 first, T2 second) {
            this.first = first;
            this.second = second;
        }
    }

    public static void main(String[] args) throws java.lang.Exception {
        FastReader in = new FastReader();
        long[] a = new long[4];
        for (int i = 0; i < 4; i++) a[i] = in.nextLong();
        System.out.println(
                Math.max(a[0] * a[2], Math.max(a[1] * a[3], Math.max(a[0] * a[3], a[1] * a[2]))));
    }
}
assistant: import bisect
import collections
import copy
import heapq
import itertools
import math
import numpy
import string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())


a, b = LI()
if a > 0:
    print('Positive')
elif a <= 0 and b >= 0:
    print('Zero')
else:
    if (a + b) % 2 == 0:
        print('Negative')
    else:
        print('Positive')


user: import java.util.Scanner;

public class atcoder_AGC002_A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a > 0) {
            System.out.println("Positive");
        } else if (b >= 0) {
            System.out.println("Zero");
        } else if ((b - a + 1) % 2 == 0) {
            System.out.println("Positive");
        } else {
            System.out.println("Negative");
        }
    }
}
assistant: import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(* (MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N, M = MAP()
balls = [[1, 0] for _ in range(N)]
balls[0] = [0, 1]
for _ in range(M):
    x, y = MAP()
    w_x, r_x = balls[x - 1]
    w_y, r_y = balls[y - 1]
    if w_x >= 1 and r_x >= 1:
        balls[x - 1][0] -= 1
        balls[y - 1][1] += 1
    elif w_x == 0:
        balls[x - 1][1] -= 1
        balls[y - 1][1] += 1
    else:
        balls[x - 1][0] -= 1
        balls[y - 1][0] += 1
ans = 0
for i in range(N):
    if balls[i][1]:
        ans += 1
print(ans)


user: import java.util.Scanner;

public class atcoder_AGC002_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Box[] B = new Box[N];
        B[0] = new Box(1, true);
        for (int i = 1; i < N; i++) {
            B[i] = new Box(1, false);
        }
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            B[x].moveTo(B[y]);
        }
        int counter = 0;
        for (Box b : B) {
            if (b.red) {
                counter++;
            }
        }
        System.out.println(counter);
    }
}

class Box {
    public int num;
    public boolean red;

    public Box(int n, boolean r) {
        num = n;
        red = r;
    }

    public void moveTo(Box other) {
        if (num == 0) {
            return;
        } else if (num == 1) {
            num = 0;
            other.num++;
            if (red) {
                other.red = true;
            }
            red = false;
        } else {
            num--;
            other.num++;
            if (red) {
                other.red = true;
            }
        }
    }
}
assistant: N = int(input())
A = [int(input()) * N + i for i in range(N)]
A.sort()
cnt = 0
for i in range(N):
    d = (A[i] % N) % 2
    if d % 2 != i % 2:
        cnt += 1
print(cnt // 2)


user: import java.util.*;

public class atcoder_AGC003_C {
    static final int NUM = (int) (1e5 + 2);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        PriorityQueue<Integer> nums = new PriorityQueue<>();
        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            nums.add(tmp);
            map.put(tmp, i);
        }
        int bin = 0;
        int diff = 0;
        while (!nums.isEmpty()) {
            int num = nums.poll();
            int idx = map.get(num);
            if ((bin % 2) != (idx % 2)) {
                diff++;
            }
            bin++;
            bin %= 2;
        }
        int ans = (diff / 2);
        System.out.println(ans);
    }
}
assistant: def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    b = [[None for _ in [0] * n] for _ in [0] * n]
    for i in range(n):
        m = a[i]
        for j in range(n):
            k = i - j
            if k < 0:
                k += n
            m = min(m, a[k])
            b[j][i] = m
    m = 10 ** 15
    for i, j in enumerate(b):
        m = min(m, sum(j) + x * i)
    print(m)


main()


user: import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class atcoder_AGC004_B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long x = scan.nextLong();
        List<Long> srimeList = new ArrayList<>(N);
        for (long i = 0; i < N; i++) {
            srimeList.add(scan.nextLong());
        }
        List<Long[]> costList = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            costList.add(new Long[N]);
        }
        for (int i = 0; i < N; i++) {
            costList.get(i)[0] = srimeList.get(i);
            for (int castNum = 1; castNum < N; castNum++) {
                costList.get(i)[castNum] =
                        Math.min(
                                costList.get(i)[castNum - 1], srimeList.get((i - castNum + N) % N));
            }
        }
        List<Long> result = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            final int j = i;
            result.add(i * x + costList.stream().mapToLong(costArray -> costArray[j]).sum());
        }
        System.out.println(result.stream().mapToLong(i -> i).min().getAsLong());
    }
}
assistant: import sys
sys.setrecursionlimit(10 ** 6)


def dfs(links, n, k, v, p):
    height_from_leaf = 0
    cut_count = 0
    for u in links[v]:
        if u == 0:
            continue
        hgt, cut = dfs(links, n, k, u, v)
        height_from_leaf = max(height_from_leaf, hgt)
        cut_count += cut
    height_from_leaf += 1
    if p != 0 and height_from_leaf == k:
        height_from_leaf = 0
        cut_count += 1
    return height_from_leaf, cut_count


n, k, * aaa = map(int, sys.stdin.buffer.read().split())
links = [set() for _ in range(n)]
for i, a in enumerate(aaa):
    a -= 1
    links[a].add(i)
_, ans = dfs(links, n, k, 0, 0)
if aaa[0] != 1:
    ans += 1
print(ans)


user: import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class atcoder_AGC004_D {
    public static void main(String args[]) {
        new Thread(null, new MyRunnable(), "", 1 << 26).start();
    }
}

class MyRunnable implements Runnable {
    @Override
    public void run() {
        int n;
        int k;
        List<Integer> as = new ArrayList<>();
        try (Scanner sc = new Scanner(System.in)) {
            n = sc.nextInt();
            k = sc.nextInt();
            for (int i = 0; i < n; i++) {
                as.add(sc.nextInt() - 1);
            }
        }
        System.out.println(new Calculator(n, k, as).calculate());
    }
}

class Calculator {
    private int k;
    private int answer = 0;
    private boolean isCalculate = false;
    private List<List<Integer>> lists = new ArrayList<>();

    Calculator(int n, int k, List<Integer> as) {
        this.k = k;
        for (int i = 0; i < n; i++) {
            this.lists.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            int j = as.get(i);
            if (0 < i) {
                this.lists.get(j).add(i);
            } else if (0 < j) {
                this.answer++;
            }
        }
    }

    int calculate() {
        if (!this.isCalculate) {
            this.dfs(0, 0);
            this.isCalculate = true;
        }
        return this.answer;
    }

    private int dfs(int a, int pre) {
        int h = 0;
        for (int i : this.lists.get(a)) {
            h = Math.max(h, this.dfs(i, a));
        }
        if (0 < pre && h == this.k - 1) {
            h = 0;
            this.answer++;
        } else {
            h++;
        }
        return h;
    }
}
assistant: def root(x): return x if par[x] == x else root(par[x])
def same(x, y): return root(x) == root(y)


def unite(* z):
    x, y = map(root, z)
    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


n, * a = map(int, open(0).read().split())
* par, = range(n)
rank = [1] * n
size = [1] * n
b = [0] * n
for i, t in enumerate(a):
    b[t - 1] = i
c = 0
for k in b[:: - 1]:
    l = r = 1
    if k > 0 and a[k - 1] > a[k]:
        l += size[root(k - 1)]
        unite(k - 1, k)
    if k + 1 < n and a[k + 1] > a[k]:
        r += size[root(k + 1)]
        unite(k + 1, k)
    c += l * r * a[k]
print(c)


user: import java.util.ArrayDeque;
import java.util.Scanner;

public class atcoder_AGC005_B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = scan.nextInt();
        }
        int[] leftl = new int[N];
        int[] rightl = new int[N];
        ArrayDeque<Integer> que = new ArrayDeque<>();
        int index = 0;
        while (index < N) {
            while (!que.isEmpty() && a[que.peek()] > a[index]) {
                int ind = que.poll();
                rightl[ind] = index - ind - 1;
            }
            que.push(index++);
        }
        while (!que.isEmpty()) {
            int ind = que.poll();
            rightl[ind] = N - ind - 1;
        }
        index = N - 1;
        while (index >= 0) {
            while (!que.isEmpty() && a[que.peek()] > a[index]) {
                int ind = que.poll();
                leftl[ind] = ind - index - 1;
            }
            que.push(index--);
        }
        while (!que.isEmpty()) {
            int ind = que.poll();
            leftl[ind] = ind - index - 1;
        }
        long ans = 0;
        for (int i = 0; i < N; ++i) {
            ans += (long) a[i] * (leftl[i] + 1) * (rightl[i] + 1);
        }
        System.out.println(ans);
    }
}
assistant: n = int(input())
s = list(input())
t = list(input())
if s == t:
    print(n)
else:
    cnt = 0
    for i in range(n):
        for j in range(n - i):
            if s[i + j] != t[j]:
                break
            if j == n - i - 1:
                cnt = n - i
    print(2 * n - cnt)


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

public class atcoder_AGC006_A {
    static int N = 200 + 10;
    static int f[] = new int[N];
    static char b[] = new char[N];

    static void getFail(char b[], int m) {
        int j = 0;
        f[0] = f[1] = 0;
        for (int i = 2; i <= m; i++) {
            while (j > 0 && b[j + 1] != b[i]) j = f[j];
            if (b[j + 1] == b[i]) j++;
            f[i] = j;
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        String s1 = in.next(), str = in.next();
        int cnt = 0;
        for (int i = 0; i < n; i++) b[++cnt] = str.charAt(i);
        for (int i = 0; i < n; i++) b[++cnt] = s1.charAt(i);
        getFail(b, cnt);
        int len = Math.min(f[cnt], Math.min(n, n));
        out.println(2 * n - len);
        out.flush();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
assistant: from itertools import permutations
N, X = [int(_) for _ in input().split()]


def calc(x):
    def sub(y, debug=0):
        if debug:
            print("D", y)
        while len(y) > 1:
            y = [sorted(y[i: i + 3])[1] for i in range(len(y) - 2)]
            if debug:
                print("D", y)
        return y
    y = sub(x)
    if y[0] == 2:
        pass
        sub(x, 1)
        print("=", x)
    return y[0]


if X == 1 or X == N * 2 - 1:
    print("No")
else:
    print("Yes")
    if X == N * 2 - 2:
        xs = list(range(N - 1, X + 2)) + list(range(1, N - 1))
    else:
        ys = list(range(1, X - 1)) + list(range(X + 3, N * 2))
        xs = ys[: N - 3] + [X + 2, X - 1, X, X + 1] + ys[N - 3:]
    for x in xs:
        print(x)


user: import java.util.Scanner;
import java.util.stream.IntStream;

public class atcoder_AGC006_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        print(x, n);
    }

    public static void print(int x, int n) {
        int max = n * 2 - 1;
        if (x == 1 || x == max) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
        String sep = System.lineSeparator();
        String ans =
                IntStream.range(x + n - 1, x + n + max - 1)
                        .mapToObj(e -> (e % max + 1) + sep)
                        .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
                        .toString();
        System.out.println(ans);
    }
}
assistant: import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, d, x = map(int, read().split())


def main(N, d, x):
    ret = 0
    while N:
        ret += d + (N - 0.5) * x
        d = d + (d / N) + (5 * x) / (2 * N)
        x += 2 * x / N
        N -= 1
    return ret


print(main(N, d, x))


user: import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;

public class atcoder_AGC007_C {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double N = scan.nextDouble();
        double d = scan.nextDouble();
        double x = scan.nextDouble();
        BigDecimal ans = new BigDecimal("0.0");
        while (N > 0.5) {
            BigDecimal adnum = BigDecimal.valueOf(d + x * (N - 0.5));
            ans = ans.add(adnum);
            d = (N + 1.0) * d / N + (5.0 * x) / (2.0 * N);
            x = (1.0 + (2.0 / N)) * x;
            --N;
        }
        DecimalFormat format = new DecimalFormat("#.#");
        format.setMinimumFractionDigits(20);
        System.out.println(format.format(ans));
    }
}
assistant: n, a = int(input()), list(map(int, input().split()))
if sum(a) % (n * (n + 1) / 2):
    print("NO")
else:
    k = sum(a) / (n * (n + 1) / 2)
    a += [a[0]]
    if sum([(k - i + j) % n for i, j in zip(a[1:], a)]) or sum([(k - i + j) / n >= 0 for i, j in zip(a[1:], a)]) != n:
        print("NO")
    else:
        print("YES")


user: import java.util.Scanner;

public class atcoder_AGC010_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) A[i] = scanner.nextInt();
        if (possible(N, A)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean possible(int N, int[] A) {
        long sum = 0;
        for (int i = 0; i < N; i++) sum += A[i];
        long NS = (long) N * (N + 1) / 2;
        if (sum % NS != 0) return false;
        long K = sum / NS;
        for (int i = 0; i < N; i++) {
            int j = i == 0 ? N - 1 : i - 1;
            long d = K - (A[i] - A[j]);
            if (d < 0 || d % N != 0) return false;
        }
        return true;
    }
}