zccneil/codelingua_dataset huggingface dataset:
assistant: import math
N = int(input())
S = input()


def calculate(n, s):
    arr = list(s)
    rNum = arr.count("R")
    gNum = arr.count("G")
    bNum = arr.count("B")
    sum = 0
    for step in range(1, math.ceil(n / 2) + 1):
        for i in range(n - 2 * step):
            s = "".join([arr[i], arr[i + step], arr[i + step * 2]])
            if s == "RGB" or s == "RBG" or s == "BGR" or s == "BRG" or s == "GBR" or s == "GRB":
                sum = sum + 1
    print(rNum * gNum * bNum - sum)


calculate(N, S)


user: import java.util.*;

public class atcoder_ABC162_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        long rc = 0;
        long gc = 0;
        long bc = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'R') {
                rc++;
            } else if (s.charAt(i) == 'G') {
                gc++;
            } else {
                bc++;
            }
        }
        long result = rc * gc * bc;
        for (int i = 1; i <= n; i++) {
            for (int k = i + 1; k <= n; k++) {
                if ((i + k) % 2 == 0) {
                    char is = s.charAt(i - 1);
                    char ks = s.charAt(k - 1);
                    char js = s.charAt(((i + k) / 2) - 1);
                    if (is != ks && ks != js && js != is) {
                        result--;
                    }
                }
            }
        }
        System.out.println(result);
    }
}
assistant: import sys


def main():
    S, W = map(int, input().split())
    print("unsafe") if (S <= W) else print("safe")


if __name__ == '__main__':
    main()


user: import java.util.*;

public class atcoder_ABC164_A {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        ArrayList<String> scList = new ArrayList<>();
        for (int i = 0; i >= 0; i++) {
            try {
                scList.add(scan.nextLine());
            } catch (Exception e) {
                break;
            }
        }
        String[] numlist = scList.get(0).split(" ");
        int Sheep = Integer.parseInt(numlist[0]);
        int Wolve = Integer.parseInt(numlist[1]);
        if (Wolve >= Sheep) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}
assistant: s, l = (input(), 2019)
m, a, r = ([1] + [0] * l, 0, 0)
for i, e in enumerate(s[:: - 1]):
    a += int(e) * pow(10, i, l)
    r += m[a % l]
    m[a % l] += 1
print(r)


user: import java.util.*;

public class atcoder_ABC164_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        int[] mod_arr = new int[N];
        int[] mod_cnt = new int[2019];
        int radix = 1;
        for (int i = 0; i < N; i++) {
            int tmp = ((int) S.charAt(N - 1 - i) - (int) '0') * radix % 2019;
            if (i != 0) tmp = (tmp + mod_arr[i - 1]) % 2019;
            mod_arr[i] = tmp;
            mod_cnt[tmp]++;
            radix = radix * 10 % 2019;
        }
        long ans = 0L;
        mod_cnt[0]++;
        for (int i = 0; i < 2019; i++) {
            ans += mod_cnt[i] * (mod_cnt[i] - 1) / 2;
        }
        System.out.println(ans);
    }
}
assistant: import sys


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    res = 0

    def rec(A):
        nonlocal res
        if len(A) == N:
            ans = 0
            for i in range(Q):
                if A[b[i] - 1] - A[a[i] - 1] == c[i]:
                    ans += d[i]
            res = max(res, ans)
            return
        last_max = 1 if len(A) == 0 else A[- 1]
        for i in range(last_max, M + 1):
            rec(A + [i])
    rec([])
    print(res)
    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))
    M = int(next(tokens))
    Q = int(next(tokens))
    a = [int()] * (Q)
    b = [int()] * (Q)
    c = [int()] * (Q)
    d = [int()] * (Q)
    for i in range(Q):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)


if __name__ == '__main__':
    main()


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

public class atcoder_ABC165_C {
    static int[] a = null;
    static int[] b = null;
    static int[] c = null;
    static int[] d = null;
    static int n = 0;
    static int m = 0;
    static int q = 0;
    static long ans = -100L;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        q = sc.nextInt();
        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];
        for (int i = 0; i < q; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        dfs(new ArrayList<Integer>());
        System.out.println(ans);
    }

    public static void dfs(ArrayList<Integer> list) {
        if (list.size() == n) {
            long score = 0L;
            for (int i = 0; i < q; ++i) {
                score += (list.get(b[i]) - list.get(a[i]) == c[i]) ? d[i] : 0L;
            }
            ans = Math.max(ans, score);
            return;
        }
        if (!list.isEmpty()) {
            for (int num = list.get(list.size() - 1); num <= m; ++num) {
                list.add(num);
                dfs(list);
                list.remove(list.size() - 1);
            }
        } else {
            for (int num = 1; num <= m; ++num) {
                list.add(num);
                dfs(list);
                list.remove(list.size() - 1);
            }
        }
    }
}
assistant: (n, m) = [int(x) for x in input().split()]
p = [x for x in range(1, n + 1)]
h = [int(x) for x in input().split()]
hp = dict(zip(p, h))
path = {i: [] for i in range(1, n + 1)}
for i in range(m):
    (a, b) = [int(x) for x in input().split()]
    path[a].append(b)
    path[b].append(a)
