zccneil/codelingua_dataset huggingface dataset:
assistant: from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys
import bisect
import math
import itertools
import pprint
import fractions
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


n, ta, ao = inpl()
ta -= 1
ao -= 1
g = [[] for i in range(n)]
for i in range(n - 1):
    a, b = inpl()
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
ta_dist = [None] * n
ta_dist[ta] = 0
ao_dist = [None] * n
ao_dist[ao] = 0


def ta_dfs(node):
    for v in g[node]:
        if ta_dist[v] != None:
            continue
        ta_dist[v] = ta_dist[node] + 1
        ta_dfs(v)


def ao_dfs(node):
    for v in g[node]:
        if ao_dist[v] != None:
            continue
        ao_dist[v] = ao_dist[node] + 1
        ao_dfs(v)


ao_dfs(ao)
ta_dfs(ta)
res = 0
for i in range(n):
    if ta_dist[i] > ao_dist[i]:
        continue
    res = max(res, ao_dist[i])
print(res - 1)


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

public class atcoder_ABC148_F {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            List<Integer>[] edges = new List[N];
            for (int i = 0; i < N; i++) {
                edges[i] = new ArrayList<>();
            }
            for (int i = 0; i < N - 1; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                edges[a].add(b);
                edges[b].add(a);
            }
            int[] d = new int[N];
            for (int i = 0; i < N; i++) {
                d[i] = Integer.MAX_VALUE;
            }
            d[u] = 0;
            dfs(u, d, edges);
            int[] e = new int[N];
            for (int i = 0; i < N; i++) {
                e[i] = Integer.MAX_VALUE;
            }
            e[v] = 0;
            dfs(v, e, edges);
            int q = -1;
            for (int i = 0; i < N; i++) {
                if (d[i] < e[i]) {
                    if (e[i] > q) {
                        q = e[i];
                    }
                }
            }
            if (q <= 0) {
                System.out.println(0);
            } else {
                System.out.println(q - 1);
            }
        }
    }

    static void dfs(int u, int[] d, List<Integer>[] edges) {
        for (Integer nu : edges[u]) {
            if (d[nu] == Integer.MAX_VALUE) {
                d[nu] = d[u] + 1;
                dfs(nu, d, edges);
            }
        }
    }
}
assistant: cookies = [int(x) for x in input().split()]
leftOver = cookies[0] - cookies[2]
takahashi = max(0, leftOver)
print(str(takahashi) + ' ' +
      (str(cookies[1]) if takahashi > 0 else str(max(0, cookies[1] - abs(leftOver)))))


user: import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class atcoder_ABC149_B {
    long A, B, K;
    long x, y;

    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
        BufferedReader in = new BufferedReader(reader);
        atcoder_ABC149_B ins = new atcoder_ABC149_B(in);
        ins.calc();
        ins.showResult();
    }

    atcoder_ABC149_B(BufferedReader in) throws IOException {
        String[] tokens = in.readLine().split(" ");
        A = Long.parseLong(tokens[0]);
        B = Long.parseLong(tokens[1]);
        K = Long.parseLong(tokens[2]);
    }

    void calc() {
        x = A;
        y = B;
        x = A - K;
        if (x < 0) {
            y = B + x;
            x = 0;
            if (y < 0) {
                y = 0;
            }
        }
    }

    void showResult() {
        System.out.println(x + " " + y);
    }
}
assistant: X = int(input())
prime = [True] * (100010)
prime[0] = False
prime[1] = False
for i in range(4, 100010, 2):
    prime[i] = False
i = 3
while (i * i <= 100008):
    if prime[i]:
        for j in range(i + i, 100008, i):
            prime[j] = False
    i += 2
for i in range(X, 100008):
    if prime[i]:
        print(i)
        break


user: import java.util.Scanner;

public class atcoder_ABC149_C {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int x = Integer.parseInt(stdIn.next());
        if (x != 2 && x % 2 == 0) x++;
        while (true) {
            int i;
            double sqrtNum = Math.sqrt(x);
            for (i = 3; i <= sqrtNum; i += 2) {
                if (x % i == 0) break;
            }
            if (i > sqrtNum) break;
            x += 2;
        }
        System.out.println(x);
    }
}
assistant: import itertools
n = int(input())
orig = list(itertools.permutations(list(range(1, n + 1))))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
pn = orig.index(p)
qn = orig.index(q)
print(abs(pn - qn))


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

