TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
import sys
s = list(str(input().rstrip()))
s = list(map(int,s))

change = 0
for i in range(len(s)-1):
  if s[i]!=s[i+1]: change+=1
if change==0:
  print(len(s))
  sys.exit()
elif change ==1:
  ones = s.count(1)
  zeros = s.count(0)
  print(max(ones,zeros))
  sys.exit()
  
0/0

import sys
s = list(str(input().rstrip()))
s = list(map(int,s))

change = 0
for i in range(len(s)-1):
  if s[i]!=s[i+1]: change+=1
if change==0:
  print(len(s))
  sys.exit()
elif change ==1:
  ones = s.count(1)
  zeros = s.count(0)
  print(max(ones,zeros))
  sys.exit()
 

s = input()

cflag=[]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    cflag+=[i+1]
  
ans = len(s)
for flag in cflag:
  ans = min(ans,max(flag,len(s)-flag) )
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
def main():
    s = map(int,input().split())

    ans = len(s)
    for i in range(0,len(s)-1):
        if s[i] != s[i+1]:
            ans = min(ans , max(i+1 , len(s)-i-1))
    print(ans)

if __name__ == '__main__':
    main()

def main():
    s = input()

    ans = len(s)
    for i in range(0,len(s)-1):
        if s[i] != s[i+1]:
            ans = min(ans , max(i+1 , len(s)-i-1))
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
import numpy as np 
fis = s[0]
n = len(s)
k = float('inf')
temp = s[0]
for i in range(n):
    if temp!=s[i]:
        temp = s[i]
        k = np.min((k, np.max( (i, n-i) ) ))
print("{}".format(int(k)))

import numpy as np 
s = input()
fis = s[0]
n = len(s)
k = n
temp = s[0]
for i in range(n):
    if temp!=s[i]:
        temp = s[i]
        k = np.min((k, np.max( (i, n-i) ) ))
print("{}".format(int(k)))

Verdicts: Runtime Error

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
def main():
  S=list(map(int,list(input())))
  N=len(S)
  prev=S[0]
  tmp=1
  count=1
  for i in range(1,N):
    if prev == S[i]:
      tmp+=1
      count=max(count,tmp)
    else:
      tmp=1
      prev=S[i]
  print(count)
main()     

def main():
    import collections
    S = list(map(int, list(input())))
    N = len(S)
    ans = N
    for i in range(N-1):
        if S[i] != S[i+1]:
            ans = min(ans, max(i+1, N-i-1))
    print(ans)


main()


Verdicts: Wrong Answer

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
s = input().strip()
n = len(s)
 
ans = n
for i, c in enumerate(s):
  ld, rd = i, n - i - 1
  if c == '1':
  	ans = min(ans, max(ld, rd))
print(ans)

s = input().strip()
n = len(s)

ans = 0
for i, c in enumerate(s):
  ld, rd = i, n - i - 1
  if c == '1':
  	ans = min(ans, max(lr, rd))
print(ans)

s = input().strip()
n = len(s)

ansone, anszero = n, n
for i, c in enumerate(s):
    ld, rd = i, n - i - 1
    if c == '1':
        ansone = min(ansone, max(ld, rd))
    else:
        anszero = min(anszero, max(ld, rd))
print(max(ansone, anszero))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
S = input()

n = len(S)
ans = n
ans2 = n

for i in range(n):
    if S[i] == "1":
        ans = min(ans, max(n-i-1, i))
    else:
        ans2 = min(ans, max(n-i-1, i))


print(max(ans, ans2))


S = input()

n = len(S)
ans = n

for i in range(n-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(n-i-1, i+1))

S = S[::-1]
for i in range(n-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(n-i-1, i+1))

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times.    * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.

Submission attempts (in order):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
ans = n

for i in range(n-1):
    if s[i] != s[i+1]:
        k = max(n-i+1,i+1)
        ans = min(ans,k)

print(ans)

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
ans = n