c = 0
for i, v in path.items():
    f = 0
    for j in v:
        if hp[i] <= hp[j]:
            f = 1
            break
    if f == 0:
        c += 1
print(c)


user: import java.util.*;

public class atcoder_ABC166_C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextLong();
        long[] H = new long[N];
        boolean[] ans = new boolean[N];
        for (int i = 0; i < N; i++) {
            H[i] = sc.nextLong();
            ans[i] = true;
        }
        for (int i = 0; i < M; i++) {
            int temp1 = sc.nextInt();
            int temp2 = sc.nextInt();
            if (H[temp1 - 1] < H[temp2 - 1]) {
                ans[temp1 - 1] = false;
            } else if (H[temp1 - 1] > H[temp2 - 1]) {
                ans[temp2 - 1] = false;
            } else {
                ans[temp1 - 1] = false;
                ans[temp2 - 1] = false;
            }
        }
        int ans2 = 0;
        for (int i = 0; i < N; i++) {
            if (ans[i]) {
                ans2++;
            }
        }
        System.out.println(ans2);
    }
}
assistant: import numpy as np
import itertools
n, m, x = list(map(int, input().split()))
c = np.array([list(map(int, input().split())) for _ in range(n)])
pre = np.arange(n)
l = []
rem = []
ans = 0
for i in pre + 1:
    for j in itertools.combinations(pre, i):
        l.append(list(j))
for i in range(1, m + 1):
    for j, k in enumerate(l):
        ca = 0
        for ii in k:
            ca += c[ii, i]
        if ca < x:
            rem.insert(0, j)
        else:
            pass
    if len(rem) > 0:
        for j in rem:
            l.pop(j)
        rem = []
    if len(l) == 0:
        print(- 1)
        break
else:
    for i in l:
        ca = 0
        for j in i:
            ca += c[j, 0]
        if ans == 0:
            ans = ca
        else:
            ans = min(ans, ca)
    print(ans)


user: import java.util.Scanner;

public class atcoder_ABC167_C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt(), min = Integer.MAX_VALUE;
        int[][] a = new int[n][m + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= m; j++) a[i][j] = sc.nextInt();
        }
        for (int i = 0; i < Math.pow(2, n); i++) {
            int[] status = new int[n];
            for (int j = 0; j < n; j++) {
                if ((1 & i >> j) == 1) {
                    status[j] = 1;
                }
            }
            int[] res = new int[m + 1];
            for (int j = 0; j < n; j++) {
                if (status[j] == 1) {
                    for (int k = 0; k <= m; k++) {
                        res[k] += a[j][k];
                    }
                }
            }
            boolean flag = true;
            for (int j = 1; j <= m; j++) {
                if (res[j] < x) {
                    flag = false;
                    break;
                }
            }
            if (flag) min = Math.min(min, res[0]);
        }
        if (min == Integer.MAX_VALUE) System.out.println(-1);
        else System.out.println(min);
    }
}
assistant: from collections import defaultdict
N, K = map(int, input().split())
L = list(map(int, input().split()))
L.insert(0, - 1)
path = [1]
ind = 0
count = 0
x = 1
t = - 1
flag = False
Hash = defaultdict(lambda: 0)
for i in range(N + 1):
    ne = L[x]
    if Hash[ne]:
        flag = True
        t = Hash[ne]
        break
    path.append(ne)
    ind += 1
    Hash[ne] = ind
    x = ne
if flag == True:
    loop = path[t::]
    if K < (len(path)):
        print(path[K])
    else:
        K = K - len(path)
        K = K % len(loop)
        print(loop[K])
else:
    print(path[K - 1])


user: import java.util.*;

public class atcoder_ABC167_D {
    Scanner sc = new Scanner(System.in);
    final int MOD = 1000000007;
    final int MAX = Integer.MAX_VALUE;
    final long LMAX = Long.MAX_VALUE;
    int len = (int) 1e6 + 1;

