zccneil/codelingua_dataset huggingface dataset:
assistant: def binary_search(key):
    bad, good = - 1, len(ans)
    while good - bad > 1:
        mid = (bad + good) // 2
        if ans[mid][- 1] < key:
            good = mid
        else:
            bad = mid
    return good


N = int(input())
ans = []
for _ in range(N):
    A = int(input())
    idx = binary_search(A)
    if idx == len(ans):
        ans.append([A])
    else:
        ans[idx].append(A)
print(len(ans))


user: import java.util.*;

public class atcoder_ABC134_E {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        while (n-- > 0) {
            int num = sc.nextInt();
            if (map.lowerKey(num) == null) {
                int val = map.getOrDefault(num, 0);
                map.put(num, ++val);
            } else {
                int key = map.lowerKey(num);
                int val = map.get(key);
                if (val == 1) {
                    map.remove(key);
                } else {
                    map.put(key, --val);
                }
                val = map.getOrDefault(num, 0);
                map.put(num, ++val);
            }
        }
        int ans = 0;
        for (Integer key : map.keySet()) {
            int val = map.get(key);
            ans += val;
        }
        System.out.println(ans);
    }
}
assistant: import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)


def input():
    return sys.stdin.readline()[: - 1]


mod = 10 ** 9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))


def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list, zip(* read_all))


S = str(input())
n = len(S)
if n == 1:
    if S == '5' or S == '?':
        print(1)
    else:
        print(0)
    exit()
dp = [[0] * 13 for i in range(n)]
for i in range(n):
    if i == 0:
        if S[i] != '?':
            dp[i][int(S[i])] += 1
        else:
            for j in range(10):
                dp[i][j] += 1
    else:
        if S[i] != '?':
            for k in range(13):
                dp[i][(k * 10 + int(S[i])) % 13] += dp[i - 1][k]
        else:
            for j in range(10):
                for k in range(13):
                    dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
        for k in range(13):
            dp[i][k] %= mod
print(dp[n - 1][5])


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

public class atcoder_ABC135_D {
    public static void main(String[] args) {
        new atcoder_ABC135_D().run();
    }

    final long MOD = (long) 1e9 + 7;

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] cs = sc.next().toCharArray();
        long[][] dp = new long[cs.length][13];
        int base = 1;
        for (int i = 0; i < cs.length; ++i) {
            if (cs[cs.length - 1 - i] == '?') {
                for (int pre = 0; pre < 13; ++pre) {
                    for (int next = 0; next < 10; ++next) {
                        dp[i][(base * next + pre) % 13] +=
                                (i > 0 ? dp[i - 1][pre] : (pre == 0 ? 1 : 0));
                        dp[i][(base * next + pre) % 13] %= MOD;
                    }
                }
            } else {
                int next = cs[cs.length - 1 - i] - '0';
                for (int pre = 0; pre < 13; ++pre) {
                    dp[i][(base * next + pre) % 13] +=
                            (i > 0 ? dp[i - 1][pre] : (pre == 0 ? 1 : 0));
                    dp[i][(base * next + pre) % 13] %= MOD;
                }
            }
            base = base * 10 % 13;
        }
        System.out.println(dp[dp.length - 1][5]);
    }

    void tr(Object... objects) {
        System.out.println(Arrays.deepToString(objects));
    }
}
assistant: def main():
    N = int(input())
    i = 1
    ans = 0
    while 10 ** i <= N:
        ans += ((10 ** i) - (10 ** (i - 1)))
        i += 2
    ans += max(0, N - 10 ** (i - 1) + 1)
    print(ans)


if __name__ == "__main__":
    main()


user: import java.util.*;

