zccneil/codelingua_dataset huggingface dataset:
assistant: N = int(input())
A = list(map(int, input().split()))
mn, mx = N + 1, - 1
for i in range(N):
    if (i + 1 != A[i]):
        mn = min(mn, i)
        mx = max(mx, i)
if (mx == - 1):
    print('0 0')
else:
    A = A[: mn] + A[mn: (mx + 1)][:: - 1] + A[(mx + 1):]
    if (sorted(A) == A):
        print(mn + 1, mx + 1)
    else:
        print('0 0')


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

public class codeforces_56_B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int len = scan.nextInt();
        int a[] = new int[len];
        for (int i = 0; i < len; i++) {
            a[i] = scan.nextInt();
        }
        int l = 0;
        int r = 0;
        boolean flag = false;
        boolean isTrue = false;
        loop:
        for (int i = 0; i < len; i++) {
            if (a[i] != i + 1 && !flag) {
                l = i + 1;
                flag = true;
                continue;
            }
            if (a[i] != i + 1 && flag) {
                r = i + 1;
                if ((a[r - 1] - a[r - 2] > 0)) {
                    isTrue = true;
                    break loop;
                }
            }
        }
        System.out.println((!isTrue) ? l + " " + r : "0" + " " + "0");
    }
}
assistant: import math
n = int(input())
x = 1
while math.log2(n) % 1:
    x += 1
    n -= 2 ** (int(math.log2(n)))
print(x)


user: import java.util.*;

public class codeforces_579_A {
    public static void main(String[] args) {
        Scanner str = new Scanner(System.in);
        int n = str.nextInt();
        String s = "";
        while (n > 0) {
            int x = n % 2;
            n /= 2;
            s += x + "";
        }
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                ans++;
            }
        }
        System.out.println(ans);
    }
}
assistant: a, b = map(int, input().split())
print(min(a, b), (max(a, b) - min(a, b)) // 2)


user: import java.util.*;

public class codeforces_581_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b;
        a = sc.nextInt();
        b = sc.nextInt();
        int count = 0;
        while (true) {
            if (a > 0 && b > 0) {
                count++;
                a--;
                b--;
            } else break;
        }
        int ans = a / 2 + b / 2;
        System.out.println(count + " " + ans);
    }
}
assistant: n = int(input())
arr = list(map(int, input().strip().split()))[: n]
ans = [0] * n
mx = arr[- 1]
for i in range(n - 2, - 1, - 1):
    ans[i] = max(0, mx - arr[i] + 1)
    if arr[i] > mx:
        mx = arr[i]
print(* ans)


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

public class codeforces_581_B {
    static TreeSet<Long> set;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = in.nextLong();
        long[] dp = new long[n + 1];
        Arrays.fill(dp, -1);
        dp[n - 1] = a[n - 1];
        for (int i = n - 1; i >= 0; i--) {
            dp[i] = Math.max(dp[i + 1], a[i]);
        }
        for (int i = 0; i < n; i++) {
            if (a[i] > dp[i + 1]) pw.print(0 + " ");
            else pw.print((dp[i + 1] - a[i] + 1) + " ");
        }
        pw.println();
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}
assistant: def main_function():
    n = int(input())
    a = [int(i) for i in input().split(" ")]
    current_level = 0
    counter = 0
    counter_turns = - 1
    while counter < len(a):
        counter_turns += 1
        for i in range(len(a)):
            if a[i] != - 1 and a[i] <= counter:
                counter += 1
                a[i] = - 1
        a.reverse()
    print(counter_turns)


main_function()


user: import java.util.*;

public class codeforces_583_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            int s = -1;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                b[i] = 0;
            }
            int tem = 1;
            int q = 0;
            while (q != n) {
                s++;
                if (tem == 1) {
                    for (int i = 0; i < n; i++) {
                        if (a[i] <= q && b[i] == 0) {
                            b[i] = 1;
                            q++;
                        }
                    }
                    tem = 0;
                } else {
                    for (int i = n - 1; i >= 0; i--) {
                        if (a[i] <= q && b[i] == 0) {
                            b[i] = 1;
                            q++;
                        }
                    }
                    tem = 1;
                }
            }
            System.out.println(s);
        }
    }
}
assistant: n = int(input())
for i in range(n, 0, - 1):
    if n % i == 0:
        n = i
        print(i, end=' ')


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

public class codeforces_58_B {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(n + " ");
        int m = n;
        for (int i = n - 1; i > 0; i--) {
            if (m % i == 0) {
                System.out.println(i + " ");
                m = i;
            }
        }
    }
}
assistant: n = int(input())
r = [* map(int, input().split())]
ans = abs(r[0])
for i in range(1, n):
    ans += abs(r[i] - r[i - 1])