    void doIt() {
        int N = sc.nextInt();
        long K = sc.nextLong();
        int A[] = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt() - 1;
        }
        Set<Integer> used = new HashSet<>();
        int idx[] = new int[N];
        int pos[] = new int[N];
        int next = 0, cur = 0;
        while (!used.contains(next)) {
            used.add(next);
            idx[next] = cur;
            pos[cur] = next;
            next = A[next];
            cur++;
        }
        long a = (long) cur - idx[next];
        long b = (long) idx[next];
        int ans = (int) ((10000 * a + K - b) % a + b);
        if (b > K) ans = (int) K;
        System.out.println(pos[ans] + 1);
    }

    public static void main(String[] args) {
        new atcoder_ABC167_D().doIt();
    }
}
assistant: def main():
    K = int(input())
    S = input()
    if len(S) <= K:
        return S
    return S[: K] + '...'


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


user: import java.util.Scanner;

public class atcoder_ABC168_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        String S = in.next();
        if (S.length() <= K) {
            System.out.println(S);
        } else {
            System.out.println(S.substring(0, K) + "...");
        }
    }
}
assistant: import math
a, b, h, m = map(int, input().split())
C = abs(360 / 60 * m - 360 / 12 * h - 360 / 12 / 60 * m)
if C > 180:
    C = 360 - C
cosC = math.cos(math.radians(C))
print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosC))


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

public class atcoder_ABC168_C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();
        BigDecimal AA = new BigDecimal(A);
        BigDecimal BB = new BigDecimal(B);
        BigDecimal HH = new BigDecimal(H);
        BigDecimal MM = new BigDecimal(M);
        BigDecimal ans2;
        BigDecimal kaku;
        BigDecimal mkaku;
        BigDecimal hkaku;
        BigDecimal AA2;
        BigDecimal BB2;
        BigDecimal CC;
        BigDecimal DD;
        double dkaku;
        double dans2;
        mkaku = MM.multiply(BigDecimal.valueOf(6));
        hkaku = HH.multiply(BigDecimal.valueOf(30));
        hkaku = hkaku.add(BigDecimal.valueOf((double) M / 2));
        kaku = mkaku.subtract(hkaku);
        dkaku = Math.abs(Math.toRadians(kaku.doubleValue()));
        AA2 = AA.multiply(AA);
        BB2 = BB.multiply(BB);
        CC = AA2.add(BB2);
        DD = BigDecimal.valueOf(Math.cos(dkaku));
        DD = DD.multiply(BigDecimal.valueOf(2));
        DD = DD.multiply(AA);
        DD = DD.multiply(BB);
        ans2 = CC.subtract(DD);
        dans2 = ans2.doubleValue();
        double ans = Math.sqrt(dans2);
        System.out.println(ans);
    }
}
assistant: def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10 ** 6)
    dbg = (lambda * something: print(* something)
           ) if 'TERM_PROGRAM' in environ else lambda * x: 0

    def input(): return stdin.readline().rstrip()
    def LMIIS(): return list(map(int, input().split()))
    def II(): return int(input())
    P = 10 ** 9 + 7
    INF = 10 ** 9 + 10
    sa, sb = input().split()
    a = int(sa)
    b = int(float(sb) * 100 + 0.1)
    print(a * b // 100)


main()


user: import java.util.Scanner;

public class atcoder_ABC169_C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        String b = sc.next();
        char[] bChar = b.toCharArray();
        int length = bChar.length;
        String bStr = "";
        for (int i = 0; i < length; i++) {
            if (bChar[i] != '.') {
                bStr += bChar[i];
            }
        }
        int bInt = Integer.parseInt(bStr);
        long result = (a * bInt) / 100;
        System.out.println(result);
    }
}
assistant: import math
from functools import reduce
from collections import deque, Counter
import sys
sys.setrecursionlimit(10 ** 7)


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


def get_nums_l():
    return [int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())


def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break


def log(* args):
    print("DEBUG:", * args, file=sys.stderr)


INF = 999999999999999999999999
MOD = 10 ** 9 + 7
n = int(input())
if n == 1:
    print(0)
    exit()


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
    if len(arr) == 0:
        arr.append((n, 1))
    return arr


fac_ = prime_factorize(n)
fac = Counter(fac_)
ans = 0
for p, e in fac.items():
    x = e
    for i in range(1, 99999999):
        if x >= i:
            x -= i
            ans += 1
        else:
            break
print(ans)


user: import java.util.Scanner;