for i in range(n-1):
    if s[i] != s[i+1]:
        k = max(n-i-1,i+1)
        ans = min(ans,k)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given a string S consisting of lowercase English letters. Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.

Submission attempts (in order):
from collections import defaultdict

a = list(map(ord, input()))
N = len(a)
La = ord("a")

data = [0]*(N+1)


d = defaultdict(list)
for i , c in enumerate(a):
    d[c-La].append(i)
print(d)
odd = 0
for v in d:
    if len(d[v]) % 2:
        odd += 1
if not odd <= N%2:
    print(-1)
    exit(0)

data = [0]*(N+1)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

M = [None]*N
for v in d:
    v = d[v]
    vl = len(v)
    for i in range(vl):
        if not i <= vl-1-i:
            break
        p = v[i]; q = v[-i-1]
        M[p] = q
        M[q] = p
cnt = 0
B = [0]*N
for i in range(N-1, -1, -1):
    if M[i] <= i:
        B[i] = B[M[i]] = cnt
        cnt += 1

cur = -1
ans = 0
for i in range(N-1, -1, -1):

    if cur < B[i]:
        cur = B[i]
        if M[i] == i:
            ans += N//2 - cur
        else:
            ans += M[i] - get(M[i]+1)
        add(M[i]+1, 1)
print(ans)


from collections import defaultdict

a = list(map(ord, input()))
N = len(a)
La = ord("a")

data = [0]*(N+1)


d = [[] for i in range(26)]
for i , c in enumerate(a):
    d[c-La].append(i)

odd = 0
for v in d:
    if len(v) % 2:
        odd += 1
if not odd <= N%2:
    print(-1)
    exit(0)

data = [0]*(N+1)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

M = [None]*N
for v in d:
    vl = len(v)
    for i in range(vl):
        if not i <= vl-1-i:
            break
        p = v[i]; q = v[-i-1]
        M[p] = q
        M[q] = p
cnt = 0
B = [0]*N
for i in range(N-1, -1, -1):
    if M[i] <= i:
        B[i] = B[M[i]] = cnt
        cnt += 1

cur = -1
ans = 0
for i in range(N-1, -1, -1):

    if cur < B[i]:
        cur = B[i]
        if M[i] == i:
            ans += N//2 - cur
        else:
            ans += M[i] - get(M[i]+1)
        add(M[i]+1, 1)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
N=int(input())
num={}
for a in input().split():
  num[a]+=1
ans=0
for k,v in num:
  if k>v:
    ans+=v
  else:
    ans+=v-k
print(ans)

import collections
N=int(input())
A=[int(a) for a in input().split()]
c=collections.Counter(A)
ans=0
for k,v in c.items():
  if k>v:
    ans+=v
  else:
    ans+=v-k
print(ans)


Verdicts: Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
hm={}
n=int(input())
ans=0
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
# print(hm)
for i in hm:
    if hm[i]==i:
        ans+=i
print(n-ans)

hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
print(hm)
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
N = int(input())
a = list(map(int, input().strip().split()))
a.sort()

i = 0
j = 1
ans = 0

for i in range(N-1):
	if a[i] == a[i+1]:
		j += 1
	else:
		if j >= a[i]:
			ans += j - a[i]
		else:
			ans += j
if a[N-1] != A[N-2]:
	if a[N-1] != 1:
		ans += 1
else:
	if j >= a[i]:
		ans += j - a[i]
	else:
		ans += j


N = int(input())
a = list(map(int, input().strip().split()))
a.sort()
i = 0
j = 1
ans = 0

for i in range(N-1):
	if a[i] == a[i+1]:
		j += 1
	else:
		if j >= a[i]:
			ans += j - a[i]
		else:
			ans += j
		j = 1
if a[N-1] != a[N-2]:
	if a[N-1] != 1:
		ans += 1
else:
	if j >= a[i]:
		ans += j - a[i]
	else:
		ans += j
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
n=int(input())
arr=list(map(int,input().split()))
d=dict()
count=0 
for i in arr:
    d[i]=d.get(i,0)+1 
