zccneil/codelingua_dataset huggingface dataset:
assistant: N = int(input())
V = input().split(" ")
V = [int(i) for i in V]
C = input().split(" ")
C = [int(i) for i in C]
list = [0]
ans = 0
X = 0
Y = 0
for i in range(N):
    if V[i] - C[i] > 0:
        X = V[i]
        Y = C[i]
        list.append(X - Y)
print(sum(list))


user: import java.util.*;

public class atcoder_ABC125_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer n = Integer.valueOf(sc.nextLine());
        String vStr = sc.nextLine();
        Map<Integer, Integer> vList = str2List(vStr);
        String cStr = sc.nextLine();
        Map<Integer, Integer> cList = str2List(cStr);
        Integer max = 0;
        for (Integer i = 0; i < n; i++) {
            Integer profit = vList.get(i) - cList.get(i);
            if (profit > 0) {
                max += profit;
            }
        }
        System.out.println(max);
    }

    static Map<Integer, Integer> str2List(String str) {
        String[] vArrStr = str.split(" ");
        Map<Integer, Integer> ret = new HashMap<>();
        Integer key = 0;
        for (String val : vArrStr) {
            ret.put(key, Integer.valueOf(val));
            key++;
        }
        return ret;
    }
}
assistant: def gcd(a: int, b: int) -> int:
    if b == 0:
        return a
    return gcd(b, a % b)


def ruiseki_lr(array):
    def op(a, b): return gcd(a, b)
    e = 0
    n = len(array)
    left = [e] * (n + 1)
    right = [e] * (n + 1)
    for i in range(n):
        left[i + 1] = op(left[i], array[i])
    for i in reversed(range(n)):
        right[i] = op(right[i + 1], array[i])
    return left, right


n = int(input())
a = list(map(int, input().split()))
left, right = ruiseki_lr(a)
ans = 0
for i in range(n):
    ans = max(gcd(left[i], right[i + 1]), ans)
print(ans)


user: import java.util.Scanner;

public class atcoder_ABC125_C {
    public static int[] A;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        sc.close();
        int[] M = new int[N];
        int[] L = new int[N];
        int[] R = new int[N];
        L[0] = A[0];
        for (int i = 1; i < N; i++) {
            L[i] = gcd(L[i - 1], A[i]);
        }
        R[N - 1] = A[N - 1];
        for (int i = N - 2; i >= 0; i--) {
            R[i] = gcd(R[i + 1], A[i]);
        }
        int answer = Math.max(L[N - 2], R[1]);
        for (int i = 1; i < N - 1; i++) {
            ;
            answer = Math.max(answer, gcd(L[i - 1], R[i + 1]));
        }
        System.out.println(answer);
    }

    public static int gcd(int a, int b) {
        int tmp;
        if (b > a) {
            tmp = a;
            a = b;
            b = tmp;
        }
        if (b == 0) {
            return a;
        }
        int r = -1;
        do {
            r = a % b;
            a = b;
            b = r;
        } while (r != 0);
        return a;
    }
}
assistant: import sys
sys.setrecursionlimit(10 ** 5)


class Node:
    def __init__(self):
        self.val = None
        self.color = None
        self.a = []


n = int(input())
nodes = []
for i in range(n):
    nodes.append(Node())
for i in range(n - 1):
    u, v, w = map(int, input().split())
    node1 = nodes[u - 1]
    node2 = nodes[v - 1]
    node1.val = u
    node2.val = v
    node1.a.append([node2, w])
    node2.a.append([node1, w])
root = nodes[0]
root.color = True
nodeSet = set()


def traverse(node, distance):
    if node in nodeSet:
        return
    else:
        nodeSet.add(node)
    for pair in node.a:
        adjNode = pair[0]
        dis = pair[1]
        if (distance + dis) % 2 == 0:
            adjNode.color = root.color
        else:
            adjNode.color = not root.color
        traverse(adjNode, distance + dis)


traverse(root, 0)
for i in range(n):
    node = nodes[i]
    if node.color:
        print(1)
    else:
        print(0)


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