public class atcoder_ABC169_D {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            long n = scanner.nextLong();
            int sqrt = (int) Math.sqrt(n);
            int answer = 0;
            for (int i = 2; i <= sqrt; i++) {
                int count = 0;
                while (0 == (n % i)) {
                    n /= i;
                    count++;
                }
                for (int j = 1; count - j >= 0; j++) {
                    count -= j;
                    answer++;
                }
            }
            if (n > 1) {
                answer++;
            }
            System.out.println(answer);
        }
    }
}
assistant: def resolve():
    n = int(input())
    low = []
    high = []
    for i in range(n):
        a, b = map(int, input().split())
        low.append(a)
        high.append(b)
    low.sort()
    high.sort()
    if n % 2:
        print(high[(n + 1) // 2 - 1] - low[(n + 1) // 2 - 1] + 1)
    else:
        hh = (high[(n) // 2 - 1] + high[(n) // 2]) / 2
        ll = (low[(n) // 2 - 1] + low[(n) // 2]) / 2
        print(int((hh - ll) * 2) + 1)


if __name__ == "__main__":
    resolve()


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

public class atcoder_ABC169_E {
    public static void main(String[] args) throws Exception {
        int num = 998244353;
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(bf.readLine());
        ArrayList<Integer> ai = new ArrayList<Integer>();
        ArrayList<Integer> bi = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            StringTokenizer st = new StringTokenizer(bf.readLine());
            ai.add(Integer.parseInt(st.nextToken()));
            bi.add(Integer.parseInt(st.nextToken()));
        }
        Collections.sort(ai);
        Collections.sort(bi);
        if (n % 2 == 1) {
            out.println(bi.get(bi.size() / 2) - ai.get(ai.size() / 2) + 1);
            out.close();
        } else {
            double b = (ai.get(ai.size() / 2) + ai.get(ai.size() / 2 - 1) + 0.0) / 2;
            double c = (bi.get(bi.size() / 2) + bi.get(bi.size() / 2 - 1) + 0.0) / 2;
            out.println((int) (2 * (c - b) + 1));
            out.close();
        }
    }
}
assistant: a = list(map(int, input().split()))
for e, i in enumerate(a):
    if i == 0:
        print(e + 1)
        break


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

public class atcoder_ABC170_A {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        String[] input_array = br.readLine().split(" ");
        int result = 0;
        for (String str : input_array) {
            result += 1;
            if ("0".equals(str)) break;
        }
        pw.println(result);
        br.close();
        pw.close();
    }
}
assistant: n, k = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[: k]))


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.Arrays;
import java.util.StringTokenizer;

public class atcoder_ABC171_B {
    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.ni(), k = in.ni();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.ni();
            Arrays.parallelSort(a);
            int ans = 0;
            for (int i = 0; i < k; ++i) ans += a[i];
            out.println(ans);
        }
    }

    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 n() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        private int ni() {
            return Integer.parseInt(n());
        }
    }
}
assistant: from functools import *
from operator import *
N = int(input())
a = list(map(int, input().split()))
total = reduce(xor, a, 0)
print(" ".join(list(map(lambda ai: str(ai ^ total), a))))


user: import java.util.Scanner;

public class atcoder_ABC171_E {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int r = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            r ^= a[i];
        }
        for (int i = 0; i < n; i++) {
            if (i != 0) System.out.print(" ");
            System.out.print(r ^ a[i]);
        }
    }
}
assistant: import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]


N = ri()
ans = 0
for i in range(1, N + 1):
    ans += i * (N // i) * (N // i + 1) // 2
print(ans)


user: import java.util.Scanner;

public class atcoder_ABC172_D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 1; i < n + 1; i++) {
            ans += (long) i * ((long) n / (long) i) * (((long) n / (long) i) + 1) / 2;
        }
        System.out.println(ans);
    }
}
assistant: from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
def ii1(): return int(stdin.readline().strip())
def is1(): return stdin.readline().strip()


def iia(): return list(map(int, stdin.readline().strip().split()))
def isa(): return stdin.readline().strip().split()


setrecursionlimit(100000)
mod = 1000000007
k = ii1()
t = 0
for i in range(1, k + 1):
    t = (t % k) * 10 + 7
    if t % k == 0:
        print(i)
        break
else:
    print(- 1)


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

public class atcoder_ABC174_C {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter pw =
            new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    private static StringTokenizer st;

    private static int readInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }

    public static void main(String[] args) throws IOException {
        pw.println(solve());
        pw.close();
    }

    private static int solve() throws IOException {
        int K = readInt();
        if (K % 2 == 0 || K % 5 == 0) return -1;
        if (K % 7 == 0) K /= 7;
        K *= 9;
        int ans = 1;
        int remainder = 10 % K;
        while (remainder != 1) {
            ans++;
            remainder = remainder * 10 % K;
        }
        return ans;
    }
}