zccneil/codelingua_dataset huggingface dataset:
assistant: def main():
    input()
    pieces = tuple(zip(map(int, input().split()), input()))
    return Bob_sMaxStrength(pieces)


def Bob_sMaxStrength(pieces):
    pScore = sScore = pMaxScore = sMaxScore = sum(
        piece[0] for piece in pieces if piece[1] == 'B')
    for piece in pieces:
        if piece[1] == 'A':
            pScore += piece[0]
            if pScore > pMaxScore:
                pMaxScore = pScore
        else:
            pScore -= piece[0]
    for i in range(len(pieces) - 1, - 1, - 1):
        if pieces[i][1] == 'A':
            sScore += pieces[i][0]
            if sScore > sMaxScore:
                sMaxScore = sScore
        else:
            sScore -= pieces[i][0]
    if pMaxScore > sMaxScore:
        return pMaxScore
    return sMaxScore


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


user: import java.util.*;

public class codeforces_632_B {
    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();
        }
        String s = sc.next();
        long sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == 'B') sum += a[i];
        }
        long ans = sum;
        long sum1 = sum;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A') sum1 += a[i];
            else sum1 -= a[i];
            ans = Math.max(ans, sum1);
        }
        sum1 = sum;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == 'A') sum1 += a[i];
            else sum1 -= a[i];
            ans = Math.max(ans, sum1);
        }
        System.out.println(ans);
    }
}
assistant: from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
s = input()[: - 1].split()
w = Counter(s)
s = s[:: - 1]
c, a = - 1, 0
for i in w:
    if w[i] == max(w.values()):
        if s.index(i) > c:
            a = i
            c = s.index(i)
print(a)


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

public class codeforces_637_A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        int ara[] = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int v = in.nextInt();
            ara[i] = v;
            if (!map.containsKey(v)) {
                map.put(v, 1);
            } else {
                map.put(v, map.get(v) + 1);
            }
        }
        int max = 0;
        for (Integer i : map.values()) {
            max = Math.max(max, i);
        }
        Map<Integer, Integer> mm = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (!mm.containsKey(ara[i])) {
                mm.put(ara[i], 1);
                if (mm.get(ara[i]) == max) {
                    pw.println(ara[i]);
                    break;
                }
            } else {
                mm.put(ara[i], mm.get(ara[i]) + 1);
                if (mm.get(ara[i]) == max) {
                    pw.println(ara[i]);
                    break;
                }
            }
        }
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}
assistant: import queue
n, b = list(map(int, input().split()))


class Task:
    def __init__(self, time: int, duration: int, index: int) -> None:
        super().__init__()
        self.time = time
        self.duration = duration
        self.index = index


remaining = queue.Queue()
running = False
finish_time = 0


def run_task(remaining: queue.Queue, finish_time: int):
    task_to_run = remaining.get()
    finish_time = max(finish_time, task_to_run.time) + task_to_run.duration
    result[task_to_run.index] = finish_time
    return finish_time, result


result = {}
for i in range(n):
    time, duration = list(map(int, input().split()))
    task = Task(time, duration, index=i)
    result.update({i: 0})
    if task.time > finish_time and remaining.empty():
        running = True
        finish_time = task.time + task.duration
        result[i] = finish_time
    else:
        if task.time >= finish_time and not remaining.empty():
            finish_time, result = run_task(
                remaining=remaining, finish_time=finish_time)
        if remaining.qsize() < b:
            remaining.put(task)
        else:
            result[i] = - 1
while not remaining.empty():
    finish_time, result = run_task(
        remaining=remaining, finish_time=finish_time)
for key in result:
    print(result.get(key))


user: import java.util.*;

public class codeforces_644_B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int b = sc.nextInt();
        long[] ans = new long[n];
        LinkedList<Long> q = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            int t = sc.nextInt();
            int d = sc.nextInt();
            while (!q.isEmpty() && q.getFirst() <= t) {
                q.pollFirst();
            }
            if (q.size() <= b) {
                ans[i] = (q.isEmpty() ? t : q.getLast()) + d;
                q.add(ans[i]);
            } else {
                ans[i] = -1;
            }
        }
        for (int i = 0; i < n; ++i) {
            System.out.print(ans[i] + " ");
        }
    }
}
assistant: x, y = map(int, input().split())
print(max(x + y - 3 + ((y - x) % 3 > 0), 0))
def num_inp(): return int(input())