print(d)
for k,v in d.items():
    if not d[k]==k:
        if d[k]<k:
            count+=d[k]
        else:
            count+=d[k]-k 
print(count)

n=int(input())
arr=list(map(int,input().split()))
d=dict()
count=0 
for i in arr:
    d[i]=d.get(i,0)+1 
for k,v in d.items():
    if not d[k]==k:
        if d[k]<k:
            count+=d[k]
        else:
            count+=d[k]-k 
print(count)

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*1).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*0).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
As = Is()
d = collections.defaultdict(int)
for a in As:
    d[a] += 1 
lis = list(d.items())
ans = 0
for e in lis:
    if e[0] - e[1] > 0:
        ans += e[1]
    else:
        ans += e[1] - e[0]
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):

length = raw_input()
nums = raw_input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in dic:
		dic[num] = 1
	else:
		dic[num]++

ret = 0
for k,v in numdict.iteritems():
	if k > v:
		 += k - v 
	else:
		ret += v - k

print(ret)

length = input()
nums = input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in numdict:
		numdict[str(num)] = 1
	else:
		numdict[str(num)] += 1

ret = 0
for k,v in numdict.items():
	if int(k) > int(v):
		ret += int(v) 
	else:
		ret += int(v) - int(k)

print(ret)

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(num-cnt)
    if num>cnt:
        ans+=cnt
print(ans)


ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(cnt-num)
    if num>cnt:
        ans+=cnt
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a = a.most_common()
ans = 0
for i in range(len(a)):
  if a[i][0] >= a[i][1]:
    ans += a[i][0] - a[i][1]
  else:
    ans += a[i][1]
    
print(ans)

import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a = a.most_common()
ans = 0
for i in range(len(a)):
  if a[i][0] <= a[i][1]:
    ans += a[i][1] - a[i][0]
  else:
    ans += a[i][1]
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)


dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b

YES = "Yes"
NO = "No"


def check(x, nums):
    x = abs(x)
    dp = [False] * (x + 1)
    dp[0] = True
    for y in nums:
        tmp = [False] * (x + 1)
        for i in range(len(dp)):
            if i + y < len(tmp):
                tmp[i + y] |= dp[i]
            if i - y >= 0:
                tmp[i - y] |= dp[i]
        dp = tmp
    return dp[x]


def solve(s, x, y):
    type_num = [(k, len(list(g))) for k, g in groupby(s)]
    if s[0] == "F":
        x -= type_num[0][1]
        type_num.pop(0)

    h, v = [], []
    now = 0
    for t, n in type_num:
        if t == "F":
            if now == 0:
                h.append(n)
            else:
                v.append(n)
        else:
            if n % 2 != 0:
                now = (now + 1) % 2
    return YES if check(x, h) and check(y, v) else NO


def main():
    s = input()
    x, y = map(int, input().split())

    print(solve(s, x, y))

if __name__ == '__main__':
    main()


import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)


dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b


def main():
    N = int(input())
    a = Counter(list(map(int, input().split())))

    ans = 0
    for k, v in a.items():
        if k == v:
            continue
        elif k < v:
            ans += v - k
        else:
            ans += v
    print(ans)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
l.sort()
l.append(0)
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    while l[j] == i and j < N:
        cnt += 1
        j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - 1
    elif cnt < i:
        ans += cnt
print(ans)

N = int(input())
l = list(map(int, input().split()))
N_MAX =  int(1e+9 + 1)
cnt = [0 for _ in range(N_MAX)]
for i in l:
    cnt[i] += 1
ans = 0
for idx, val in enumerate(cnt):
    if val == 0 or val == idx:
        pass
    elif val < idx:
        ans += val
    elif idx < val:
        ans += val - idx
print(ans)

N = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    
    while l[j] == i and j < len(l):
        cnt += 1
        j += 1
    j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - 1
    elif cnt < i:
        ans += cnt
print(ans)