public class atcoder_ABC126_D {
    private static int[] colors;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n - 1;
        colors = new int[n];
        Arrays.fill(colors, -1);
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(i);
        }
        while (m-- > 0) {
            int me = sc.nextInt() - 1;
            int you = sc.nextInt() - 1;
            int length = sc.nextInt();
            points[me].becomeFriend(points[you], length);
            points[you].becomeFriend(points[me], length);
        }
        dfs(points[0], 0);
        for (int c : colors) {
            System.out.println(c);
        }
    }

    public static void dfs(Point p, int length) {
        boolean alreadyKnown = colors[p.name] != -1;
        if (alreadyKnown) return;
        if (length % 2 == 0) {
            colors[p.name] = 0;
        } else {
            colors[p.name] = 1;
        }
        for (Entry<Point, Integer> entry : p.friends.entrySet()) {
            Point friend = entry.getKey();
            int length2 = entry.getValue();
            dfs(friend, length + length2);
        }
    }

    public static class Point {
        int name;
        Map<Point, Integer> friends;

        Point(int name) {
            this.name = name;
            this.friends = new HashMap<Point, Integer>();
        }

        void becomeFriend(Point p, int length) {
            this.friends.put(p, length);
        }
    }
}
assistant: import sys
from collections import deque
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    edge = [[] for _ in range(N)]
    for i in range(M):
        X, Y, Z = map(lambda x: int(x) - 1, input().split())
        edge[X].append(Y)
        edge[Y].append(X)
    used = [False] * N
    ans = 0
    for i in range(N):
        if not used[i]:
            ans += 1
            queue = deque()
            queue.append(i)
            while queue:
                node = queue.popleft()
                used[node] = True
                for nextnode in edge[node]:
                    if not used[nextnode]:
                        queue.append(nextnode)
    print(ans)


if __name__ == '__main__':
    main()


user: import java.util.*;

public class atcoder_ABC126_E {
    Scanner sc = new Scanner(System.in);
    final int MOD = 1000000007;

    void doIt() {
        int n = sc.nextInt();
        UnionFindTree utf = new UnionFindTree(n);
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            int z = sc.nextInt();
            utf.unite(x, y);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (utf.par[i] == i) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }

    class UnionFindTree {
        int n;
        int[] par;
        int[] rank;

        UnionFindTree(int n) {
            this.n = n;
            par = new int[n];
            rank = new int[n];
            for (int i = 0; i < n; i++) {
                par[i] = i;
                rank[i] = 0;
            }
        }

        int find(int x) {
            if (par[x] == x) {
                return x;
            } else {
                return par[x] = find(par[x]);
            }
        }

        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (rank[x] < rank[y]) par[x] = y;
            else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        boolean same(int x, int y) {
            return find(x) == find(y);
        }
    }

    public static void main(String[] args) {
        new atcoder_ABC126_E().doIt();
    }
}
assistant: r, D, x = map(int, input().split())
for i in range(2, 12):
    print(int((r ** (i - 1)) * (x + D / (1 - r)) - D / (1 - r)))


user: import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class atcoder_ABC127_B {
    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);
        int r = scanner.nextInt();
        int d = scanner.nextInt();
        long x = scanner.nextLong();
        for (int i = 0; i < 10; ++i) {
            x = r * x - d;
            writer.println(x);
        }
        writer.close();
    }

    private static class SimpleScanner {
        private static final int BUFFER_SIZE = 10240;
        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof) throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
assistant: import heapq
q = int(input())
ans = [0, 0]
p1 = []
p2 = []
heapq.heapify(p1)
heapq.heapify(p2)
sum_b = 0
sum_p1 = 0
sum_p2 = 0
for _ in range(q):
    ql = list(map(int, input().split()))
    if ql[0] == 2:
        if len(p1) == len(p2):
            print(- p2[0], sum_p1 - len(p1) * - p2[0] +
                  len(p2) * - p2[0] - sum_p2 + sum_b)
        else:
            print(p1[0], sum_p1 - len(p1) * p1[0] +
                  len(p2) * p1[0] - sum_p2 + sum_b)
    else:
        sum_b += ql[2]
        if len(p1) == 0:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        elif p1[0] <= ql[1]:
            heapq.heappush(p1, ql[1])
            sum_p1 += ql[1]
        else:
            heapq.heappush(p2, - ql[1])
            sum_p2 += ql[1]
        if len(p1) < len(p2):
            k = heapq.heappop(p2)
            heapq.heappush(p1, - k)
            sum_p2 += k
            sum_p1 -= k
        if len(p1) - 1 > len(p2):
            k = heapq.heappop(p1)
            heapq.heappush(p2, - k)
            sum_p1 -= k
            sum_p2 += k


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