print(ans)


user: import java.util.*;

public class codeforces_596_B {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        long answer = Math.abs(arr[0]);
        for (int i = 1; i < n; i++) {
            answer += Math.abs(arr[i] - arr[i - 1]);
        }
        System.out.println(answer);
    }
}
assistant: t = int(input())


def solve(n):
    s = (1 + n) * n // 2
    t = 1
    while t <= n:
        s -= 2 * t
        t *= 2
    return s


for _ in range(t):
    n = int(input())
    print(solve(n))


user: import java.util.*;

public class codeforces_598_A {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        while (q-- > 0) {
            int n = sc.nextInt();
            long s = 0;
            int x = (int) (Math.log(n) / Math.log(2));
            x++;
            s =
                    -1 * (long) Math.pow(2, x)
                            + 2
                            + ((long) n * (long) (n + 1)) / 2
                            - (long) Math.pow(2, x);
            System.out.println(s);
        }
    }
}
assistant: txt = input()
cu = 0
cl = 0
for z in txt:
    if z.islower():
        cl = cl + 1
    else:
        cu = cu + 1
if cu > cl:
    out = txt.upper()
else:
    out = txt.lower()
print(out)


user: import java.util.Scanner;

public class codeforces_59_A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String word = in.next();
        int uppercase = 0;
        int lowercase = 0;
        for (int i = 0; i < word.length(); i++) {
            char ch = word.charAt(i);
            if (Character.isUpperCase(ch)) {
                uppercase++;
            } else {
                lowercase++;
            }
        }
        if (uppercase > lowercase) System.out.println(word.toUpperCase());
        else if (lowercase > uppercase) System.out.println(word.toLowerCase());
        else System.out.println(word.toLowerCase());
    }
}
assistant: n = int(input())
l = [0 for _ in range(1000010)]
dp = [0 for _ in range(1000010)]
for i in range(n):
    a, b = map(int, input().split())
    l[a] = b
if l[0] > 0:
    dp[0] = 1
mx = 0
for i in range(1, 1000010):
    if (l[i] == 0):
        dp[i] = dp[i - 1]
    else:
        if (l[i] >= i):
            dp[i] = 1
        else:
            dp[i] = dp[i - l[i] - 1] + 1
    if (dp[i] > mx):
        mx = dp[i]
print(n - mx)


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

public class codeforces_607_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int max = 0;
        int n = sc.nextInt();
        int[] beacon = new int[1000001];
        int[] dp = new int[1000001];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            beacon[a] = sc.nextInt();
        }
        if (beacon[0] != 0) dp[0] = 1;
        for (int i = 1; i < 1000001; i++) {
            if (beacon[i] != 0 && beacon[i] < i) {
                dp[i] = dp[i - beacon[i] - 1] + 1;
            } else if (beacon[i] != 0) {
                dp[i] = 1;
            } else {
                dp[i] = dp[i - 1];
            }
            max = Math.max(max, dp[i]);
        }
        System.out.print(n - max);
    }
}
assistant: import sys
input = sys.stdin.readline
n, s = map(int, input().split())
c = 0
for _ in range(n):
    f, t = map(int, input().split())
    x = t - (s - f)
    if x > c:
        c = x
print(s + c)


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

public class codeforces_608_A {
    public static void main(String[] args) {
        FastScanner in = new FastScanner();
        Scanner sc = new Scanner(System.in);
        PrintWriter o = new PrintWriter(System.out);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int max = 0;
        while (n-- > 0) {
            int f = sc.nextInt();
            int t = sc.nextInt();
            if (max < f + t) {
                max = f + t;
            }
        }
        o.println(Math.max(max, s));
        o.close();
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        public String next() {
            while (!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

        short nextShort() {
            return Short.parseShort(next());
        }

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

        long nextLong() {
            return java.lang.Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
assistant: def _input(): return map(int, input().split())


n, m = _input()
lst = list(_input())
l = {}
for i in range(n):
    if lst[i] not in l:
        l[lst[i]] = 1
    else:
        l[lst[i]] += 1
res = 0
for i in range(n):
    if l[lst[i]] > 1:
        res += n - i - l[lst[i]]
        l[lst[i]] -= 1
    else:
        res += n - i - 1
print(res)


user: import java.util.Scanner;

public class codeforces_609_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int arr[] = new int[n];
        int gen[] = new int[11];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            gen[arr[i]]++;
        }
        long ans = 0;
        for (int i = 1; i <= m; i++) {
            for (int k = 1; k <= m; k++) {
                if (i != k) {
                    ans += (long) gen[i] * gen[k];
                }
            }
        }
        System.out.println(ans / 2);
    }
}
assistant: n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n):
    b[a[i] - 1] = i
res = 0
for i in range(1, n):
    res += abs(b[i] - b[i - 1])
print(res)


user: import java.util.Scanner;

public class codeforces_612_B {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int dp[] = new int[200001];
        for (int i = 0; i < n; i++) {
            dp[s.nextInt()] = i;
        }
        long ans = 0;
        for (int i = 2; i <= n; i++) {
            ans += Math.abs(dp[i] - dp[i - 1]);
        }
        System.out.println(ans);
    }
}
assistant: from math import prod
input()
a = input()
print(0 if a.count("1") == 0 else prod(
    [i.count("0") + 1 for i in a.strip("0 ").split('1')]))