public class atcoder_ABC136_B {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int count = 0;
        int temp = N;
        int ans = 0;
        while (temp > 0) {
            temp /= 10;
            count++;
        }
        for (int i = 1; i <= count; i++) {
            if (i == count) {
                if (i % 2 == 1) {
                    ans += (N - Math.pow(10, i - 1) + 1);
                }
            } else {
                if (i == 1) {
                    ans += 9;
                } else if (i % 2 == 1) {
                    ans += (Math.pow(10, i) - Math.pow(10, i - 1));
                }
            }
        }
        System.out.println(ans);
    }
}
assistant: import heapq
n, m = map(int, input().split())
x = []
y = []
for i in range(n):
    day, salary = map(int, input().split())
    heapq.heappush(x, (- day, - salary))
while x:
    d, s = heapq.heappop(x)
    r = m - len(y)
    if r >= - d:
        heapq.heappush(y, - s)
    else:
        heapq.heappush(y, - s)
        heapq.heappop(y)
print(sum(y))


user: import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

class Job implements Comparable<Job> {
    int a;
    int b;

    Job(int a, int b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public int compareTo(Job otherJob) {
        if (otherJob.a == this.a) return this.b - otherJob.b;
        else return this.a - otherJob.a;
    }
}

public class atcoder_ABC137_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" \u2581 ");
        int N = Integer.parseInt(line[0]);
        int M = Integer.parseInt(line[1]);
        Queue<Job> q = new PriorityQueue<>();
        for (int i = 0; i < N; i++) {
            line = sc.nextLine().split(" \u2581 ");
            q.add(new Job(Integer.parseInt(line[0]), Integer.parseInt(line[1])));
        }
        int cnt = 0;
        Queue<Integer> jobQ = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 1; i <= M; i++) {
            while (!q.isEmpty()) {
                Job job = q.peek();
                if (job.a <= i) {
                    jobQ.add(q.poll().b);
                } else break;
            }
            if (!jobQ.isEmpty()) cnt += jobQ.poll();
        }
        System.out.println(cnt);
    }
}
assistant: a, b = map(int, input().split())
hole = 1
i = 0
check = True
while check:
    if hole >= b:
        check = False
    else:
        hole = a * (i + 1) - i
        i += 1
print(i)


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

public class atcoder_ABC139_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int amari = 0;
        int result = 0;
        result = (B - 1) / (A - 1);
        amari = (B - 1) % (A - 1);
        if (amari != 0) {
            result += 1;
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(result);
        sc.close();
        out.flush();
    }
}
assistant: from collections import deque
import scipy
import numpy
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)
N = gi()
K = gi()
S = gw()
seg_cnt = 0
for i in range(0, N - 1):
    if S[i] != S[i + 1]:
        seg_cnt += 1
cur_happy = N - 1 - seg_cnt
if 2 * K >= seg_cnt:
    ans = N - 1
else:
    ans = cur_happy + 2 * K
print(ans)


user: import java.util.*;

public class atcoder_ABC140_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        String S = sc.next();
        char[] c1 = S.toCharArray();
        char[] c3 = S.toCharArray();
        boolean flag = false;
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (flag && c1[i] == 'R') {
                flag = false;
                count++;
            }
            if (count == K) {
                break;
            }
            if (c1[i] == 'L') {
                flag = true;
                c1[i] = 'R';
            }
        }
        flag = false;
        count = 0;
        for (int i = 0; i < N; i++) {
            if (flag && c3[i] == 'L') {
                flag = false;
                count++;
            }
            if (count == K) {
                break;
            }
            if (c3[i] == 'R') {
                flag = true;
                c3[i] = 'L';
            }
        }
        String S1 = new String(c1);
        String S3 = new String(c3);
        count = 1;
        int sum1 = 0;
        char bef = S1.charAt(0);
        for (int i = 1; i < N; i++) {
            if (S1.charAt(i) == bef) {
                count++;
                if (i == N - 1) {
                    sum1 += count - 1;
                }
            } else {
                bef = S1.charAt(i);
                sum1 += count - 1;
                count = 1;
            }
        }
        count = 1;
        int sum3 = 0;
        bef = S3.charAt(0);
        for (int i = 1; i < N; i++) {
            if (S3.charAt(i) == bef) {
                count++;
                if (i == N - 1) {
                    sum3 += count - 1;
                }
            } else {
                bef = S3.charAt(i);
                sum3 += count - 1;
                count = 1;
            }
        }
        System.out.println(Math.max(sum1, sum3));
    }
}
assistant: import sys
def I(): return (int(sys.stdin.readline()))
def LI(): return ([int(x) for x in sys.stdin.readline().split()])