N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Verdicts: Wrong Answer

Time Limit Exceeded

Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
N=int(input())
a=[int(i) for i in input().split()]
data={}
for num in a:
    data[num]+=1
 
ans=0
for key in data.keys():
        if data[key]<key:
                ans+=data[key]
        else:
                ans+=data[key]-key
print(ans)

N=int(input())
a=[int(i) for i in input().split()]
data={}
for num in a:
        if num in data:
                data[num]+=1
        else:
                data[num]=1

ans=0
for key in data.keys():
        if data[key]<key:
                ans+=data[key]
        else:
                ans+=data[key]-key
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**.  Here, an sequence b is a **good sequence** when the following condition holds true:    * For each element x in b, the value x occurs exactly x times in b.  For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Submission attempts (in order):
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import product
def inpl(): return tuple(map(int, input().split()))
   

S = input()
x, y = inpl()
M = []

d = 0
for s in S:
    if s == "F":
        d += 1
    else:
        M.append(d)
        d = 0
M.append(d)

Cx = Counter(M[2::2])
Cy = Counter(M[1::2])

Lx = []
Ly = []

for k, v in Cx.items():
    if k == 0:
        pass
    else:
        Lx.append(list(range(-k*v, k*v+1, 2*k)))
        
for k, v in Cy.items():
    if k == 0:
        pass
    else:
        Ly.append(list(range(-k*v, k*v+1, 2*k)))

def bfss(Ls, t, f):
    N = set([f])
    for L in Ls:
        nN = set(([n+l for n, l in product(N, L)]))
        N = nN
    if t in N:
        return True
    else:
        return False

if bfss(Lx, x, M[0]) and bfss(Ly, y, 0):
    print("Yes")
else:
    print("No")

# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
C = Counter(A)
res = 0

for k, v in C.items():
    if v < k:
        res += v
    elif v > k:
        res += (v - k)
print(res)


Verdicts: Runtime Error

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
s=input()
x,y=map(int, input().split())
px=[(0,1)]
py=[(0,0)]
for k in s:
    npx=set()
    npy=set()
    for i,ho in px:
        if k=='F':
            npx.add((i+ho,ho))
        else:
            npx|={(i,(ho+1)%2),(i,-((ho+1)%2))}
    for j,ho in py:
        if k=='F':
            npy.add((j+ho,ho))
        else:
            npy|={(j,(ho+1)%2),(j,-((ho+1)%2))}
    px=npx
    py=npy
ans='No'
for (i,ho1),(j,ho2) in zip(px,py):
    if i==x and j==y:ans='Yes'
print(ans)

s=input()
x,y=map(int, input().split())
sl=[len(i) for i in s.split('T')]
a,b={0:1},{0:1}
for i in sl[2::2]:
    if i==0:continue
    a2={}
    for j in a.keys():
        a2[j+i]=1
        a2[j-i]=1
    a=a2
for i in sl[1::2]:
    if i==0:continue
    b2={}
    for j in b.keys():
        b2[j+i]=1
        b2[j-i]=1
    b=b2
if x-sl[0] in a and y in b:print('Yes')
else:print('No')

Verdicts: Wrong Answer

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))

dp_x = {m[0]}
for i in m[2::2]:
    new_dp = set()
    for v in dp_x:
        new_dp += {v + i, v - i}
    dp_x = new_dp

dp_y = {0}
for i in m[1::2]:
    new_dp = set()
    for v in dp_y:
        new_dp += {v + i, v - i}
    dp_y = new_dp

print('Yes' if x in dp_x and y in dp_y else 'No')

print(dp_x)
print(dp_y)

s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))

dp_x = {m[0]}
for i in m[2::2]:
    new_dp = set()
    for v in dp_x:
        new_dp |= {v + i, v - i}
    dp_x = new_dp

dp_y = {0}
for i in m[1::2]:
    new_dp = set()
    for v in dp_y:
        new_dp |= {v + i, v - i}
    dp_y = new_dp