def arr_inp(): return list(map(int, input().split()))
def sp_inp(): return map(int, input().split())
def str_inp(): return input()


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

public class codeforces_651_A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int a = in.nextInt(), b = in.nextInt();
        int c = 0;
        if (a == 1 && b == 1) {
            pw.println(0);
        } else {
            while (a >= 1 || b >= 1) {
                if (a >= b) {
                    b++;
                    a -= 2;
                } else {
                    a++;
                    b -= 2;
                }
                if (a <= 0 || b <= 0) {
                    c++;
                    break;
                }
                c++;
            }
            pw.println(c);
        }
        pw.close();
    }

    static void swap(int a, int b) {
        int t = b;
        b = a;
        a = t;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}
assistant: n = int(input())
l = list(map(int, input().split()))
l.sort()
for i in l:
    if i + 1 in l and i + 2 in l:
        print('YES')
        break
else:
    print('NO')


user: import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;

public class codeforces_653_A {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            int n = in.nextInt();
            List<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int value = in.nextInt();
                a.add(value);
            }
            a = a.stream().distinct().sorted().collect(Collectors.toList());
            boolean found = false;
            for (int i = 0; i < a.size(); i++) {
                if (i + 1 < a.size() && i + 2 < a.size()) {
                    if (a.get(i) + 1 == a.get(i + 1) && a.get(i + 1) + 1 == a.get(i + 2)) {
                        found = true;
                    }
                }
            }
            out.println(found ? "YES" : "NO");
        }
    }
}
assistant: a, at = map(int, input().split())
b, bt = map(int, input().split())
t1, t2 = map(int, input().split(':'))
st = t2 + (t1 - 5) * 60
fin = st + at
now = 0
ans = 0
while now < fin and now < 1140:
    if now + bt > st:
        ans += 1
    now += b
print(ans)


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

public class codeforces_665_A {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int tA = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int b = Integer.parseInt(st.nextToken());
        int tB = Integer.parseInt(st.nextToken());
        String timing = br.readLine();
        int hrs = Integer.parseInt(timing.substring(0, 2));
        int mins = Integer.parseInt(timing.substring(3));
        int simDeparture = hrs * 60 + mins;
        int simArrival = simDeparture + tA;
        int counter = 0;
        for (int i = 300; i < 1440; i += b) {
            int busDeparture = i;
            int busArrival = i + tB;
            if (busDeparture >= simArrival || simDeparture >= busArrival) continue;
            counter++;
        }
        pw.println(counter);
        pw.flush();
        pw.close();
    }
}
assistant: n = int(input())
print((n * 2 + 1) // 3)


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

public class codeforces_669_A {
    public static void main(String[] subhani) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        solve(n);
    }

    public static void solve(int n) {
        System.out.println((n / 3) * 2 + (n % 3 == 0 ? 0 : 1));
    }
}
assistant: li = []
ind = 0
for i in range(1, 371):
    temp = []
    p, q = i, i
    count = 0
    while p != 0:
        p //= 10
        count += 1
    if count == 1:
        li.append(i)
    if count == 2:
        temp = []
        while q != 0:
            x = q % 10
            q //= 10
            temp.append(x)
        li = li + temp[:: - 1]
    if count == 3:
        temp = []
        while q != 0:
            x = q % 10
            q //= 10
            temp.append(x)
        li = li + temp[:: - 1]
li.pop()
li.pop()
n = int(input(''))
print(li[n - 1])


user: import java.util.Scanner;

public class codeforces_672_A {
    static char[] generateString() {
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= 1000; i++) {
            sb.append(i);
        }
        return sb.toString().toCharArray();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(generateString()[n - 1]);
    }
}
assistant: n = int(input())
arr = list(map(int, input().split()))
if arr[0] > 15:
    print(15)
else:
    for i in range(1, len(arr)):
        if arr[i] - arr[i - 1] > 15:
            print(arr[i - 1] + 15)
            break
    else:
        if arr[- 1] == 90 or arr[- 1] + 15 >= 90:
            print(90)
        else:
            print(arr[- 1] + 15)


user: import java.util.*;