def main():
    N = I()
    S = sorted(LI(), reverse=True)
    flag = [True] * len(S)
    cur = []
    cur.append(S[0])
    flag[0] = False
    for i in range(N):
        j = 0
        jM = len(cur)
        for k in range(len(S)):
            if flag[k] and S[k] < cur[j]:
                cur.append(S[k])
                j += 1
                flag[k] = False
                if j == jM:
                    break
        else:
            return ("No")
        cur.sort(reverse=True)
    return ("Yes")


if __name__ == "__main__":
    print(main())


user: import java.util.*;

public class atcoder_ABC140_F {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int size = (1 << N);
        int[] S = new int[size];
        boolean[] spawned = new boolean[size];
        spawned[size - 1] = true;
        for (int i = 0; i < size; i++) S[i] = sc.nextInt();
        Arrays.sort(S);
        List<Integer> active = new ArrayList<>();
        active.add(S[size - 1]);
        spawned[size - 1] = true;
        for (int i = 0; i < N; i++) {
            active.sort(Collections.reverseOrder());
            List<Integer> activated = new ArrayList<>();
            int next = size - 1;
            for (int slime : active) {
                while (next >= 0 && (S[next] >= slime || spawned[next])) {
                    next--;
                }
                if (next < 0) {
                    System.out.println("No");
                    return;
                }
                spawned[next] = true;
                activated.add(S[next]);
            }
            active.addAll(activated);
        }
        System.out.println("Yes");
    }
}
assistant: from math import *


def next_int():
    return int(input())


def next_ints():
    return list(map(int, input().split()))


n = next_int()
t = 0
for i in range(n):
    if i + 1 & 1:
        t += 1
print(t / n)


user: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class atcoder_ABC142_A {
    public static void main(String[] args) throws Exception {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            double input = Double.parseDouble(br.readLine());
            double countOdd = Math.round(input / 2);
            BigDecimal result = new BigDecimal(countOdd / input);
            result.setScale(10, RoundingMode.HALF_UP);
            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}
assistant: from operator import itemgetter
N = int(input())
A = [(i + 1, int(x)) for i, x in enumerate(input().split())]
A_ = sorted(A, key=itemgetter(1))
A__ = [a[0] for a in A_]
for i in A__[: - 1]:
    print(i, end=' ')
print(A__[- 1])


user: import java.util.*;

public class atcoder_ABC142_C {
    public static List<Integer> P;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Map<Integer, Integer> idorder = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            int A = scanner.nextInt();
            idorder.put(A, i);
        }
        for (int i = 1; i <= N; i++) {
            System.out.print(idorder.get(i));
            System.out.print(" ");
        }
    }
}
assistant: A, B = map(int, input().split())
ans = A - 2 * B
if ans < 0:
    ans = 0
print(ans)


user: import java.io.BufferedReader;
import java.io.InputStreamReader;