public class atcoder_ABC127_F {
    static OutputStream outputStream = System.out;
    static PrintWriter out = new PrintWriter(outputStream);

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        String[] s;
        PriorityQueue<Integer> pqmax = new PriorityQueue<Integer>();
        PriorityQueue<Integer> pqmin =
                new PriorityQueue<Integer>(
                        new Comparator<Integer>() {
                            public int compare(Integer x, Integer y) {
                                return y - x;
                            }
                        });
        long sumMin = 0, sumMax = 0, sumb = 0;
        int min = 0;
        while (t-- > 0) {
            s = br.readLine().split(" ");
            if (s[0].charAt(0) == '2') {
                long ans = min;
                ans *= pqmin.size();
                ans -= sumMin;
                long ans1 = min;
                ans1 *= pqmax.size();
                ans1 = sumMax - ans1;
                out.println(min + " " + (ans + ans1 + sumb));
            } else {
                int in = Integer.parseInt(s[1]);
                sumb += Long.parseLong(s[2]);
                if (in > min) {
                    pqmax.add(in);
                    sumMax += in;
                } else {
                    pqmin.add(in);
                    sumMin += in;
                }
                if (pqmin.size() > pqmax.size()) {
                    sumMax += pqmin.peek();
                    sumMin -= pqmin.peek();
                    pqmax.add(pqmin.poll());
                }
                if (pqmin.size() < pqmax.size()) {
                    sumMax -= pqmax.peek();
                    sumMin += pqmax.peek();
                    pqmin.add(pqmax.poll());
                }
                min = pqmin.peek();
            }
        }
        out.close();
    }
}
assistant: def main():
    import itertools
    n, m = map(int, input().split())
    li = [list(map(int, input().split()))[1:] for _ in range(m)]
    p = tuple(map(int, input().split()))
    q = set(sum(li, []))
    r = set(range(1, n + 1))
    v = r - q
    ans = 0
    for i in range(0, len(q) + 1):
        for s in itertools.combinations(q, i):
            for u, w in zip(li, p):
                s = set(s)
                if len(s & set(u)) % 2 != w:
                    break
            else:
                ans += 2 ** (len(v))
    print(ans)


if __name__ == "__main__":
    main()


user: import java.util.*;

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

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            a.add(0);
        }
        for (int i = 0; i < M; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                int s = sc.nextInt();
                s--;
                a.set(s, a.get(s) | (1 << i));
            }
        }
        int p = 0;
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt();
            p |= (x << i);
        }
        int ans = 0;
        for (int s = 0; s < (1 << N); s++) {
            int t = 0;
            for (int i = 0; i < N; i++) {
                if (((s >> i) & 1) == 1) {
                    t ^= a.get(i);
                }
            }
            if (p == t) {
                ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}
assistant: mod = 10 ** 9 + 7
l = input()
n = len(l)
dp = [[0] * 2 for _ in range(n + 1)]
dp[0][0] = 1
for i, c in enumerate(l):
    if c == '0':
        dp[i + 1][0] += dp[i][0]
        dp[i + 1][1] += dp[i][1] * 3
    else:
        dp[i + 1][0] += dp[i][0] * 2
        dp[i + 1][1] += dp[i][0]
        dp[i + 1][1] += dp[i][1] * 3
    dp[i + 1][0] %= mod
    dp[i + 1][1] %= mod
print((dp[n][0] + dp[n][1]) % mod)


user: import java.util.Scanner;

public class atcoder_ABC129_E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = 1000000007;
        char[] s = sc.nextLine().toCharArray();
        int n = s.length;
        int[][] dp = new int[n + 1][2];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            } else {
                dp[i + 1][1] = (dp[i][0] + dp[i][1]) % M;
            }
            if (s[i] == '0') {
                dp[i + 1][1] += (dp[i][1] * 2) % M;
                dp[i + 1][1] %= M;
            } else {
                dp[i + 1][0] += (dp[i][0] * 2) % M;
                dp[i + 1][1] += (dp[i][1] * 2) % M;
                dp[i + 1][0] %= M;
                dp[i + 1][1] %= M;
            }
        }
        System.out.println((dp[n][0] + dp[n][1]) % M);
    }
}
assistant: from collections import Counter
S = input()
c = Counter(S)
Sa = set(list(S))
if len(Sa) != 2:
    print("No")
    exit()
for i in Sa:
    if c[i] != 2:
        print("No")
        exit()
print("Yes")


user: import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;

