message
stringlengths
2
67k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
463
109k
cluster
float64
19
19
__index_level_0__
int64
926
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move. Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him. Input The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters. Output If the player who moves first wins, print "First", otherwise print "Second" (without the quotes). Examples Input 2 3 a b Output First Input 3 1 a b c Output First Input 1 2 ab Output Second Submitted Solution: ``` #!/usr/local/bin/python3 # insert string s into a trie def insert_string(trie, s): if s == "": return trie else: head = s[0] tail = s[1:] if head in trie: trie[head] = insert_string(trie[head], tail) else: trie[head] = insert_string({}, tail) return trie from functools import reduce # There are 2 players: true and false # trie is the full prefix tree (constant) # node is the current prefix (given as node in trie) # k the number of game left to play # player is the player about to play # returns winner memo = {} def winner(trie, node, player, k): # if (id(node), player, k) in memo: # return memo[id(node), player, k] if node != {}: # slower, but more fun m = [winner(trie, v, not player, k) for (_, v) in node.items()] res = reduce((lambda x, y: x or y), m) elif k == 1: # finished last game res = not player else: # one game is finished # loser starts the next game res = winner(trie, trie, player, k - 1) memo[id(node), player, k] = res return res n, k = (int(j) for j in input().split()) # compute the trie trie = {} for _ in range(n): trie = insert_string(trie, input()) # print(trie) if winner(trie, trie, True, k): print("First") else: print("Second") ```
instruction
0
12,841
19
25,682
No
output
1
12,841
19
25,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings for two players. Given a group of n non-empty strings. During the game two players build the word together, initially the word is empty. The players move in turns. On his step player must add a single letter in the end of the word, the resulting word must be prefix of at least one string from the group. A player loses if he cannot move. Andrew and Alex decided to play this game k times. The player who is the loser of the i-th game makes the first move in the (i + 1)-th game. Guys decided that the winner of all games is the player who wins the last (k-th) game. Andrew and Alex already started the game. Fedor wants to know who wins the game if both players will play optimally. Help him. Input The first line contains two integers, n and k (1 ≤ n ≤ 105; 1 ≤ k ≤ 109). Each of the next n lines contains a single non-empty string from the given group. The total length of all strings from the group doesn't exceed 105. Each string of the group consists only of lowercase English letters. Output If the player who moves first wins, print "First", otherwise print "Second" (without the quotes). Examples Input 2 3 a b Output First Input 3 1 a b c Output First Input 1 2 ab Output Second Submitted Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 2/11/20 """ import collections import time import os import sys import bisect import heapq from typing import List def make_trie(A): trie = {} for word in A: t = trie for w in word: if w not in t: t[w] = {} t = t[w] # t['#'] = True return trie def game(trie): if not trie: return False return not all([game(t) for k, t in trie.items()]) def can_lose(trie): if not trie: return True return all([game(t) for k, t in trie.items()]) def solve(N, K, A): trie = make_trie(A) win = game(trie) if not win: return False if K == 1: return True if can_lose(trie): return True return K % 2 == 1 N, K = map(int, input().split()) A = [] for i in range(N): s = input() A.append(s) print('First' if solve(N, K, A) else 'Second') ```
instruction
0
12,842
19
25,684
No
output
1
12,842
19
25,685
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,471
19
26,942
Tags: greedy, math, probabilities Correct Solution: ``` def add(a, b): return (a + b) % mod def mult(a, b): tmp = (a % mod) * (b % mod) return tmp % mod n = int(input()) c = [int(i) for i in input().split()] c.sort(reverse = True) pref = [0] * (n + 1) pref[0] = 0 for i in range(1, n + 1): pref[i] = pref[i - 1] + c[i - 1] mod = 998244353 invn = pow(n, mod - 2, mod) for k in range(1, n + 1): ans = 0 j = 0 for i in range(0, n + 1, k): ans = add(ans, mult(j, (add(pref[min(n, i + k)], -pref[i])))) j += 1 ans = mult(ans, invn) print(ans, end = ' ') ```
output
1
13,471
19
26,943
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,472
19
26,944
Tags: greedy, math, probabilities Correct Solution: ``` from sys import stdin input = stdin.buffer.readline def inv(x): return pow(x, mod - 2, mod) mod = 998244353 n = int(input()) a = sorted(map(int, input().split()), reverse=True) p = [0] * (n + 1) p[0] = a[0] for i in range(1, n): p[i] = p[i - 1] + a[i] #print(p) for k in range(1, n + 1): ans = 0 i = 0 while i + k <= n: ans = (ans + (p[i + k - 1] - p[i - 1]) * (i // k)) % mod #print(ans, p[i + k - 1], p[i - 1]) i += k #print(ans) ans = (ans + (p[n - 1] - p[i - 1]) * (i // k)) % mod #print(ans, i) ans = ans * inv(n) print(ans % mod) ```
output
1
13,472
19
26,945
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,473
19
26,946
Tags: greedy, math, probabilities Correct Solution: ``` from sys import stdin def inverse(a,mod): return pow(a,mod-2,mod) n = int(stdin.readline()) c = list(map(int,stdin.readline().split())) mod = 998244353 c.sort() d = [0] for i in range(n): d.append(d[-1] + c[i]) inv = inverse( n , mod ) ans = [] for k in range(1,n+1): now = 0 ni = n-k cnt = 1 while ni > k: now += cnt * (d[ni]-d[ni-k]) cnt += 1 ni -= k now += cnt * d[ni] ans.append(now * inv % mod) print (*ans) ```
output
1
13,473
19
26,947
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,474
19
26,948
Tags: greedy, math, probabilities Correct Solution: ``` n=int(input());c=sorted(list(map(int,input().split())));mod=998244353;inv=pow(n,mod-2,mod);imos=[c[i] for i in range(n)];res=[0]*n for i in range(1,n):imos[i]+=imos[i-1] for i in range(1,n+1): temp=0;L=n-i;R=n-1;count=0 while True: temp+=count*(imos[R]-imos[L-1]*(L>=1));count+=1 if L==0:break else:R-=i;L=max(0,L-i) res[i-1]=(temp*inv)%mod print(*res) ```
output
1
13,474
19
26,949
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,475
19
26,950
Tags: greedy, math, probabilities Correct Solution: ``` from itertools import accumulate def readline(): return map(int, input().split()) MOD = 998244353 def sum_mod(a, b): return (a + b) % MOD def main(): n = int(input()) c = sorted(readline()) assert len(c) == n psums = list(accumulate(c, sum_mod)) psums.insert(0, 0) assert len(psums) == n + 1 inv_n = pow(n, MOD-2, MOD) for k in range(1, n + 1): p = 0 for t in range(n % k, n, k): p = (p + psums[t]) % MOD p *= inv_n print(p % MOD, end=' ') print() if __name__ == '__main__': main() ```
output
1
13,475
19
26,951
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,476
19
26,952
Tags: greedy, math, probabilities Correct Solution: ``` n=int(input()) c=list(map(int,input().split())) mod=998244353 inv=pow(n,mod-2,mod) c.sort() imos=[c[i] for i in range(n)] for i in range(1,n): imos[i]+=imos[i-1] res=[0]*n for i in range(1,n+1): temp=0 L=n-i R=n-1 count=0 while True: temp+=count*(imos[R]-imos[L-1]*(L>=1)) count+=1 if L==0: break else: R-=i L=max(0,L-i) res[i-1]=(temp*inv)%mod print(*res) ```
output
1
13,476
19
26,953
Provide tags and a correct Python 3 solution for this coding contest problem. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8.
instruction
0
13,477
19
26,954
Tags: greedy, math, probabilities Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def solve(): cs = [aa[0]] for a in aa[1:]: cs.append((cs[-1] + a) % md) # print(cs) inv = pow(n, md - 2, md) ans = [] for k in range(1, n): cur = 0 for i in range(1, n): if n - 1 - k * i < 0: break cur = (cur + cs[n - 1 - k * i]) % md cur = cur * inv % md ans.append(cur) ans.append(0) print(*ans) md=998244353 n=II() aa=LI() aa.sort() solve() ```
output
1
13,477
19
26,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8. Submitted Solution: ``` print(0) ```
instruction
0
13,478
19
26,956
No
output
1
13,478
19
26,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description of the multiset of n chests: the i-th chest has treasure value c_i. Each chest can be of one of two types: * regular chest — when a player enters a room with this chest, he grabs the treasure and proceeds to the next room; * mimic chest — when a player enters a room with this chest, the chest eats him alive, and he loses. The player starts in a random room with each room having an equal probability of being chosen. The players earnings is equal to the total value of treasure chests he'd collected before he lost. You are allowed to choose the order the chests go into the rooms. For each k from 1 to n place the chests into the rooms in such a way that: * each room contains exactly one chest; * exactly k chests are mimics; * the expected value of players earnings is minimum possible. Please note that for each k the placement is chosen independently. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Input The first contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of rooms and the number of chests. The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^6) — the treasure values of each chest. Output Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics. It can be shown that it is in the form of P/Q where P and Q are non-negative integers and Q ≠ 0. Report the values of P ⋅ Q^{-1} \pmod {998244353}. Examples Input 2 1 2 Output 499122177 0 Input 8 10 4 3 6 5 10 7 5 Output 499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 Note In the first example the exact values of minimum expected values are: \frac 1 2, \frac 0 2. In the second example the exact values of minimum expected values are: \frac{132} 8, \frac{54} 8, \frac{30} 8, \frac{17} 8, \frac{12} 8, \frac 7 8, \frac 3 8, \frac 0 8. Submitted Solution: ``` for i in range(int(1e5)): print('кф не лагай пж') ```
instruction
0
13,479
19
26,958
No
output
1
13,479
19
26,959
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,671
19
27,342
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = map(int, input().split()) print(k * (6 * n - 1)) for i in range(1, n + 1): x = (i - 1) * 6 + 1 print(k * x, end = ' ') print(k * (x + 1), end = ' ') print(k * (x + 2), end = ' ') print(k * (x + 4)) ```
output
1
13,671
19
27,343
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,672
19
27,344
Tags: constructive algorithms, greedy, math Correct Solution: ``` n,k=map(int,input().split()) print((6*n-1)*k) for i in range(0,6*n,6): print((i+1)*k,(i+2)*k,(i+3)*k,(i+5)*k) ```
output
1
13,672
19
27,345
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,673
19
27,346
Tags: constructive algorithms, greedy, math Correct Solution: ``` n,k=map(int,input().split()) print((6*n-1)*k) maxx=-1 for i in range(0,n): a,b,c,d=k*(6*i+1),k*(6*i+2),k*(6*i+3),k*(6*i+5) print(a,b,c,d) ```
output
1
13,673
19
27,347
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,674
19
27,348
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = map(int, input().split()) l = [1, 2, 3, 5] print((6 * n - 1) * k) for i in range(n): for j in l: print((6 * i + j) * k, end=' ') print() ```
output
1
13,674
19
27,349
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,675
19
27,350
Tags: constructive algorithms, greedy, math Correct Solution: ``` a, b = map(int, input().split(' ')) print((6*a-1)*b) for i in range(a): print((6*i+1)*b, (6*i+2)*b, (6*i+3)*b, (6*i+5)*b) ```
output
1
13,675
19
27,351
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,676
19
27,352
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = map(int, input().split()) print(k*(6*n-1)) for i in range (n): print(k*(6*i+1), k * (6*i+3), k*(6*i+4), k * (6*i+5)) ```
output
1
13,676
19
27,353
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,677
19
27,354
Tags: constructive algorithms, greedy, math Correct Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ALPHA='abcdefghijklmnopqrstuvwxyz/' M=998244353 EPS=1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() n,k=value() ans=[] for i in range(1,2*n*4,6): ans.append(i) ans.append(i+1) ans.append(i+2) ans.append(i+4) print(k*max(ans[:4*n])) for i in range(n): for j in range(4): print(k*ans[4*i+j],end=" ") print() ```
output
1
13,677
19
27,355
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>.
instruction
0
13,678
19
27,356
Tags: constructive algorithms, greedy, math Correct Solution: ``` n, k = list(map(int,input().split())) print((6*n-1)*k) for i in range(0, n): print((6*i+1)*k,(6*i+2)*k,(6*i+3)*k,(6*i+5)*k) ```
output
1
13,678
19
27,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>. Submitted Solution: ``` import sys INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br """ Facts and Data representation Constructive? Top bottom up down """ n, k = I() ans = [[1, 2, 3, 5]] cur = 2 add = 7 for i in range(1, n): ok = [cur, add, add + 2, add + 4] add += 6 cur += 2 ans.append(ok) print((add - 2) * k) for i in ans: print(*[j * k for j in i]) ```
instruction
0
13,683
19
27,366
No
output
1
13,683
19
27,367
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution. Input The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100). Output On the first line print a single integer — the minimal possible m. On each of the next n lines print four space separated integers representing the i-th set. Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them. Examples Input 1 1 Output 5 1 2 3 5 Input 2 2 Output 22 2 4 6 22 14 18 10 16 Note For the first example it's easy to see that set {1, 2, 3, 4} isn't a valid set of rank 1 since <image>. Submitted Solution: ``` n, k = map(int, input().split()) print(2 * (3 * n) - 1) now = 1 for i in range(n): print(k * 2 * (i + 1), end = ' ') for j in range(3): print(k * now, end = ' ') now += 2 print() ```
instruction
0
13,686
19
27,372
No
output
1
13,686
19
27,373
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,836
19
27,672
Tags: greedy, two pointers Correct Solution: ``` n,m,k = map(int,input().split()) x,y = 0,0 a = [] for i in range(n): a.append(list(map(int, input().split()))) for i in zip(*a): u,v = 0,0 for j in range(n-k+1): p,q = sum(i[j:j+k]), sum(i[:j]) if p > u: u = p v = q x += u y += v print(x,y) ```
output
1
13,836
19
27,673
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,837
19
27,674
Tags: greedy, two pointers Correct Solution: ``` n,m, k = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) ans = 0 ans1 = 0 for j in range(m): mv = 0 td = 0 cc = 0 no = 0 for i in range(n): if a[i][j]: v = 0 for z in range(i, min(i+k, n)): v += a[z][j] if v > mv: mv = v td = no no += 1 ans += mv ans1 += td print(ans, ans1) ```
output
1
13,837
19
27,675
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,838
19
27,676
Tags: greedy, two pointers Correct Solution: ``` row,colum,k = map(int, input().split()) colums = [[] for i in range(colum)] for i in range(row): temp = list(map(int, input().split())) for i in range(colum): colums[i].append(temp[i]) c = 0 ans = 0 for i in colums: count = 0 for j in range(row-k+1): count = max(count,i[j:j+k].count(1)) if count==k: break for j in range(row-k+1): if sum(i[j:j+k]) == count: c+=sum(i[:j]) break ans+=count print(ans,c) ```
output
1
13,838
19
27,677
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,839
19
27,678
Tags: greedy, two pointers Correct Solution: ``` def cal(col,index,k): one = 0 for i in range(index,len(col)): if col[i] == 1: for j in range(i,min(len(col),i+k)): if col[j] == 1: one += 1 break return one def solve(col,k): change = 0 score = 0 n = len(col) for i in range(n): if col[i] == 1: one = 0 for j in range(i,min(n,i+k)): if col[j] == 1: one += 1 score = one break remove = 0 for i in range(n): if col[i] == 1: change += 1 one = cal(col,i+1,k) if one > score: remove = change score = one return score,remove def main(): n,m,k = map(int,input().split()) matrix = [] for i in range(n): matrix.append(list(map(int,input().split()))) score = 0 change = 0 for i in range(m): col = [] for j in range(n): col.append(matrix[j][i]) curr_score,curr_rem = solve(col,k) score += curr_score change += curr_rem print(score,change) main() ```
output
1
13,839
19
27,679
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,840
19
27,680
Tags: greedy, two pointers Correct Solution: ``` import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' n,m,k=map(int,input().split()) R=[list(map(int,input().split()))for i in range(n)] s=0 t=0 for i in zip(*R): var=0 tt=0 flag=0 for j in range(n): if i[j]==1: f=1 for r in range(j+1,min(j+k,n)): f+=i[r] if f>var: var=f tt=flag flag+=1 s+=var t+=tt print(s, t) ```
output
1
13,840
19
27,681
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,841
19
27,682
Tags: greedy, two pointers Correct Solution: ``` f = lambda: map(int, input().split()) n, m, k = f() s = d = 0 for t in zip(*[f() for i in range(n)]): p, q = x, y = sum(t[:k]), 0 for j in range(n - k): p += t[j + k] - t[j] q += t[j] if p > x: x, y = p, q s += x d += y print(s, d) ```
output
1
13,841
19
27,683
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,842
19
27,684
Tags: greedy, two pointers Correct Solution: ``` n, m, k = map(int, input().split()); a = []; b = []; score = []; ct = 0 for i in range(n): a.append([int(x) for x in input().split()]) for i in range(m): b.append([]) for i in range(m): for j in range(n): b[i].append(a[j][i]) for i in range(m): maxsums = [] for j in range(n): if b[i][j] == 1: if j + k < n: maxsums.append(sum(b[i][j:j + k])) else: maxsums.append(sum(b[i][j:])) try: score.append(max(maxsums)) ct += maxsums.index(max(maxsums)) except: pass print(sum(score), ct) ```
output
1
13,842
19
27,685
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2.
instruction
0
13,843
19
27,686
Tags: greedy, two pointers Correct Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random """ created by shhuan at 2017/10/12 23:03 """ n, m, k = map(int, input().split()) a = [] for i in range(n): a.append([int(x) for x in input().split()]) removed = 0 score = 0 for c in range(m): count, sr = 0, 0 for r in range(n): tc = sum([a[x][c] for x in range(r, min(r+k, n))]) if tc > count: count = tc sr = r score += count removed += sum([a[r][c] for r in range(sr)]) print(score, removed) ```
output
1
13,843
19
27,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` def main(): n, m, k = [int(x) for x in input().split()] matr = [] for i in range(n): matr.append(input().split()) matr = list(zip(*matr)) score = 0 repl = 0 for i in range(m): window = count1(matr[i][:k]) row_scores = [] for j in range(k, n+k): if matr[i][j-k] == '1': row_scores.append(window) window -= 1 else: row_scores.append(0) if j < n and matr[i][j] == '1': window += 1 row_best = max(row_scores) ind_best = row_scores.index(row_best) repl += count1(matr[i][:ind_best]) score += row_best print(score, repl) def count1(lst): return len(list(filter(lambda x: x == '1', lst))) if __name__ == "__main__": main() ```
instruction
0
13,844
19
27,688
Yes
output
1
13,844
19
27,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` h, w, k = map(int, input().split()) d = [[int(x) for x in input().split()] for _ in range(h)] d = [[x for x in line] for line in zip(*d)] totalScore = 0 totalCost = 0 for line in d: max = 0 cost = 0 cur = 0 curCost = 0 for c1, c2 in zip(line, [0] * k + line): cur += c1 cur -= c2 curCost += c2 if cur > max: cost = curCost max = cur totalScore += max totalCost += cost print(totalScore, totalCost) ```
instruction
0
13,845
19
27,690
Yes
output
1
13,845
19
27,691
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` n, m, k = map(int, input().split()) ar = [] for i in range(n): ar.append(list(map(int, input().split()))) score = 0 min_moves = 0 for j in range(m): cr = [ar[i][j] for i in range(n)] c = 0 maxi = 0 r_s = 0 r_m = 0 for i in range(len(cr)): if cr[i] == 1: maxi = sum(cr[i:i+k]) if maxi > r_s: r_s = maxi r_m = c c += 1 score += r_s min_moves += r_m print(score, min_moves) ```
instruction
0
13,846
19
27,692
Yes
output
1
13,846
19
27,693
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` nmk = list(map(int, input().split())) n = nmk[0] m = nmk[1] k = nmk[2] a = [] for i in range(n): a.append(list(map(int, input().split()))) sum = 0 z = 0 for i in range(m): sums = [a[0][i]] for j in range(1, n): sums.append(sums[-1] + a[j][i]) max_sum = 0 max_ones = 0 cur_ones = 0 for j in range(n): if a[j][i] == 1: cur_ones += 1 if j + k - 1 < n: if j > 0: s = sums[j + k - 1] - sums[j - 1] else: s = sums[j + k - 1] else: if j > 0: s = sums[n - 1] - sums[j - 1] else: s = sums[n - 1] if s > max_sum: max_sum = s max_ones = cur_ones - 1 sum += max_sum z += max_ones print(sum, z) ```
instruction
0
13,847
19
27,694
Yes
output
1
13,847
19
27,695
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` def find(li,k): li=li mm=len(li) x,y,c,an=0,0,0,0 # print(li) while x<mm and y<mm: while y<mm and li[y]-li[x]<k: y+=1 if y-x>an: an=y-x c=x x+=1 # print(an) return [an,c] n,m,k = map(int,input().split()) lis=[] fin=ans=0 for i in range(n): a=list(map(int,input().split())) lis.append(a) for j in range(m): tmp=[] for i in range(n): if lis[i][j]==1: tmp.append(i) a,b=find(tmp,k) ans+=a # print(a,ans,j,end=' ') if b>1: fin+=(b-1) print(ans,fin) ```
instruction
0
13,848
19
27,696
No
output
1
13,848
19
27,697
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` import sys input=sys.stdin.readline n,m,k=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] s=0 cnt=0 for j in range(m): score1=0 for i in range(n): if a[i][j]==1: for ii in range(i,min(n,i+k)): if a[ii][j]==1: score1+=1 a[i][j]=0 break score2=0 for i in range(n): if a[i][j]==1: for ii in range(i,min(n,i+k)): if a[ii][j]==1: score2+=1 break if score2>score1: cnt+=1 s+=score2 else: s+=score1 print(s,cnt) ```
instruction
0
13,849
19
27,698
No
output
1
13,849
19
27,699
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` n,m,k = map(int,input().split()) arr = [] for _ in range(n): arr.append(list(map(int,input().split()))) delete = ans = 0 for i in range(m): mx = 0 ind = -1 j = 0 while j < n: if arr[j][i] == 1: cur = 0 while j < n and arr[j][i] == 1: cur += 1 j += 1 if cur > mx: mx = cur ind = j - cur j += 1 if mx > 1: q = 0 while q < ind: delete += arr[q][i] q += 1 ans += mx print(ans,delete) ```
instruction
0
13,850
19
27,700
No
output
1
13,850
19
27,701
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score is 0; 2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped; 3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score. Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score. Input The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1. Output Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score. Examples Input 4 3 2 0 1 0 1 0 1 0 1 0 1 1 1 Output 4 1 Input 3 2 1 1 0 0 1 0 0 Output 2 0 Note In the first example Ivan will replace the element a1, 2. Submitted Solution: ``` y, x, k = map(int, input().split()) h = [[int(i) for i in input().split()] for j in range(y)] q, w = 0, 0 sh = -1 for i in range(x): a = 0 s = 0 for j in range(y): if h[j][i]: g = sum([h[lp][i] for lp in range(j, min(j + k, y))]) if g > a: if sh == i: s += 1 sh = i a = g q += a w += s print(q, w) ```
instruction
0
13,851
19
27,702
No
output
1
13,851
19
27,703
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of digits in the ticket. The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy. Submitted Solution: ``` import math as ma n = int(input()) s = input() sum_left = 0 sum_right = 0 q_left = 0 q_right = 0 s1 = s[:int(n/2)] s2 = s[int(n/2):] for i in s1: if i=="?": q_left += 1 else: sum_left += int(i) for i in s2: if i=="?": q_right += 1 else: sum_right += int(i) k =q_left - q_right if k>0: if sum_left>sum_right: sum_left += ma.ceil(k/2)*9 else : sum_left += ma.floor(k/2)*9 else : if sum_left>sum_right: sum_left += ma.floor(k/2)*9 else : sum_left += ma.ceil(k/2)*9 if sum_left == sum_right : print("Bicarp") else : print("Monocarp") ```
instruction
0
14,236
19
28,472
Yes
output
1
14,236
19
28,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of digits in the ticket. The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy. Submitted Solution: ``` import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) def lis():return [int(i) for i in input().split()] def value():return int(input()) n=value() a=input().strip('\n') l1,l2=a[:(n//2)].count('?'),a[(n//2):].count('?') s1 = s2 = 0 for i in range(len(a)): if i<n//2: s1+=int(a[i]) if a[i]!='?' else 0 else: s2+=int(a[i]) if a[i]!='?' else 0 no = 1 for i in range(l1): if s1>s2: if no: s1+=9 else:s1+=0 else: if no: s1+=0 else:s1+=9 no = 1 - no for i in range(l2): if s1>s2: if no: s2+=0 else:s2+=9 else: if no: s2+=9 else:s2+=0 no = 1 - no if s1!=s2:print('Monocarp') else:print('Bicarp') ```
instruction
0
14,238
19
28,476
Yes
output
1
14,238
19
28,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of digits in the ticket. The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy. Submitted Solution: ``` """ NTC here """ from sys import stdin, setrecursionlimit setrecursionlimit(10**6) import operator as op from io import BytesIO, IOBase import sys,os # print("Case #{}: {} {}".format(i, n + m, n * m)) import threading threading.stack_size(2 ** 27) def iin(): return int(stdin.readline()) def lin(): return list(map(int, stdin.readline().split())) # range = xrange # input = raw_input import math ceil=math.ceil log=math.log gcd=math.gcd def main(): n=iin() a=list(input()) l=a[:n//2] r=a[n//2:] ch1,ch2=l.count('?'),r.count('?') ch3,ch4=(ch1+1)//2, (ch2+1)//2 cl,cr=0,0 for i in l: if i!='?':cl+=int(i) for i in r: if i!='?':cr+=int(i) #l<r #print(cl,cr,ch1,ch2) if cl+ch3*9!=cr+ch4*9 : print('Monocarp') else: print('Bicarp') #threading.Thread(target=main).start() BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def Print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion main() ```
instruction
0
14,239
19
28,478
Yes
output
1
14,239
19
28,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n/2 digits of this ticket is equal to the sum of the last n/2 digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. Input The first line contains one even integer n (2 ≤ n ≤ 2 ⋅ 10^{5}) — the number of digits in the ticket. The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. Output If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). Examples Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp Note Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy. Submitted Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): n = int(input()) a = list(input()) ls = 0; rs = 0 lq = 0; rq = 0 for i in range(n // 2): if a[i] == '?': lq += 1 else: ls += int(a[i]) for i in range(n // 2 , n): if a[i] == '?': rq += 1 else: rs += int(a[i]) if ls == rs: if lq == rq: print('Bicarp') else: print('Monocarp') elif ls > rs: if lq < rq and (rq - lq) // 2 * 9 >= ls - rs: print('Bicarp') else: print('Monocarp') else: if rq < lq and (lq - rq) // 2 * 9 >= rs - ls: print('Bicarp') else: print('Monocarp') return if __name__ == "__main__": main() ```
instruction
0
14,241
19
28,482
No
output
1
14,241
19
28,483
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. When they are bored, Federico and Giada often play the following card game with a deck containing 6n cards. Each card contains one number between 1 and 6n and each number appears on exactly one card. Initially the deck is sorted, so the first card contains the number 1, the second card contains the number 2, ..., and the last one contains the number 6n. Federico and Giada take turns, alternating; Federico starts. In his turn, the player takes 3 contiguous cards from the deck and puts them in his pocket. The order of the cards remaining in the deck is not changed. They play until the deck is empty (after exactly 2n turns). At the end of the game both Federico and Giada have 3n cards in their pockets. You are given the cards in Federico's pocket at the end of the game. Describe a sequence of moves that produces that set of cards in Federico's pocket. Input The first line of the input contains one integer n (1≤ n ≤ 200). The second line of the input contains 3n numbers x_1, x_2,…, x_{3n} (1 ≤ x_1 < x_2 <… < x_{3n} ≤ 6n) – the cards in Federico's pocket at the end of the game. It is guaranteed that for each test there is at least one sequence of moves that produces such set of cards in Federico's pocket. Output Print 2n lines, each containing 3 integers. The i-th line should contain, in increasing order, the integers a_i<b_i<c_i written on the three cards taken by the player during the i-th turn (so taken by Federico if i is odd and by Giada if i is even). If there is more than one possible sequence of moves, you can print any. Examples Input 2 2 3 4 9 10 11 Output 9 10 11 6 7 8 2 3 4 1 5 12 Input 5 1 2 3 4 5 9 11 12 13 18 19 20 21 22 23 Output 19 20 21 24 25 26 11 12 13 27 28 29 1 2 3 14 15 16 18 22 23 6 7 8 4 5 9 10 17 30 Note Explanation of the first testcase: Initially the deck has 12 = 2⋅ 6 sorted cards, so the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12]. * During turn 1, Federico takes the three cards [9\ 10\ 11]. After his move, the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 12]. * During turn 2, Giada takes the three cards [6\ 7\ 8]. After her move, the deck is [1\ 2\ 3\ 4\ 5\ 12]. * During turn 3, Federico takes the three cards [2\ 3\ 4]. After his move, the deck is [1\ 5\ 12]. * During turn 4, Giada takes the three cards [1\ 5\ 12]. After her move, the deck is empty. At the end of the game, the cards in Federico's pocket are [2\ 3\ 4\ 9\ 10\ 11] and the cards in Giada's pocket are [1\ 5\ 6\ 7\ 8\ 12]. Submitted Solution: ``` n = int(input()) x = list(map(int, input().strip().split())) y = [i for i in range(1, 6*n+1) if i not in x] deck = dict() rdeck = dict() rdeck[1] = 0 for i in range(1, 6*n+1): deck[i] = i+1 rdeck[i+1] = i def dist(a, b): d = 0 c = deck[a] while c != b: d += 1 c = deck[c] return d x_dists = [dist(a, b) for a, b in zip(x, x[1:])] y_dists = [dist(a, b) for a, b in zip(y, y[1:])] def remove(x, x_dists, y, y_dists, moves, i): a, b, c = x[i], x[i+1], x[i+2] moves.append((a, b, c)) xn = x[:i] + x[i+3:] xn_dists = x_dists[:i] + x_dists[i+3:] u = rdeck[a] v = deck[c] rdeck[v] = u deck[u] = v if solve(y, y_dists, xn, xn_dists, moves): return True deck[u] = a rdeck[v] = c return False def solve(x, x_dists, y, y_dists, moves): if len(x) == 0: for (a, b, c) in moves: print(a, b, c) return True scores = dict() for i, d in enumerate(y_dists[:-1]): d2 = y_dists[i+1] if d == 0 and d2 == 0: continue if d % 3 != 0 or d2 % 3 != 0: continue a = y[i] b = y[i+1] u = deck[a] v = deck[b] if d != 0: scores[u] = min(d+d2, scores.get(u, 3*n)) if d2 != 0: scores[v] = min(d+d2, scores.get(v, 3*n)) if len(scores) > 0: su = sorted(scores.keys(), key=scores.get) for min_x in su: for i, u in enumerate(x): if u == min_x: break if i+1 == len(x_dists): continue if x_dists[i] != 0 or x_dists[i+1] != 0: continue U = rdeck[min_x] for j, u in enumerate(y): if u == U: break y_dists[j] -= 3 if remove(x, x_dists, y, y_dists, moves, i): return True y_dists[j] += 3 for i, d in enumerate(x_dists[:-1]): d2 = x_dists[i+1] if d == 0 and d2 == 0: if remove(x, x_dists, y, y_dists, moves, i): return True return False solve(x, x_dists, y, y_dists, []) ```
instruction
0
14,365
19
28,730
No
output
1
14,365
19
28,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. When they are bored, Federico and Giada often play the following card game with a deck containing 6n cards. Each card contains one number between 1 and 6n and each number appears on exactly one card. Initially the deck is sorted, so the first card contains the number 1, the second card contains the number 2, ..., and the last one contains the number 6n. Federico and Giada take turns, alternating; Federico starts. In his turn, the player takes 3 contiguous cards from the deck and puts them in his pocket. The order of the cards remaining in the deck is not changed. They play until the deck is empty (after exactly 2n turns). At the end of the game both Federico and Giada have 3n cards in their pockets. You are given the cards in Federico's pocket at the end of the game. Describe a sequence of moves that produces that set of cards in Federico's pocket. Input The first line of the input contains one integer n (1≤ n ≤ 200). The second line of the input contains 3n numbers x_1, x_2,…, x_{3n} (1 ≤ x_1 < x_2 <… < x_{3n} ≤ 6n) – the cards in Federico's pocket at the end of the game. It is guaranteed that for each test there is at least one sequence of moves that produces such set of cards in Federico's pocket. Output Print 2n lines, each containing 3 integers. The i-th line should contain, in increasing order, the integers a_i<b_i<c_i written on the three cards taken by the player during the i-th turn (so taken by Federico if i is odd and by Giada if i is even). If there is more than one possible sequence of moves, you can print any. Examples Input 2 2 3 4 9 10 11 Output 9 10 11 6 7 8 2 3 4 1 5 12 Input 5 1 2 3 4 5 9 11 12 13 18 19 20 21 22 23 Output 19 20 21 24 25 26 11 12 13 27 28 29 1 2 3 14 15 16 18 22 23 6 7 8 4 5 9 10 17 30 Note Explanation of the first testcase: Initially the deck has 12 = 2⋅ 6 sorted cards, so the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12]. * During turn 1, Federico takes the three cards [9\ 10\ 11]. After his move, the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 12]. * During turn 2, Giada takes the three cards [6\ 7\ 8]. After her move, the deck is [1\ 2\ 3\ 4\ 5\ 12]. * During turn 3, Federico takes the three cards [2\ 3\ 4]. After his move, the deck is [1\ 5\ 12]. * During turn 4, Giada takes the three cards [1\ 5\ 12]. After her move, the deck is empty. At the end of the game, the cards in Federico's pocket are [2\ 3\ 4\ 9\ 10\ 11] and the cards in Giada's pocket are [1\ 5\ 6\ 7\ 8\ 12]. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline from itertools import accumulate, permutations from functools import lru_cache M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] n = val() l = set(li()) turn = 1 currset = list(range(1, 6 * n + 1)) def printit(a, b, c): print(currset[a], currset[b], currset[c]) for _ in range(2 * n): # print(currset) if _ == 2 * n - 1: print(*currset) break if turn: for i in range(2, len(currset)): if currset[i - 2] in l and currset[i - 1] in l and currset[i] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break else: done = 0 for i in range(2, len(currset)): if currset[i - 2] in l or currset[i - 1] in l or currset[i] in l:continue if i > 3 and i < len(currset) - 1 and currset[i - 4] in l and currset[i - 3] in l and currset[i + 1] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] done = 1 break elif i > 2 and i < len(currset) - 2 and currset[i - 3] in l and currset[i + 1] in l and currset[i + 2] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] done = 1 break if not done: for i in range(2, len(currset)): if currset[i - 2] in l or currset[i - 1] in l or currset[i] in l:continue if i > 4 and currset[i - 5] in l and currset[i - 4] in l and currset[i - 3] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break elif i < len(currset) - 3 and currset[i + 1] in l and currset[i + 2] in l and currset[i + 3] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break turn = 1 - turn ```
instruction
0
14,366
19
28,732
No
output
1
14,366
19
28,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. When they are bored, Federico and Giada often play the following card game with a deck containing 6n cards. Each card contains one number between 1 and 6n and each number appears on exactly one card. Initially the deck is sorted, so the first card contains the number 1, the second card contains the number 2, ..., and the last one contains the number 6n. Federico and Giada take turns, alternating; Federico starts. In his turn, the player takes 3 contiguous cards from the deck and puts them in his pocket. The order of the cards remaining in the deck is not changed. They play until the deck is empty (after exactly 2n turns). At the end of the game both Federico and Giada have 3n cards in their pockets. You are given the cards in Federico's pocket at the end of the game. Describe a sequence of moves that produces that set of cards in Federico's pocket. Input The first line of the input contains one integer n (1≤ n ≤ 200). The second line of the input contains 3n numbers x_1, x_2,…, x_{3n} (1 ≤ x_1 < x_2 <… < x_{3n} ≤ 6n) – the cards in Federico's pocket at the end of the game. It is guaranteed that for each test there is at least one sequence of moves that produces such set of cards in Federico's pocket. Output Print 2n lines, each containing 3 integers. The i-th line should contain, in increasing order, the integers a_i<b_i<c_i written on the three cards taken by the player during the i-th turn (so taken by Federico if i is odd and by Giada if i is even). If there is more than one possible sequence of moves, you can print any. Examples Input 2 2 3 4 9 10 11 Output 9 10 11 6 7 8 2 3 4 1 5 12 Input 5 1 2 3 4 5 9 11 12 13 18 19 20 21 22 23 Output 19 20 21 24 25 26 11 12 13 27 28 29 1 2 3 14 15 16 18 22 23 6 7 8 4 5 9 10 17 30 Note Explanation of the first testcase: Initially the deck has 12 = 2⋅ 6 sorted cards, so the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12]. * During turn 1, Federico takes the three cards [9\ 10\ 11]. After his move, the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 12]. * During turn 2, Giada takes the three cards [6\ 7\ 8]. After her move, the deck is [1\ 2\ 3\ 4\ 5\ 12]. * During turn 3, Federico takes the three cards [2\ 3\ 4]. After his move, the deck is [1\ 5\ 12]. * During turn 4, Giada takes the three cards [1\ 5\ 12]. After her move, the deck is empty. At the end of the game, the cards in Federico's pocket are [2\ 3\ 4\ 9\ 10\ 11] and the cards in Giada's pocket are [1\ 5\ 6\ 7\ 8\ 12]. Submitted Solution: ``` n = int(input()) x = list(map(int, input().strip().split())) y = [i for i in range(1, 6*n+1) if i not in x] deck = dict() rdeck = dict() rdeck[1] = 0 for i in range(1, 6*n+1): deck[i] = i+1 rdeck[i+1] = i def dist(a, b): d = 0 c = deck[a] while c != b: d += 1 c = deck[c] return d x_dists = [dist(a, b) for a, b in zip(x, x[1:])] y_dists = [dist(a, b) for a, b in zip(y, y[1:])] def remove(x, x_dists, y, y_dists, moves, i): a, b, c = x[i], x[i+1], x[i+2] moves.append((a, b, c)) x = x[:i] + x[i+3:] x_dists = x_dists[:i] + x_dists[i+3:] u = rdeck[a] v = deck[c] rdeck[v] = u deck[u] = v solve(y, y_dists, x, x_dists, moves) def solve(x, x_dists, y, y_dists, moves): if len(x) == 0: for (a, b, c) in moves: print(a, b, c) return scores = dict() for i, d in enumerate(y_dists[:-2]): d2 = y_dists[i+1] if d == 0 and d2 == 0: continue a = y[i] b = y[i+1] u = deck[a] v = deck[b] if d != 0: scores[u] = min(d+d2, scores.get(u, 3*n)) if d2 != 0: scores[v] = min(d+d2, scores.get(v, 3*n)) if len(scores) > 0: su = sorted(scores.keys(), key=scores.get) for min_x in su: for i, u in enumerate(x): if u == min_x: break if i+1 == len(x_dists): continue if x_dists[i] != 0 or x_dists[i+1] != 0: continue U = rdeck[min_x] for j, u in enumerate(y): if u == U: break y_dists[j] -= 3 remove(x, x_dists, y, y_dists, moves, i) return for i, d in enumerate(x_dists[:-1]): d2 = x_dists[i+1] if d == 0 and d2 == 0: remove(x, x_dists, y, y_dists, moves, i) return solve(x, x_dists, y, y_dists, []) ```
instruction
0
14,367
19
28,734
No
output
1
14,367
19
28,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. When they are bored, Federico and Giada often play the following card game with a deck containing 6n cards. Each card contains one number between 1 and 6n and each number appears on exactly one card. Initially the deck is sorted, so the first card contains the number 1, the second card contains the number 2, ..., and the last one contains the number 6n. Federico and Giada take turns, alternating; Federico starts. In his turn, the player takes 3 contiguous cards from the deck and puts them in his pocket. The order of the cards remaining in the deck is not changed. They play until the deck is empty (after exactly 2n turns). At the end of the game both Federico and Giada have 3n cards in their pockets. You are given the cards in Federico's pocket at the end of the game. Describe a sequence of moves that produces that set of cards in Federico's pocket. Input The first line of the input contains one integer n (1≤ n ≤ 200). The second line of the input contains 3n numbers x_1, x_2,…, x_{3n} (1 ≤ x_1 < x_2 <… < x_{3n} ≤ 6n) – the cards in Federico's pocket at the end of the game. It is guaranteed that for each test there is at least one sequence of moves that produces such set of cards in Federico's pocket. Output Print 2n lines, each containing 3 integers. The i-th line should contain, in increasing order, the integers a_i<b_i<c_i written on the three cards taken by the player during the i-th turn (so taken by Federico if i is odd and by Giada if i is even). If there is more than one possible sequence of moves, you can print any. Examples Input 2 2 3 4 9 10 11 Output 9 10 11 6 7 8 2 3 4 1 5 12 Input 5 1 2 3 4 5 9 11 12 13 18 19 20 21 22 23 Output 19 20 21 24 25 26 11 12 13 27 28 29 1 2 3 14 15 16 18 22 23 6 7 8 4 5 9 10 17 30 Note Explanation of the first testcase: Initially the deck has 12 = 2⋅ 6 sorted cards, so the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12]. * During turn 1, Federico takes the three cards [9\ 10\ 11]. After his move, the deck is [1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 12]. * During turn 2, Giada takes the three cards [6\ 7\ 8]. After her move, the deck is [1\ 2\ 3\ 4\ 5\ 12]. * During turn 3, Federico takes the three cards [2\ 3\ 4]. After his move, the deck is [1\ 5\ 12]. * During turn 4, Giada takes the three cards [1\ 5\ 12]. After her move, the deck is empty. At the end of the game, the cards in Federico's pocket are [2\ 3\ 4\ 9\ 10\ 11] and the cards in Giada's pocket are [1\ 5\ 6\ 7\ 8\ 12]. Submitted Solution: ``` from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline from itertools import accumulate, permutations from functools import lru_cache M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n')] def li3():return [int(i) for i in input().rstrip('\n')] n = val() l = set(li()) turn = 1 currset = list(range(1, 6 * n + 1)) def printit(a, b, c): print(currset[a], currset[b], currset[c]) for _ in range(2 * n): # print(currset) if _ == 2 * n - 1: print(*currset) break if turn: for i in range(2, len(currset)): if currset[i - 2] in l and currset[i - 1] in l and currset[i] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break else: for i in range(2, len(currset)): if currset[i - 2] in l or currset[i - 1] in l or currset[i] in l:continue if i > 4 and currset[i - 5] in l and currset[i - 4] in l and currset[i - 3] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break elif i > 3 and i < len(currset) - 1 and currset[i - 4] in l and currset[i - 3] in l and currset[i + 1] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break elif i > 2 and i < len(currset) - 2 and currset[i - 3] in l and currset[i + 1] in l and currset[i + 2] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break elif i < len(currset) - 3 and currset[i + 1] in l and currset[i + 2] in l and currset[i + 3] in l: printit(i - 2, i - 1, i) currset = currset[:i - 2] + currset[i + 1:] break turn = 1 - turn ```
instruction
0
14,368
19
28,736
No
output
1
14,368
19
28,737
Provide a correct Python 3 solution for this coding contest problem. You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? Note: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints * 2 \le N \le 200,000 * 0 \le A_p \le 10^{12} for any p = 1,\ldots, N * 0 \le B_p \le 100 for any p = 1, \ldots, N * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. Examples Input 5 4 2 6 3 5 1 1 1 1 1 Output 4.700000000000 Input 4 100 0 100 0 0 100 0 100 Output 50.000000000000 Input 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Output 7047.142857142857 Input 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Output 815899161079.400024414062
instruction
0
14,774
19
29,548
"Correct Solution: ``` from math import gcd n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) class Seg_min(): def __init__(self,x): #####単位元###### self.ide_ele_min = 10**10 self.func = min self.n = len(x) #num_max:n以上の最小の2のべき乗 self.num_max =2**(self.n-1).bit_length() self.x = [self.ide_ele_min]*2*self.num_max for i,num in enumerate(x, self.num_max): self.x[i] = num for i in range(self.num_max-1,0,-1): self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1]) def update(self,i,x): i += self.num_max self.x[i] = x while(i>0): i = i//2 self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1]) def query(self,i,j): res = self.ide_ele_min if i>=j: return res i += self.num_max j += self.num_max -1 while(i<=j): if(i==j): res = self.func(res,self.x[i]) break if(i&1): res = self.func(res,self.x[i]) i += 1 if(not j&1): res = self.func(res,self.x[j]) j -= 1 i = i>>1 j = j>>1 return res class Seg_max(): def __init__(self,x): #####単位元###### self.ide_ele_min = 10**10 * -1 self.func = max self.n = len(x) #num_max:n以上の最小の2のべき乗 self.num_max =2**(self.n-1).bit_length() self.x = [self.ide_ele_min]*2*self.num_max for i,num in enumerate(x, self.num_max): self.x[i] = num for i in range(self.num_max-1,0,-1): self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1]) def update(self,i,x): i += self.num_max self.x[i] = x while(i>0): i = i//2 self.x[i] = self.func(self.x[i<<1],self.x[(i<<1) + 1]) def query(self,i,j): res = self.ide_ele_min if i>=j: return res i += self.num_max j += self.num_max -1 while(i<=j): if(i==j): res = self.func(res,self.x[i]) break if(i&1): res = self.func(res,self.x[i]) i += 1 if(not j&1): res = self.func(res,self.x[j]) j -= 1 i = i>>1 j = j>>1 return res # aの最大値のindexを取得 max_ind = 0 max_num = -1 for ind,i in enumerate(a): if(i > max_num): max_ind = ind max_num = i # max_ind が先頭になるように順番を変更 a = a[max_ind:] + a[:max_ind] b = b[max_ind:] + b[:max_ind] # Aiが小さい順に探索する。その順番を取得しておく。 order = [(i,ind) for ind,i in enumerate(a)] order.sort() # 累積和を作る。 # cs1は普通のBiの累積和 # cs2はi*Biの累積和 cs1_l = [0] * (n) cs2_l = [0] * (n) cs1_r = [0] * (n+1) cs2_r = [0] * (n+1) for i in range(1,n): cs1_l[i] = cs1_l[i-1] + b[i] cs2_l[i] = cs2_l[i-1] + b[i]*i for i in range(1,n): cs1_r[-(i+1)] = cs1_r[-i] + b[-i] cs2_r[-(i+1)] = cs2_r[-i] + b[-i]*i # 1週して戻ってくる点を追加しておく a.append(a[0]) b.append(b[0]) # ゲームを終了する位置を記録・取得するためにセグ木を使う seg_left = Seg_max( list(range(n+1)) ) seg_right = Seg_min( list(range(n+1)) ) # すべての点について、終了するかしないかを記録しておく。 end = [1] * (n+1) # end[0] = 1 # end[-1] = 1 # 終了しない場合の期待値計算の関数 def calc_ex(ind): left = seg_left.query(0,ind) right = seg_right.query(ind+1,n+1) div = right - left wid_l = ind-left wid_r = right-ind # left-ind base = cs2_l[ind] - cs2_l[left] - (cs1_l[ind] - cs1_l[left])*left ex_l = base*2 * wid_r # ind-right base = cs2_r[ind] - cs2_r[right] - (cs1_r[ind] - cs1_r[right])*(n-right) ex_r = base*2 * wid_l ex = -ex_l - ex_r + b[ind]*wid_l*wid_r*2 + a[left]*wid_r + a[right]*wid_l return ex,div # Aiが小さい順に期待値計算をして、終了するかどうか判断。 # A0は絶対に終了すべきなのでskip order = [j for i,j in order][::-1] flag = True while(flag): flag = False while(order): ind = order.pop() if(ind==0): continue if(end[ind]==0): continue ex,div = calc_ex(ind) if(a[ind]*div < ex): end[ind] = 0 seg_left.update(ind,0) seg_right.update(ind,n) left = seg_left.query(0,ind) right = seg_right.query(ind+1,n+1) if(left!=0): order.append(left) if(right!=n): order.append(right) flag = True if(flag): for i,val in enumerate(end[:-1]): if(val==1): order.append(i) # 終了すべきポイントがわかったので期待値合計を計算 ans = [0] * (n) for ind,flag in enumerate(end[:-1]): if(flag==1): ans[ind] = (a[ind],1) else: ex,div = calc_ex(ind) ans[ind] = (ex,div) lcm = 1 for ex,div in ans: lcm = (lcm*div)//gcd(lcm,div) ans_num = 0 for ex,div in ans: ans_num += ex*(lcm//div) print(ans_num/(lcm*n)) ```
output
1
14,774
19
29,549
Provide a correct Python 3 solution for this coding contest problem. You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? Note: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints * 2 \le N \le 200,000 * 0 \le A_p \le 10^{12} for any p = 1,\ldots, N * 0 \le B_p \le 100 for any p = 1, \ldots, N * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. Examples Input 5 4 2 6 3 5 1 1 1 1 1 Output 4.700000000000 Input 4 100 0 100 0 0 100 0 100 Output 50.000000000000 Input 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Output 7047.142857142857 Input 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Output 815899161079.400024414062
instruction
0
14,775
19
29,550
"Correct Solution: ``` from bisect import bisect_right def det(p1, p2, p3): area = (p2[0] - p1[0])*(p3[1] - p1[1]) - (p2[1] - p1[1])*(p3[0] - p1[0]) return area > 0 def convex_hull(pts): pts = sorted(pts) n = len(pts) extsize = 0 extpts = [] for i in range(n): while extsize > 1: if det(extpts[-2], extpts[-1], pts[i]): break extsize -= 1 extpts.pop() extpts.append(pts[i]) extsize += 1 t = extsize for i in range(n-1, -1, -1): while extsize > t: if det(extpts[-2], extpts[-1], pts[i]): break extsize -= 1 extpts.pop() extpts.append(pts[i]) extsize += 1 return extpts[:-1] n = int(input()) aa = [int(x) for x in input().split()] bb = [int(x) for x in input().split()] ma = max(aa) ind = -1 for i in range(n): if ma == aa[i]: ind = i break a = aa[i:] + aa[:i+1] b = bb[i:] + bb[:i+1] c = [0]*(n+1) for i in range(2, n+1): c[i] = 2*(c[i-1]+b[i-1])-c[i-2] pts = [] for i in range(n+1): pts.append((i, a[i]-c[i])) f = [-10**15]*(n+1) ext = [] for i, val in convex_hull(pts): if val*n < (a[0]-c[0])*(n-i)+(a[n]-c[n])*i: continue f[i] = val ext.append(i) ext = sorted(ext) for i in range(n+1): if f[i] == -10**15: t = bisect_right(ext, i) l = ext[t-1] r = ext[t] f[i] = f[l] + (i-l)*(f[r]-f[l])/(r-l) ans = 0 for i in range(1, n+1): ans += f[i]+c[i] print(f'{ans/n:.12f}') ```
output
1
14,775
19
29,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? Note: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints * 2 \le N \le 200,000 * 0 \le A_p \le 10^{12} for any p = 1,\ldots, N * 0 \le B_p \le 100 for any p = 1, \ldots, N * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. Examples Input 5 4 2 6 3 5 1 1 1 1 1 Output 4.700000000000 Input 4 100 0 100 0 0 100 0 100 Output 50.000000000000 Input 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Output 7047.142857142857 Input 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Output 815899161079.400024414062 Submitted Solution: ``` def solve(n, a_list, b_list): prev_g_list = [max(a_list)] * n prev_res = sum(prev_g_list) / n while True: print(prev_g_list) new_g_list = [0.0] * n for i in range(n): next_expectation = 0.5 * (prev_g_list[i - 1] + prev_g_list[(i + 1) % n]) - b_list[i] new_g_list[i] = a_list[i] if a_list[i] >= next_expectation else next_expectation new_res = sum(new_g_list) / n if abs(new_res - prev_res) < 1e-10: return new_res prev_g_list = new_g_list prev_res = new_res if __name__ == "__main__": n = int(input()) a_list = [int(s) for s in input().split()] b_list = [int(s) for s in input().split()] res = solve(n, a_list, b_list) print(res) ```
instruction
0
14,776
19
29,552
No
output
1
14,776
19
29,553
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? Note: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints * 2 \le N \le 200,000 * 0 \le A_p \le 10^{12} for any p = 1,\ldots, N * 0 \le B_p \le 100 for any p = 1, \ldots, N * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. Examples Input 5 4 2 6 3 5 1 1 1 1 1 Output 4.700000000000 Input 4 100 0 100 0 0 100 0 100 Output 50.000000000000 Input 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Output 7047.142857142857 Input 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Output 815899161079.400024414062 Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) import sys sys.setrecursionlimit(10**7) def getMoney(now, money): if money >= (a[(now+1)%n]+a[(now-1)%n])/2 - b[now]: return money x = getMoney((now+1)%n, a[(now+1)%n] - b[now]) y = getMoney((now-1)%n, a[(now-1)%n] - b[now]) return (x+y)/2 anss = [] for i in range(n): ans = getMoney(i,a[i]) anss.append(ans) ans = sum(anss)/n print(ans) ```
instruction
0
14,777
19
29,554
No
output
1
14,777
19
29,555
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\\{1,2,\dots, N\\}. The N positions are arranged on a circle (so that 1 is between N and 2). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1, p+1 (with the identifications 0 = N and N+1=1). What is the expected gain of an optimal strategy? Note: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints * 2 \le N \le 200,000 * 0 \le A_p \le 10^{12} for any p = 1,\ldots, N * 0 \le B_p \le 100 for any p = 1, \ldots, N * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10}. Examples Input 5 4 2 6 3 5 1 1 1 1 1 Output 4.700000000000 Input 4 100 0 100 0 0 100 0 100 Output 50.000000000000 Input 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Output 7047.142857142857 Input 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Output 815899161079.400024414062 Submitted Solution: ``` N, = map(int, input().split()) X = list(map(int, input().split())) B = list(map(int, input().split())) for _ in range(1000): for i in range(N): j, k = i+1, i-1 if i == 0: k = N-1 if i == N-1: j = 0 X[i] = max((X[j]+X[k])/2 - B[i], X[i]) print(sum(X)/N) ```
instruction
0
14,778
19
29,556
No
output
1
14,778
19
29,557