public class atcoder_ABC143_A {
    public static void main(String[] args) {
        try {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            String[] x = bf.readLine().trim().split(" ");
            int a = Integer.parseInt(x[0]);
            int b = Integer.parseInt(x[1]);
            int c = a - b * 2;
            if (c < 0) c = 0;
            System.out.println(c);
        } catch (Exception e) {
        }
    }
}
assistant: from bisect import bisect_right, bisect_left
n, * l = map(int, open(0).read().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = l[i]
        b = l[j]
        right = bisect_left(l, a + b)
        left = bisect_right(l, max(a - b, b - a))
        tmp = max(0, right - left)
        if left <= i < right:
            tmp -= 1
        if left <= j < right:
            tmp -= 1
        ans += tmp
print(ans // 3)


user: import java.util.*;

public class atcoder_ABC143_D {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        List<Integer> L = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            L.add(scanner.nextInt());
        }
        Collections.sort(L);
        int count = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int a = L.get(i);
                int b = L.get(j);
                int res = find(L, j + 1, a + b);
                count = count + res;
            }
        }
        System.out.println(count);
    }

    public static int find(List<Integer> li, int from, int target) {
        int low = from;
        int upp = li.size() - 1;
        int mid = (upp - low + 1) % 2 == 0 ? (low + upp) / 2 + 1 : (low + upp) / 2;
        if (upp - low < 0) {
            return 0;
        } else if (li.get(from) >= target) {
            return 0;
        } else if (li.get(upp) < target) {
            return upp - low + 1;
        }
        while (upp - low > 1) {
            if (li.get(mid) >= target) {
                upp = mid;
            } else {
                low = mid;
            }
            mid = (upp - low + 1) % 2 == 0 ? (low + upp) / 2 + 1 : (low + upp) / 2;
        }
        return low - from + 1;
    }
}
assistant: n = int(input())
s = input()
if n % 2 != 0:
    print('No')
elif s[: int(n / 2)] == s[int(n / 2):]:
    print('Yes')
else:
    print('No')


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

public class atcoder_ABC145_B {
    public static void cout(String str) {
        System.out.println(str);
    }
    ;

    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        String a = "", b = "", str;
        int n;
        n = cin.nextInt();
        cin.nextLine();
        str = cin.nextLine();
        for (int i = 0; i < n / 2; i++) {
            a = a + str.charAt(i);
        }
        if (str.equals(a + a)) cout("Yes");
        else cout("No");
    }
}
;
assistant: import sys
import itertools


def solve(N: int, x: "List[int]", y: "List[int]"):
    indices = [i for i in range(N)]
    permutations = itertools.permutations(indices)
    distances = []
    for permutation in permutations:
        total_distance = 0
        for i in range(0, N - 1):
            f, t = permutation[i: i + 2]
            distance = ((x[t] - x[f]) ** 2 + (y[t] - y[f]) ** 2) ** 0.5
            total_distance += distance
        distances.append(total_distance)
    result = sum(distances) / len(distances)
    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    x = [int()] * (N)
    y = [int()] * (N)
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == "__main__":
    main()


user: import java.util.Scanner;

public class atcoder_ABC145_C {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[][] pos = new int[N][2];
        for (int i = 0; i < N; i++) {
            pos[i][0] = scanner.nextInt();
            pos[i][1] = scanner.nextInt();
        }
        double sum = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i == j) continue;
                sum += dist(pos[i][0], pos[i][1], pos[j][0], pos[j][1]);
            }
        }
        System.out.println(sum / N);
    }

    private static double dist(int x1, int y1, int x2, int y2) {
        return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    }
}
assistant: import sys
from operator import itemgetter
input = sys.stdin.readline
TIME = 0
VAL = 1
N, T = [int(a) for a in input().split()]
time_value = [(- 1, - 1)] + [None] * (N)
for i in range(1, N + 1):
    time_value[i] = tuple(int(a) for a in input().split())
time_value.sort(key=itemgetter(VAL))
dp = [[- 1] * T for _ in range(N + 1)]
for t in range(0, T):
    dp[0][t] = 0
for n in range(1, N + 1):
    dp[n][0] = 0
    for t in range(1, T):
        if time_value[n][TIME] > t:
            dp[n][t] = dp[n - 1][t]
        else:
            dp[n][t] = max(dp[n - 1][t], time_value[n][VAL] +
                           dp[n - 1][t - time_value[n][TIME]])
val_acum = time_value[N][VAL]
t = T - 1
max_val = val_acum + dp[N - 1][t]
for n in range(N - 1, 0, - 1):
    val_acum += time_value[n][VAL]
    t -= time_value[n + 1][TIME]
    if t < 0:
        break
    else:
        max_val = max(max_val, val_acum + dp[n - 1][t])