public class atcoder_ABC132_A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] targ = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < targ.length; i++) {
            if (!map.containsKey(targ[i])) {
                map.put(targ[i], 1);
            } else {
                map.put(targ[i], map.get(targ[i]) + 1);
            }
        }
        boolean ok = true;
        for (Entry<Character, Integer> c : map.entrySet()) {
            if (c.getValue() != 2) {
                ok = false;
                break;
            }
        }
        if (ok && map.size() == 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        in.close();
    }
}
assistant: mod = 10 ** 9 + 7
n, k = map(int, input().split())
coef = []
for i in range(1, int(n ** 0.5) + 1):
    coef.append((n // i) - (n // (i + 1)))
coef += [1] * (n - sum(coef))
coef = coef[:: - 1]
nn = len(coef)
dp = [[0] * nn for _ in range(k + 1)]
dp[0][0] = 1
for i in range(1, k + 1):
    tmp = 0
    for j in range(nn - 1, - 1, - 1):
        tmp += dp[i - 1][(nn - 1) - j]
        tmp %= mod
        dp[i][j] = coef[j] * tmp
        dp[i][j] %= mod
print(sum(dp[k]) % mod)


user: import java.util.*;

public class atcoder_ABC132_F {
    public static void main(String[] args) {
        long mod = (long) 1e9 + 7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();
        ArrayList<Integer> len = new ArrayList<>();
        int l = 1;
        while (l <= n) {
            int r = n / (n / l);
            len.add(r - l + 1);
            l = r + 1;
        }
        int q = len.size();
        long[] dp = new long[k * (q + 1)];
        for (int j = 1; j <= q; j++) {
            dp[j] = len.get(j - 1) + dp[j - 1];
        }
        for (int i = 1; i < k; i++) {
            for (int j = 1; j <= q; j++) {
                dp[i * (q + 1) + j] =
                        dp[i * (q + 1) + j - 1]
                                + dp[(i - 1) * (q + 1) + q - j + 1] * len.get(j - 1);
                dp[i * (q + 1) + j] %= mod;
            }
        }
        System.out.println(dp[k * (q + 1) - 1]);
    }
}
assistant: import math
n, d = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]


def dist(x, y):
    tmp = 0.0
    for i in range(d):
        tmp += (x[i] - y[i]) ** 2
    return math.sqrt(tmp)


count = 0
for i, elm in enumerate(points):
    for j in range(i + 1, n):
        if dist(elm, points[j]).is_integer():
            count += 1
print(count)


user: import java.util.Scanner;

public class atcoder_ABC133_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] vectors = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                vectors[i][j] = sc.nextInt();
            }
        }
        int answer = 0;
        for (int i = 0; i < N - 1; i++) {
            for (int j = i + 1; j < N; j++) {
                int dist = 0;
                for (int d = 0; d < D; d++) {
                    int x = (vectors[i][d] - vectors[j][d]);
                    dist += (x * x);
                }
                double sq = Math.sqrt(dist);
                answer += (Math.abs(sq - Math.floor(sq)) < 0.001 ? 1 : 0);
            }
        }
        System.out.println(answer);
    }
}
assistant: from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)
graph = defaultdict(list)
N, K = map(int, input().split())
for i in range(N - 1):
    a, b = map(int, input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
mod = 10 ** 9 + 7


def dfs(fro, to, f):
    caseNum = f
    colorNum = K - 1 if f == K else K - 2
    for u in graph[fro]:
        if u == to:
            continue
        pat = dfs(u, fro, colorNum)
        if pat == 0:
            caseNum = 0
            break
        caseNum = caseNum * pat % mod
        colorNum -= 1
    return caseNum


ans = dfs(0, - 1, K)
print(ans)


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

public class atcoder_ABC133_E {
    private class Node {
        public long pattern = 0;
        public int index;
        public LinkedList<Integer> children = new LinkedList<Integer>();
        public int parent = -1;

        public Node(int i) {
            this.index = i;
        }

        public void setParent(int K, int parent, int use, Node[] nodes) {
            this.pattern = K - use;
            this.parent = parent;
            int count = 1;
            if (parent != -1) {
                count++;
            }
            for (int n : children) {
                if (n == this.parent) {
                    continue;
                }
                nodes[n].setParent(K, index, count, nodes);
                count++;
            }
        }
    }

    public void solve() {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int K = in.nextInt();
        Node[] nodes = new Node[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node(i);
        }
        for (int i = 0; i < N - 1; i++) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            nodes[a].children.add(b);
            nodes[b].children.add(a);
        }
        in.close();
        nodes[0].setParent(K, -1, 0, nodes);
        long patterns = 1;
        for (int i = 0; i < N; i++) {
            patterns = (patterns * nodes[i].pattern) % 1_000_000_007;
        }
        System.out.println(patterns);
    }

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