public class codeforces_673_A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<Integer>();
        int value;
        for (int i = 0; i < n; i++) {
            value = sc.nextInt();
            a.add(value);
        }
        int result, pos = 0, flag = 0;
        if (a.get(0) > 15) result = 15;
        else {
            for (int i = 1; i < n; i++) {
                if (a.get(i) - a.get(i - 1) > 15) {
                    pos = i - 1;
                    flag = 1;
                    break;
                }
            }
            if (flag == 1) result = a.get(pos) + 15;
            else result = a.get(n - 1) + 15;
        }
        if (result > 90) result = 90;
        System.out.println(result);
    }
}
assistant: vamshi, z = map(int, input().split())
print((vamshi // z + 1) * z)


user: import java.util.Scanner;

public class codeforces_678_A {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        n++;
        int z = 0;
        if (n % k != 0) z = k - n % k;
        System.out.println(n + z);
    }
}
assistant: def leapyear(n):
    if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):
        return "y"
    else:
        return "n"


n = int(input())
d = "f"
if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):
    ans = "ly"
else:
    ans = "nly"
while (True):
    if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)):
        if (d == "m"):
            d = "w"
            n += 1
        elif (d == "t"):
            d = "th"
            n += 1
        elif (d == "w"):
            d = "f"
            n += 1
        elif (d == "th"):
            d = "sa"
            n += 1
        elif (d == "f"):
            d = "s"
            n += 1
        elif (d == "sa"):
            d = "m"
            n += 1
        elif (d == "s"):
            d = "t"
            n += 1
    else:
        if (d == "m"):
            d = "t"
            n += 1
        elif (d == "t"):
            d = "w"
            n += 1
        elif (d == "w"):
            d = "th"
            n += 1
        elif (d == "th"):
            d = "f"
            n += 1
        elif (d == "f"):
            d = "sa"
            n += 1
        elif (d == "sa"):
            d = "s"
            n += 1
        elif (d == "s"):
            d = "m"
            n += 1
    if (d == "f" and ans == "ly" and leapyear(n) == "y"):
        break
    elif (d == "f" and ans == "nly" and leapyear(n) == "n"):
        break
print(n)


user: import java.util.*;

public class codeforces_678_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int y = in.nextInt();
        boolean leap = check_leap(y);
        int sum = 0;
        int mod = 0;
        for (int i = y + 1; ; i++) {
            if (check_leap(i)) {
                sum += 366;
            } else {
                sum += 365;
            }
            if (sum % 7 == 0) {
                if ((check_leap(i) && leap) || (!check_leap(i) && !leap)) {
                    System.out.println(i);
                    return;
                } else {
                    continue;
                }
            }
        }
    }

    static boolean check_leap(int y) {
        return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
    }
}
assistant: u = input
n, k = map(int, u().split())
M = [int(i) for i in u().split()]
m = 0
for j in range(n):
    for p in range(n):
        if (0 == M[p]):
            print(p + 1, end=' ')
            break
    for l in range(p + 1 - k):
        M[l] -= 1
    M[p] -= 1


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

public class codeforces_67_B extends PrintWriter {
    codeforces_67_B() {
        super(System.out, true);
    }

    Scanner sc = new Scanner(System.in);

    public static void main(String[] $) {
        codeforces_67_B o = new codeforces_67_B();
        o.main();
        o.flush();
    }

    void main() {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] bb = new int[n];
        for (int i = 0; i < n; i++) bb[i] = sc.nextInt();
        int[] aa = new int[n];
        int m = 0;
        for (int a = n - 1; a >= 0; a--) {
            int j = 0;
            while (bb[a] > 0) {
                if (aa[j] >= a + k) bb[a]--;
                j++;
            }
            for (int j_ = m++; j_ > j; j_--) aa[j_] = aa[j_ - 1];
            aa[j] = a;
        }
        for (int i = 0; i < n; i++) print(aa[i] + 1 + " ");
        println();
    }
}
assistant: import os
import sys
import io
import math
from array import array
from math import *
def I(): return [* map(int, sys.stdin.readline().split())]
def IS(): return input()


def IN(): return int(input())
def IF(): return float(input())


n = IN()
l = I()
f = 1
l.sort()
c = 0
for i in l:
    if i > c:
        c += 1
print(c + 1)


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