print(max_val)


user: import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class atcoder_ABC145_E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[][] AB = new int[N][2];
        for (int i = 0; i < N; i++) {
            AB[i][0] = sc.nextInt();
            AB[i][1] = sc.nextInt();
        }
        Arrays.sort(AB, Comparator.comparingInt(a -> a[0]));
        int[][] dp = new int[N + 1][6001];
        for (int i = 1; i <= N; i++) {
            for (int timeAfterEat = 0; timeAfterEat <= 6000; timeAfterEat++) {
                dp[i][timeAfterEat] = Math.max(dp[i][timeAfterEat], dp[i - 1][timeAfterEat]);
                int time = AB[i - 1][0];
                int value = AB[i - 1][1];
                if (0 <= timeAfterEat - time && timeAfterEat - time < T) {
                    dp[i][timeAfterEat] =
                            Math.max(dp[i][timeAfterEat], dp[i - 1][timeAfterEat - time] + value);
                }
            }
        }
        System.out.println(Arrays.stream(dp[N]).max().getAsInt());
    }
}
assistant: from collections import deque
import sys
input = sys.stdin.readline


def bfs(v, N, G, E):
    visited = [0] * N
    queue = deque()
    K = - 1
    node2color = [- 1 for _ in range(N)]
    queue.append(v)
    visited[v] = 1
    while queue:
        q = queue.popleft()
        color = 0
        for nex in G[q]:
            if visited[nex]:
                continue
            visited[nex] = 1
            color += 1
            if color == node2color[q]:
                color += 1
            node2color[nex] = color
            E[(min(q, nex), max(q, nex))] = color
            queue.append(nex)
        K = max(K, color)
    return K


def main():
    N = int(input())
    G = [deque() for _ in range(N)]
    E = dict()
    for i in range(N - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        G[b].append(a)
        E[(a, b)] = 0
    K = bfs(0, N, G, E)
    print(K)
    for value in E.values():
        print(value)


main()


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

public class atcoder_ABC146_D {
    static int n;
    static List<ArrayList<Edge>> g;
    static int[] ans;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        g = new ArrayList();
        for (int i = 0; i < n; i++) {
            g.add(new ArrayList<Edge>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = Integer.parseInt(sc.next()) - 1;
            int b = Integer.parseInt(sc.next()) - 1;
            g.get(a).add(new Edge(i, b));
            g.get(b).add(new Edge(i, a));
        }
        ans = new int[n - 1];
        dfs(0, -1, -1);
        int max = 0;
        for (int temp : ans) {
            max = Math.max(max, temp);
        }
        System.out.println(max);
        for (int c : ans) {
            System.out.println(c);
        }
    }

    static void dfs(int to, int color, int parents) {
        int k = 1;
        for (Edge e : g.get(to)) {
            if (e.to == parents) continue;
            if (k == color) k++;
            ans[e.id] = k;
            dfs(e.to, k, to);
            k++;
        }
    }
}

class Edge {
    Edge(int id, int to) {
        this.id = id;
        this.to = to;
    }

    int id;
    int to;
}
assistant: import numpy as np
N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)
result = 0
for b in range(60):
    bs = int(((A >> b) & 1).sum())
    result = (result + bs * (N - bs) * (1 << b)) % 1000000007
print(result)


user: import java.util.*;

public class atcoder_ABC147_D {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long div = (long) Math.pow(10, 9) + 7;
        long[] A = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextLong();
        }
        for (int i = 0; i < 60; i++) {
            long a = 0;
            long count1 = 0;
            for (int j = 0; j < n; j++) {
                if ((A[j] >> i & 1) == 1) count1++;
            }
            a = a + count1 * (n - count1);
            for (int j = 0; j < i; j++) {
                a = (a << 1) % div;
            }
            ans += a;
            ans %= div;
        }
        System.out.println(ans);
        long endTime = System.currentTimeMillis();
    }
}