public class atcoder_ABC150_C {
    public static List<String> permutation(List<String> list, String target, String ans) {
        if (target.length() <= 1) {
            list.add(ans + target);
        } else {
            for (int i = 0; i < target.length(); i++) {
                permutation(
                        list,
                        target.substring(0, i) + target.substring(i + 1),
                        ans + target.charAt(i));
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        String[][] line = new String[2][1];
        for (int i = 0; i < 2; i++) {
            Arrays.fill(line[i], "");
            for (int j = 0; j < n; j++) {
                line[i][0] += scanner.next();
            }
        }
        String number = "";
        for (int i = 1; i <= n; i++) {
            number += i;
        }
        List<String> listA = new ArrayList<>();
        permutation(listA, number, "");
        int sum = 0;
        for (int j = 0; j < line.length; j++) {
            for (int i = 0; i < listA.size(); i++) {
                if (listA.get(i).equals(line[j][0])) {
                    if (sum == 0) {
                        sum += i;
                    } else {
                        sum -= i;
                    }
                }
            }
        }
        System.out.println(Math.abs(sum));
    }
}
assistant: import fractions
import math
n, num = map(int, input().split())
num_set = set(map(lambda x: int(x), input().split()))
two_times_set = set()
for i in num_set:
    for j in range(1, 30):
        i //= 2
        if i % 2 != 0:
            two_times_set.add(j)
            break
    if len(two_times_set) != 1:
        print(0)
        break
else:
    num_list = list(num_set)
    lcm = num_list[0]
    for i in range(1, len(num_list)):
        lcm = lcm * num_list[i] // fractions.gcd(lcm, num_list[i])
    print((num - lcm // 2) // (lcm) + 1)


user: import java.util.*;

public class atcoder_ABC150_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next()) / 2;
        }
        long gcd;
        long lcd = 1;
        for (int i = 0; i < n; i++) {
            gcd = getGCD(lcd, a[i]);
            lcd = lcd * a[i] / gcd;
            if (lcd > m) {
                System.out.println(0);
                return;
            }
        }
        for (int i = 0; i < n; i++) {
            if ((lcd / a[i]) % 2 == 0) {
                System.out.println(0);
                return;
            }
        }
        System.out.println((m / lcd + 1) / 2);
    }

    public static long getGCD(long a, long b) {
        if (b == 0) {
            return a;
        } else {
            return getGCD(b, a % b);
        }
    }
}
assistant: mod = 10 ** 9 + 7
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)
b = pow(2, 2 * n - 2, mod)
a = 2 * b % mod
ans = 0
for i in range(n):
    ans += c[i] * (a + i * b)
    ans %= mod
print(ans)


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

public class atcoder_ABC150_E {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sa = br.readLine().split(" ");
        int n = Integer.parseInt(sa[0]);
        sa = br.readLine().split(" ");
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = Integer.parseInt(sa[i]);
        }
        br.close();
        int mod = 1000000007;
        if (n == 1) {
            System.out.println(c[0] * 2 % mod);
            return;
        }
        Arrays.parallelSort(c);
        long b = power(2, n);
        long a = power(2, n - 2);
        long ans = 0;
        for (int i = 2; i <= n + 1; i++) {
            long val = a * i % mod;
            val *= c[n + 1 - i];
            val %= mod;
            ans += val;
            ans %= mod;
        }
        ans *= b;
        ans %= mod;
        System.out.println(ans);
    }

    static long power(long x, long n) {
        if (n == 0) {
            return 1;
        }
        int mod = 1000000007;
        long val = power(x, n / 2);
        val = val * val % mod;
        if (n % 2 == 1) {
            val = val * x % mod;
        }
        return val;
    }
}
assistant: import sys
import math
debug = False


def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string=None):
    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1: - 1]
    c = [e for e in lines[0].split(" ")][0]
    return (c, )


def solve(c):
    a = "abcdefghijklmnopqrstuvwxyz"
    i = a.index(c)
    return a[i + 1]


def main():
    result = solve(* parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')


if __name__ == '__main__':
    main()


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

public class atcoder_ABC151_A {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
        String s;
        String sl[];
        s = r.readLine();
        System.out.printf("%c", s.charAt(0) + 1);
    }
}

class RemRing {
    long module;

    public RemRing(long module) {
        this.module = module;
    }

    public long sum(long a, long b) {
        return (a + b + module) % module;
    }

    public long sub(long a, long b) {
        return (a - b + module) % module;
    }

    public long prod(long a, long b) {
        return (a * b) % module;
    }

    public long div(long a, long b) {
        return (a * inv(b)) % module;
    }