public class codeforces_682_B {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(in.nextInt());
        }
        Collections.sort(list);
        int c = 1;
        for (int i = 0; i < n; i++) {
            if (list.get(i) >= c) {
                c++;
            }
        }
        pw.println(c);
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}
assistant: import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
c = 2
for i in w:
    if i == 1:
        print(c)
    elif i % 2 == 0:
        c = 3 - c
        print(c)
    else:
        print(c)


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

public class codeforces_705_B {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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

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

    static FastReader scan = new FastReader();

    public static void main(String[] args) {
        int t = 1;
        while (t-- > 0) {
            solve();
        }
    }

    public static void solve() {
        int t = scan.nextInt();
        int[] arr = new int[t];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scan.nextInt();
        }
        int prevWinner = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 1) {
                if (prevWinner == 0) {
                    prevWinner = 2;
                }
            }
            if (prevWinner == 2 || prevWinner == 0) {
                if ((arr[i] - 1) % 2 == 0) {
                    System.out.println(2);
                    prevWinner = 2;
                } else {
                    System.out.println(1);
                    prevWinner = 1;
                }
            } else {
                if ((arr[i] - 1) % 2 == 0) {
                    System.out.println(1);
                    prevWinner = 1;
                } else {
                    System.out.println(2);
                    prevWinner = 2;
                }
            }
        }
    }
}
assistant: import re
n = int(input())
ans, sumL = 1, 0
for s in re.split("[.?!]", input()):
    s = s.strip() + '.'
    L = len(s)
    if L > 1:
        if L > n:
            print("Impossible")
            exit()
        if sumL + L + (sumL > 0) > n:
            ans += 1
            sumL = L
        else:
            sumL = sumL + L + (sumL > 0)
print(ans)


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

public class codeforces_70_B {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String input = br.readLine();
        int max = -1;
        int[] msgLength = new int[input.length() / 2];
        int count = 0;
        int idx = 0;
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c == '.' || c == '?' || c == '!') {
                msgLength[idx++] = ++count;
                if (count > max) max = count;
                i++;
                count = 0;
            } else count++;
        }
        if (max > n) System.out.println("Impossible");
        else {
            int ans = 0;
            for (int i = 0; i < idx; i++) {
                int l = msgLength[i];
                while (i < idx - 1 && l + msgLength[i + 1] + 1 <= n) {
                    l += msgLength[i + 1] + 1;
                    i++;
                }
                ans++;
            }
            System.out.println(ans);
        }
    }
}
assistant: x, y = list(map(int, input().split()))
a = 0
while x >= 0 and y >= 22 or x >= 1 and y >= 12 or x >= 2 and y >= 2:
    if a:
        if y >= 22:
            y -= 22
        elif x >= 1 and y >= 12:
            x -= 1
            y -= 12
        else:
            x -= 2
            y -= 2
    else:
        if x >= 2 and y >= 2:
            x -= 2
            y -= 2
        elif x >= 1 and y >= 12:
            x -= 1
            y -= 12
        else:
            y -= 22
    a = 1 - a
print(['Ciel', 'Hanako'][1 - a])


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

public class codeforces_79_A {
    public static boolean canTake(int xNeeded, int xAvailable, int yNeeded, int yAvailable) {
        if (xNeeded > xAvailable) return false;
        if (yNeeded > yAvailable) return false;
        return true;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int x = Integer.parseInt(st.nextToken());
        int y = Integer.parseInt(st.nextToken());
        int turn = 0;
        while (true) {
            if (turn % 2 == 0) {
                if (canTake(2, x, 2, y)) {
                    x -= 2;
                    y -= 2;
                } else if (canTake(1, x, 12, y)) {
                    x -= 1;
                    y -= 12;
                } else if (canTake(0, x, 22, y)) {
                    y -= 22;
                } else {
                    System.out.println("Hanako");
                    return;
                }
            } else {
                if (canTake(0, x, 22, y)) {
                    y -= 22;
                } else if (canTake(1, x, 12, y)) {
                    x -= 1;
                    y -= 12;
                } else if (canTake(2, x, 2, y)) {
                    x -= 2;
                    y -= 2;
                } else {
                    System.out.println("Ciel");
                    return;
                }
            }
            turn++;
        }
    }
}