print('Yes' if x in dp_x and y in dp_y else 'No')

Verdicts: Runtime Error

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
import sys

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in sy) and (y in st):
	print("Yes")
else:
	print("No")

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

if list_yoko == []:
	list_yoko = [0]

if list_tate == []:
	list_tate = [0]
	
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Verdicts: Runtime Error

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
def f(m, s, g):
    for i in m:
        if s > g:
            s -= i
        else:
            s += i
    return s == g
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
print(m)
if (f(sorted(m[::2][1::])[::-1], m[0], x)
        and f(sorted(m[1::2])[::-1], 0, y)):
    print('Yes')
else:
    print('No')

def f(m, s, g):
    for i in m:
        if s > g:
            s -= i
        else:
            s += i
    return s == g
s = input()
x, y = map(int, input().split())
m = list(map(len, s.split('T')))
if (f(sorted(m[::2][1::])[::-1], m[0], x)
        and f(sorted(m[1::2])[::-1], 0, y)):
    print('Yes')
else:
    print('No')

Verdicts: Wrong Answer

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def dfs(dir, d, i=0, s=0):
        if s == d: return True
        if s > d or i == len(dd[dir]): return False
        if dfs(dir, d, i + 1, s): return True
        if dfs(dir, d, i + 1, s + dd[dir][i]): return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total = [0, 0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                dd[dir].append(cnt)
                total[dir] += cnt
            dir = 1 - dir
            cnt = 0
    dd[dir].append(cnt)
    total[dir] += cnt

    print(xy, dd, total)
    for dir in range(2):
        if not -total[dir] <= xy[dir] <= total[dir]: no()
        d = abs(total[dir] - xy[dir])
        if d % 2: no()
        if not dfs(dir, d // 2): no()
    print("Yes")

main()


import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def no():
    print("No")
    exit()

def main():
    def ok(dir):
        goal = abs(xy[dir])
        over=total[dir]-goal
        if over<0 or over%2:
            return False
        if over==0:
            return True
        over//=2
        dp = [False] * (over + 1)
        dp[0] = True
        for d in dd[dir]:
            for i in range(d, over + 1):
                dp[i] |= dp[i - d]
            if dp[-1]: return True
        return False

    s = input()[:-1]
    xy = list(map(int, input().split()))

    dd = [[], []]
    total=[0,0]
    dir = 0
    cnt = 0
    first = True
    for c in s:
        if c == "F":
            cnt += 1
        if c == "T":
            if first:
                xy[0] -= cnt
                first = False
            else:
                if cnt: dd[dir].append(cnt)
                total[dir]+=cnt
            dir = 1 - dir
            cnt = 0
    if first:
        xy[0] -= cnt
    else:
        if cnt: dd[dir].append(cnt)
        total[dir] += cnt
    #print(xy, dd)

    for dir in range(2):
        if not ok(dir): no()
    print("Yes")

main()


Verdicts: Wrong Answer

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
def inpl(): return [int(i) for i in input().split()]

s = input().split('T')
x, y = inpl()
xi = [len(s[i]) for i in s if i%2 == 0]
yi = [len(s[i]) for i in s if i%2 == 1]

X = (sum(xi)-x)//2
x0 = xi.pop(0) 
Hx = {0: True}
for i in xi:
    for j in Hx.copy().keys():
        Hx[j+i] = True
Y = (sum(yi)-y)//2
Hy = {0: True}
for i in yi:
    for j in Hy.copy().keys():
        Hy[j+i] = True
  
ans = 'Yes'      
if (x0+sum(xi)-x)%2 != 0 or (sum(yi)-y)%2 != 0:
    ans = 'No'
if not Hx.get(X, False) or not Hy.get(Y, False):
    ans = 'No'
print(ans)

s = input() + 'T'
x, y = [int(i) for i in input().split()]

dire = True
xi = []
yi = []
ctr = 0
for i in range(len(s)):
    if s[i] == 'F':
        ctr += 1
        continue
    if dire:
        xi.append(ctr)
    else:
        yi.append(ctr)
    ctr = 0
    dire = not dire
ans = 'Yes'
X = (sum(xi)-x)//2
x0 = xi.pop(0)
Hx = {0: True}
for i in xi:
    for j in Hx.copy().keys():
        Hx[j+i] = True
Y = (sum(yi)-y)//2
Hy = {0: True}
for i in yi:
    for j in Hy.copy().keys():
        Hy[j+i] = True
        
if (x0+sum(xi)-x)%2 != 0 or (sum(yi)-y)%2 != 0:
    ans = 'No'
if not Hx.get(X, False) or not Hy.get(Y, False):
    ans = 'No'
print(ans)

Verdicts: Runtime Error

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 if (g,n,t) in memo:
  return memo[(g,n,t)]
 if tg(g[1:],n+g[0],t)or tg(g[1:],n-g[0],t):
  memo[(g,n,t)]=True
  return True
 else:
  memo[(g,n,t)]=False
  return False

if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")
 

import sys
sys.setrecursionlimit(10000)
inp=list(map(len,input().split("T")))
inx,iny=list(map(int,input().split()))
memo={}
def tg(g,n,t):
 g.sort()
 g.reverse()
 def tn(g,n,t):
  if (tuple(g),n,t) in memo:
   return memo[(tuple(g),n,t)]
  if g==[]:
   if n==t:
    return True
   else:
    return False
  if n<t:
   z=tn(g[1:],n+g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
  else:
   z=tn(g[1:],n-g[0],t)
   memo[(tuple(g),n,t)]=z
   return z
 return tn(g,n,t)
 
if tg(inp[1::2],0,iny)and tg(inp[2::2],inp[0],inx):
 print("Yes")
else:
 print("No")
 

Verdicts: Runtime Error

Accepted
Problem: A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.  This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.    * `F` : Move in the current direction by distance 1.   * `T` : Turn 90 degrees, either clockwise or counterclockwise.  The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable.

Submission attempts (in order):
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque




# inf = float("inf")



def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	ss = input().split('T')
	x, y = map(int, input().split())
	 
	dpx = dict()
	dpy = dict()
	 
	dpx[0+len(ss[0])] = True
	dpy[0] = True
	 
	direct = 1 #0:x, 1:y
	 
	 
	for s in ss[1:]:
		tmp = dict()
		n = len(s)
		if direct%2 == 0: 
			for k, v in dpx.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpx = tmp
		else:
			for k, v in dpy.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpy = tmp

		print(dpx, dpy)
		direct += 1
	 	

	if x in dpx and y in dpy:
	    print('Yes')
	else:
	    print('No')


if __name__ == '__main__':
	main()

import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque




# inf = float("inf")



def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	ss = input().split('T')
	x, y = map(int, input().split())
	 
	dpx = dict()
	dpy = dict()
	 
	dpx[0+len(ss[0])] = True
	dpy[0] = True
	 
	direct = 1 #0:x, 1:y
	 
	 
	for s in ss[1:]:
		tmp = dict()
		n = len(s)
		if direct%2 == 0: 
			for k, v in dpx.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpx = tmp
		else:
			for k, v in dpy.items():
				tmp[k+n] = True
				tmp[k-n] = True
			dpy = tmp

		# print(dpx, dpy)
		direct += 1
	 	

	if x in dpx and y in dpy:
	    print('Yes')
	else:
	    print('No')


if __name__ == '__main__':
	main()

Verdicts: Wrong Answer

Accepted
Problem: For strings s and t, we will say that s and t are _prefix-free_ when neither is a prefix of the other.  Let L be a positive integer. A set of strings S is a _good string set_ when the following conditions hold true:    * Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.   * Any two distinct strings in S are prefix-free.  We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:    * Add a new string to S. After addition, S must still be a good string set.  The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.

Submission attempts (in order):
n, l = map(int, input().split())
ss = [input() for _ in range(n)]
prefix = set()
for s in ss:
	u = ""
	for i in range(len(s)):
		u += s[i]
		prefix.add(u)
grundy = 0
for p in prefix:
	le = len(p)
	if p[le-1] == "0":
		t = p[:le-1] + "1"
	else:
		t = p[:le-1] + "0"
	#if t not in prefix:
		

if grundy == 0:
	print("Bob")
else:
	print("Alice")

import sys
#from collections import defaultdict
sys.setrecursionlimit(10**6)

def input():
	return sys.stdin.readline()[:-1]
n, l = map(int, input().split())
ss = [list(input())[::-1] for _ in range(n)]

def addTree(tree, sentence):
	if not sentence:
		return None   

	if sentence[-1] not in tree:
		tree[sentence[-1]] = {}

	p = sentence.pop()
	tree[p] = addTree(tree[p], sentence)

	return tree

def createTree(sentences):    
	tree = {}
	for sentence in sentences:
		tree = addTree(tree, sentence)

	return tree

tree = createTree(ss)
#print(tree)

grundy = 0
def dfs(cur, level):
	global grundy
	if cur is None:
		return
	elif len(cur) == 1:
		grundy ^= (l-level) & (-l+level)
	for k in cur.keys():
		dfs(cur[k], level+1)
	return
	
dfs(tree, 0)

if grundy == 0:
	print("Bob")
else:
	print("Alice")


Verdicts: Wrong Answer

Accepted
Problem: For strings s and t, we will say that s and t are _prefix-free_ when neither is a prefix of the other.  Let L be a positive integer. A set of strings S is a _good string set_ when the following conditions hold true:    * Each string in S has a length between 1 and L (inclusive) and consists of the characters `0` and `1`.   * Any two distinct strings in S are prefix-free.  We have a good string set S = \\{ s_1, s_2, ..., s_N \\}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:    * Add a new string to S. After addition, S must still be a good string set.  The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.

Submission attempts (in order):
from collections import defaultdict


def solve(l, ss):
    xor = 0
    for d in range(min(ss), l + 1):
        sl = ss[d]
        sl.sort()
        while sl:
            s = sl.pop()
            ps = s[:-1]
            ss[d + 1].append(ps)
            if s[-1] == '1':
                if sl and sl[-1][:-1] == ps:
                    sl.pop()
                else:
                    xor ^= d & -d
        del ss[d]
    return xor


n, l = map(int, input().split())
ss = defaultdict(list)
for s in (input() for _ in range(n)):
    ss[l - len(s) + 1].append(s)

print('Alice' if solve(l, ss) else 'Bob')


from collections import defaultdict


def solve(l, ss):
    xor = 0
    for d in range(min(ss), l + 1):
        sl = ss[d]
        sl.sort()
        while sl:
            s = sl.pop()
            ps = s[:-1]
            ss[d + 1].append(ps)
            if s[-1] == '1' and sl and sl[-1][:-1] == ps:
                sl.pop()
            else:
                xor ^= d & -d
        del ss[d]
    return xor


n, l = map(int, input().split())
ss = defaultdict(list)
for s in (input() for _ in range(n)):
    ss[l - len(s) + 1].append(s)

print('Alice' if solve(l, ss) else 'Bob')


Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Submission attempts (in order):
def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d

n, k = list(map(int, input().rstrip().split()))
print(sum(sorted(mycounter(list(map(int, input().rstrip().split()))).values(), reverse=True)[k:]))


n, k = list(map(int, input().rstrip().split()))
print(sum(sorted(Counter(list(map(int, input().rstrip().split()))).values(), reverse=True)[k:]))

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d


n,k=map(int,input().split())
d=dict()
for i in map(int,input().split()):
    d=mycounter(d,i)
p=0
f=len(d)
#print(f)

for i in sorted(d.values()):
    if f>k:
        p+=i
        f-=1
    else:
        print(p)
        break

Verdicts: Runtime Error

Runtime Error

Accepted