    public long inv(long a) {
        long b = this.module;
        long u = 1;
        long v = 0;
        while (b > 0) {
            long t = a / b;
            a -= t * b;
            u -= t * v;
            long z = a;
            a = b;
            b = z;
            z = u;
            u = v;
            v = z;
        }
        u %= this.module;
        if (u < 0) u += this.module;
        return u;
    }
}
assistant: import numpy as np
N = int(input())
n = [int(x) for x in input().split()]
n = np.array(n)
a = 1
pos = 0
for i in range(1, N):
    if n[pos] > n[i]:
        a += 1
        pos = i
print(a)


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

public class atcoder_ABC152_C {
    public static void main(String[] args) {
        System.out.println(solve());
    }

    public static int solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        int sum = 0;
        Queue<Integer> q = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            q.add(arr[i]);
            if (arr[i] <= q.peek()) {
                sum++;
            }
        }
        return sum;
    }
}
assistant: from fractions import gcd


def lcm(a, b):
    return a * b / gcd(a, b)


MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
_lcm = 1
for a in A:
    _lcm = _lcm * a // gcd(_lcm, a)
ans = _lcm * sum([pow(s, MOD - 2, MOD) for s in A]) % MOD
print(int(ans % MOD))


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

public class atcoder_ABC152_E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        sc.close();
        BigInteger lcm = BigInteger.ONE;
        for (int ai : A) {
            BigInteger a = BigInteger.valueOf(ai);
            lcm = lcm.divide(lcm.gcd(a)).multiply(a);
        }
        long mod = 1000000007;
        long modLcm = lcm.remainder(BigInteger.valueOf(mod)).longValue();
        long ans = 0;
        for (int ai : A) ans = (ans + modDiv(modLcm, ai, mod)) % mod;
        System.out.println(ans);
    }

    private static long modDiv(long a, long b, long mod) {
        return (a % mod) * modInv(b, mod) % mod;
    }

    private static long modInv(long x, long mod) {
        return modPow(x, mod - 2, mod);
    }

    private static long modPow(long b, long e, long mod) {
        long ans = 1;
        long x = b % mod;
        for (long y = e; y != 0; y >>= 1) {
            if ((y & 1) == 1) ans = (ans * x) % mod;
            x = (x * x) % mod;
        }
        return ans;
    }
}
assistant: h, a = map(int, input().split(" "))
sho = int(h / a)
am = int(h % a)
if am != 0:
    sho += 1
else:
    pass
print(sho)


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

public class atcoder_ABC153_A {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] str = in.readLine().split(" ");
        int h = Integer.parseInt(str[0]);
        int a = Integer.parseInt(str[1]);
        int num = 0;
        for (int i = 1; h > 0; i++) {
            h = h - a;
            num++;
        }
        System.out.println(num);
    }
}
assistant: import sys


def solve(S: str, T: str, A: int, B: int, U: str):
    if S == U:
        A -= 1
    if T == U:
        B -= 1
    print(A, B)
    return


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


if __name__ == '__main__':
    main()


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

public class atcoder_ABC154_A {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] str = in.readLine().split(" ");
        StringTokenizer st = new StringTokenizer(in.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        String u = in.readLine();
        System.out.println(u.equals(str[0]) ? (a - 1) + " " + b : a + " " + (b - 1));
    }
}
assistant: N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ll = - 10 ** 18 - 1
rr = 10 ** 18 + 1
while ll + 1 < rr:
    x = (ll + rr) // 2
    tot = 0
    for i in range(N):
        if A[i] < 0:
            l = - 1
            r = N
            while l + 1 < r:
                c = (l + r) // 2
                if A[i] * A[c] < x:
                    r = c
                else:
                    l = c
            tot += N - r
        else:
            l = - 1
            r = N
            while l + 1 < r:
                c = (l + r) // 2
                if A[i] * A[c] < x:
                    l = c
                else:
                    r = c
            tot += r
        if A[i] * A[i] < x:
            tot -= 1
    tot //= 2
    if tot < K:
        ll = x
    else:
        rr = x
print(ll)


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

public class atcoder_ABC155_D {
    static int mod = (int) 1e9 + 7;
    static int DX[] = {-1, 0, 1, 0}, DY[] = {0, -1, 0, 1};
    static int n;
    static long k;
    static long a[];