user: import java.util.*;

public class codeforces_617_B {
    static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        int n = input.nextInt();
        List<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) if (input.nextInt() == 1) arr.add(i);
        if (arr.isEmpty()) System.out.println(0);
        else {
            long result = 1;
            for (int i = 1; i < arr.size(); i++) result *= arr.get(i) - arr.get(i - 1);
            System.out.println(result);
        }
    }
}
assistant: import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os


def valid(i, j, n, m):
    if i < n and i >= 0 and j >= 0 and j < m:
        return True
    return False


def sumn(i, n):
    return (n - i) * (i + n) / 2


def sqfun(a, b, c):
    return (- b + math.sqrt(b * b - 4 * a * c)) / 2 * a


def value(): return tuple(map(int, input().split()))
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlst(): return [int(i) for i in input().split()]
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(input())
def inps(): return int(sys.stdin.readline())
def instr(): return input()
def stlst(): return [i for i in input().split()]


def f(s):
    r = ''
    for i in s:
        if i not in ['-', ';', '_']:
            r += i.lower()
    return r


def solve():
    l = []
    for i in range(3):
        l.append(f(input()))
    t = itertools.permutations(l, len(l))
    l = []
    for i in t:
        l.append("".join(i))
    for i in range(inp()):
        if f(instr()) in l:
            print('ACC')
        else:
            print('WA')


if __name__ == "__main__":
    solve()


user: import java.util.*;

public class codeforces_61_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String word1 = in.nextLine().replaceAll("[^a-zA-Z]", "").toLowerCase();
        String word2 = in.nextLine().replaceAll("[^a-zA-Z]", "").toLowerCase();
        String word3 = in.nextLine().replaceAll("[^a-zA-Z]", "").toLowerCase();
        String perm1 = word1 + word2 + word3;
        String perm2 = word1 + word3 + word2;
        String perm3 = word2 + word1 + word3;
        String perm4 = word2 + word3 + word1;
        String perm5 = word3 + word2 + word1;
        String perm6 = word3 + word1 + word2;
        int students = in.nextInt();
        in.nextLine();
        for (int i = 0; i < students; i++) {
            String testCase = in.nextLine().replaceAll("[^a-zA-Z]", "").toLowerCase();
            if (testCase.equals(perm1)
                    || testCase.equals(perm2)
                    || testCase.equals(perm3)
                    || testCase.equals(perm4)
                    || testCase.equals(perm5)
                    || testCase.equals(perm6)) {
                System.out.println("ACC");
            } else {
                System.out.println("WA");
            }
        }
    }
}
assistant: n = int(input())
lst = list(map(int, input().split()))
lst.sort()
lst.reverse()
od = 0
for i in lst:
    if (i & 1):
        od += 1
sum = 0
ok = 0
for i in range(n):
    if (lst[i] % 2 == 0):
        sum += lst[i]
    else:
        if (ok or od > 1):
            sum += lst[i]
            od -= 1
            ok = not ok
print(sum)


user: import java.util.*;

public class codeforces_621_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) list.add(sc.nextLong());
        List<Long> odd = new ArrayList<>();
        long sum = 0;
        for (long i : list) {
            if (i % 2 == 0) sum += i;
            else odd.add(i);
        }
        Collections.sort(odd);
        for (long i : odd) sum += i;
        if (odd.size() % 2 != 0) sum -= odd.get(0);
        System.out.println(sum);
    }
}
assistant: from cmd import IDENTCHARS
n = int(input())
l = 1
r = n
while (l < r):
    mid = l + (r - l) // 2
    idxcnt = mid * (mid + 1) / 2
    if (idxcnt < n):
        l = mid + 1
    else:
        r = mid
l -= 1
idxcnt = l * (l + 1) / 2
print(int(n - idxcnt))


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