    public static void main(String[] args) {
        Scanner fs = new Scanner(System.in);
        n = fs.nextInt();
        k = fs.nextLong();
        a = new long[n];
        for (int i = 0; i < n; ++i) {
            a[i] = fs.nextLong();
        }
        Arrays.sort(a);
        long INF = (long) (1e18) + 1;
        long l = -INF;
        long r = INF;
        while (l + 1 < r) {
            long c = (l + r) / 2;
            if (check(c)) l = c;
            else r = c;
        }
        System.out.println(l);
    }

    static boolean check(long x) {
        long tot = 0;
        for (int i = 0; i < n; i++) {
            long now = a[i];
            int l = 0, r = n;
            if (now >= 0) {
                while (l < r) {
                    int c = (l + r) / 2;
                    if (now * a[c] < x) l = c + 1;
                    else r = c;
                }
                tot += l;
            } else {
                while (l < r) {
                    int c = (l + r) / 2;
                    if (now * a[c] >= x) l = c + 1;
                    else r = c;
                }
                tot += (n - l);
            }
            if ((long) a[i] * a[i] < x) tot--;
        }
        if (tot / 2 < k) return true;
        else return false;
    }
}
assistant: import sys
input_methods = ['clipboard', 'file', 'key']
using_method = 0
input_method = input_methods[using_method]
def IN(): return map(int, input().split())


mod = 1000000007


def main_b():
    s = input()
    pp = 0
    na = 0
    for i, c in enumerate(s[:: - 1]):
        cc = na + int(c)
        na = 0
        if cc <= 4:
            pp += cc
        else:
            na = 1
            if i == len(s) - 1:
                pp += 1
            pp += 10 - cc
    print(pp)


def main():
    s = input()
    pmin = 1000
    mmin = 0
    s = '0' + s
    for c in s[:: - 1]:
        v = int(c)
        npmin = min(pmin + 10 - (v + 1), mmin + 10 - v)
        nmmin = min(pmin + v + 1, mmin + v)
        pmin = npmin
        mmin = nmmin
    return min(pmin, mmin)


isTest = False


def pa(v):
    if isTest:
        print(v)


def input_clipboard():
    import clipboard
    input_text = clipboard.get()
    input_l = input_text.splitlines()
    for l in input_l:
        yield l


if __name__ == "__main__":
    if sys.platform == 'ios':
        if input_method == input_methods[0]:
            ic = input_clipboard()
            def input(): return ic.__next__()
        elif input_method == input_methods[1]:
            sys.stdin = open('inputFile.txt')
        else:
            pass
        isTest = True
    else:
        pass
    ret = main()
    if ret is not None:
        print(ret)


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

public class atcoder_ABC155_E {
    public static void main(String[] args) {
        final long INF = (long) 1e15;
        Scanner sc = new Scanner(System.in);
        String number = sc.next();
        int[] digits = new int[number.length() + 1];
        for (int i = 0; i < number.length(); i++) {
            digits[i] = number.charAt(number.length() - 1 - i) - '0';
        }
        int bills = 0;
        for (int i = 0; i <= number.length(); i++) {
            if (digits[i] == 10) {
                digits[i + 1]++;
                digits[i] = 0;
            }
            if (digits[i] < 5) {
                bills += digits[i];
            } else if (digits[i] == 5) {
                if (digits[i + 1] >= 5) {
                    digits[i + 1]++;
                }
                bills += 5;
            } else {
                digits[i + 1]++;
                bills += 10 - digits[i];
            }
        }
        System.out.println(bills);
    }
}
assistant: stdin = input()
s = stdin
result = "Yes" if "A" in s and "B" in s else "No"
print(result)


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

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

    static class AStationAndBus {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            if (s.contains("A") && s.contains("B")) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }
}
assistant: import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


def main():
    mod = 10 ** 9 + 7
    N, A, B = MI()
    ans = 0
    rep = N // (A + B)
    ans += rep * A
    res = N - rep * (A + B)
    ans += min(res, A)
    print(ans)


main()


user: import java.util.*;

public class atcoder_ABC158_B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long N = scan.nextLong();
        long A = scan.nextLong();
        long B = scan.nextLong();
        long k = 0;
        if (1 <= N
                && N <= Math.pow(10, 18)
                && 0 <= A
                && 0 <= B
                && 0 < A + B
                && A + B <= Math.pow(10, 18)) {
            if (A + B <= N) {
                k = N / (A + B);
                if (N - k * (A + B) > A) {
                    System.out.println(A * k + (N - k * (A + B)) - (N - (k * (A + B) + A)));
                } else {
                    System.out.println(A * k + (N - k * (A + B)));
                }
            } else if (A + B > N && A <= N) {
                System.out.println(A);
            } else {
                System.out.println(N);
            }
        }
    }
}