public class codeforces_622_A {
    public static final int BUFFERSIZE = 512000;
    private static Scanner sc =
            new Scanner(new BufferedReader(new InputStreamReader(System.in), BUFFERSIZE));
    private static PrintWriter out =
            new PrintWriter(new BufferedOutputStream(System.out, BUFFERSIZE));

    public static void solve() {
        long position = sc.nextLong();
        long nrstSeqStartIndx = 1;
        while (getValueAtIndex(nrstSeqStartIndx * 2) < position) {
            nrstSeqStartIndx *= 2;
        }
        while (getValueAtIndex(nrstSeqStartIndx + 1) <= position) nrstSeqStartIndx++;
        long startIndex = getValueAtIndex(nrstSeqStartIndx);
        out.println((position - startIndex) + 1);
    }

    public static long getValueAtIndex(long index) {
        return 1 + ((index - 1) * index / 2);
    }

    public static void main(String args[]) throws Exception {
        in.init(System.in);
        solve();
        out.close();
    }

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

        static void init(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input), BUFFERSIZE);
            tokenizer = new StringTokenizer("");
        }

        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}
assistant: import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
pre = float('inf')
ans = 0
a.sort(reverse=True)
for j in range(n):
    ans += max(0, min(pre - 1, a[j]))
    pre = max(0, min(pre - 1, a[j]))
print(ans)


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

public class codeforces_624_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Long[] ans = new Long[n];
        for (int i = 0; i < n; i++) {
            ans[i] = in.nextLong();
        }
        Arrays.sort(ans);
        Long count = ans[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            if (ans[i] < ans[i + 1]) {
                count += ans[i];
            } else {
                while (ans[i] >= ans[i + 1]) {
                    ans[i]--;
                }
                if (ans[i] > 0) {
                    count += ans[i];
                }
            }
        }
        System.out.println(count);
    }
}
assistant: n = int(input())
cake = []
happiness = 0
chocCount = 0
nfat = 1
for i in range(n):
    line = str(input())
    cake.append(line)
    for j in line:
        if (j == 'C'):
            chocCount += 1
    if (chocCount > 1):
        for i in range(chocCount, chocCount - 2, - 1):
            nfat *= i
        happiness += nfat / 2
    nfat = 1
    chocCount = 0
posCount = 0
for j in range(n):
    for i in range(n):
        if (cake[i][j] == 'C'):
            chocCount += 1
    if (chocCount > 1):
        for i in range(chocCount, chocCount - 2, - 1):
            nfat *= i
        happiness += nfat / 2
    nfat = 1
    chocCount = 0
print(int(happiness))


user: import java.util.*;

public class codeforces_629_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int counter = 0;
        int fine = 0;
        ArrayList<String> arr = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            String s = sc.next();
            arr.add(s);
        }
        for (int i = 0; i < num; i++) {
            for (int k = 0; k < num; k++) {
                if (arr.get(k).charAt(i) == 'C') {
                    counter++;
                }
            }
            fine += (counter * (counter - 1)) / 2;
            counter = 0;
        }
        for (int i = 0; i < num; i++) {
            for (int k = 0; k < num; k++) {
                if (arr.get(i).charAt(k) == 'C') {
                    counter++;
                }
            }
            fine += (counter * (counter - 1)) / 2;
            counter = 0;
        }
        System.out.println(fine);
    }
}
assistant: import sys
input = sys.stdin.readline
N = 368
m = [0] * N
f = [0] * N
for i in range(int(input())):
    x, a, b = input()[: - 1].split()
    a = int(a)
    b = int(b) + 1
    if x == 'M':
        m[a] += 2
        m[b] -= 2
    else:
        f[a] += 2
        f[b] -= 2
a, b, c = 0, 0, 0
for i in range(N):
    a += m[i]
    b += f[i]
    if min(a, b) > c:
        c = min(a, b)
print(c)


user: import java.util.*;

public class codeforces_629_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] FfriendPerDay = new int[367];
        int[] MfriendPerDay = new int[367];
        int answer = 0;
        for (int i = 0; i < n; i++) {
            char c = sc.next().charAt(0);
            int a = sc.nextInt();
            int b = sc.nextInt();
            for (int j = a; j <= b; j++) {
                if (c == 'M') MfriendPerDay[j]++;
                else FfriendPerDay[j]++;
                if (MfriendPerDay[j] < FfriendPerDay[j]) {
                    if (MfriendPerDay[j] > answer) answer = MfriendPerDay[j];
                } else {
                    if (FfriendPerDay[j] > answer) answer = FfriendPerDay[j];
                }
            }
        }
        System.out.println(answer * 2);
    }
}