message
stringlengths
2
23.4k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
129
108k
cluster
float64
6
6
__index_level_0__
int64
258
216k
Provide tags and a correct Python 3 solution for this coding contest problem. The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await furt...
instruction
0
48,386
6
96,772
Tags: implementation, sortings, strings Correct Solution: ``` def sinkingship(alist): rat,womanchild,man,captain=[],[],[],[] # rat woman & child man captain for i in alist: if i[1]=="rat": rat.append(i[0]) if i[1]=="woman" or i[1]=="child": womanchild.append(i[0]) ...
output
1
48,386
6
96,773
Provide tags and a correct Python 3 solution for this coding contest problem. The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await furt...
instruction
0
48,387
6
96,774
Tags: implementation, sortings, strings Correct Solution: ``` def main(): def clear(t): nonlocal n, q for i in range(n): if q[i] == None: continue if q[i][1] in t: print(q[i][0]) q[i] = None n = int(input()) q = [] f...
output
1
48,387
6
96,775
Provide tags and a correct Python 3 solution for this coding contest problem. The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await furt...
instruction
0
48,388
6
96,776
Tags: implementation, sortings, strings Correct Solution: ``` from operator import itemgetter peoplenum = int(input()) list = [] peopleorder = [] supposedorder = {"rat":1, "woman":2, "child":2, "man":3, "captain":4} order = [] for i in range(peoplenum): list.append(input().split()) for i in range(peoplenum): ...
output
1
48,388
6
96,777
Provide tags and a correct Python 3 solution for this coding contest problem. The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await furt...
instruction
0
48,389
6
96,778
Tags: implementation, sortings, strings Correct Solution: ``` n = int(input()) arr = [] d = {"rat":1,"woman":2,"child":2,"man":3,"captain":5} for i in range(n): arr.append(tuple(input().split())) arr.sort(key = lambda x:d[x[1]]) for data in arr: print(data[0]) ```
output
1
48,389
6
96,779
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,927
6
99,854
Tags: dp Correct Solution: ``` MOD = int(1e9) + 7 if __name__ == "__main__": a = input() b = input() k = int(input()) if(len(a) != len(b)): print(0) exit() a = a + a x = 0 y = 0 for i in range(len(a) // 2): flag = 1 for j in range(len(b)): if(a...
output
1
49,927
6
99,855
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,928
6
99,856
Tags: dp Correct Solution: ``` start,end,k=input(),input(),int(input()) n,mod=len(end),10**9+7 dp=[1,0] psum=1 for i in range(k): dp[0]=psum-dp[0] dp[1]=psum-dp[1] psum=(dp[0]+((n-1)*dp[1])%mod)%mod ans=0 for i in range(n): if start[i:]+start[:i]==end: if i==0:ans+=dp[0] else:ans+=dp[1] print(ans%mod) ```
output
1
49,928
6
99,857
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,929
6
99,858
Tags: dp Correct Solution: ``` start, end, k = input(), input(), int(input()) dp = [[start == end for _ in range(k + 1)], [start != end for _ in range(k + 1)]] mod = int(1e9 + 7) same = sum(end == (start[i: len(start)] + start[0: i]) for i in range(len(start))) diff = len(start) - same for i in range(1, k + 1): dp[...
output
1
49,929
6
99,859
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,930
6
99,860
Tags: dp Correct Solution: ``` class Solution(): def number_or_ways(start, end, moves): p = 10**9+7 num_rots = 0 for i in range(len(start)): rot = start[i:]+start[0:i] if rot == end: num_rots += 1 dp = [[0 for i in range(2)] for j in range(moves+1)] dp[0][0], dp[0][1] = 1, 0 for i in range(1, ...
output
1
49,930
6
99,861
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,931
6
99,862
Tags: dp Correct Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in fi...
output
1
49,931
6
99,863
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,932
6
99,864
Tags: dp Correct Solution: ``` # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code def main(): MOD = int(1e9 + 7) a = input() b = input() n = in...
output
1
49,932
6
99,865
Provide tags and a correct Python 3 solution for this coding contest problem. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operati...
instruction
0
49,933
6
99,866
Tags: dp Correct Solution: ``` def WordCut(): start = input() end = input() k = int(input()) n=len(start) dpA,dpB = (start==end),(start!=end) end+=end A=sum(start==end[i:i+n] for i in range(n)) B = n- A M = 10**9+7 for _ in range(k): dpA,dpB=(dpA*(A-1)+dpB*A)%M,(dpA*B+dpB...
output
1
49,933
6
99,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty...
instruction
0
49,934
6
99,868
No
output
1
49,934
6
99,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty...
instruction
0
49,935
6
99,870
No
output
1
49,935
6
99,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty...
instruction
0
49,936
6
99,872
No
output
1
49,936
6
99,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty...
instruction
0
49,937
6
99,874
No
output
1
49,937
6
99,875
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,095
6
100,190
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` P = 910519 MOD = 32416190071 p = [1] for i in range(1, 200010): p.append((P * p[i - 1]) % MOD) n = int(input()) s = list(set([input() for i in range(n)])) n = len(s) name = ['' for i in range(n)] path = ['' fo...
output
1
50,095
6
100,191
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,096
6
100,192
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` n=int(input()) d={}; D={}; ans=[] for _ in range(n): s=input()+'/'; t=s.find('/',7); d.setdefault(s[:t],set()).add(s[t:]) for k in d: D.setdefault(frozenset(d[k]),[]).append(k) [ans.append(D[k]) for k in D if len(D[k...
output
1
50,096
6
100,193
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,097
6
100,194
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` import sys from collections import defaultdict # sys.stdin = open("ivo.in") n = int(sys.stdin.readline()) h = defaultdict(set) for iter in range(n): entry = sys.stdin.readline().rstrip() + "/" path_start = 7 + ...
output
1
50,097
6
100,195
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,098
6
100,196
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` n=int(input()) d={} D={} for i in range(n): h,*p=(input()[7:]+'/').split('/') d.setdefault(h,set()).add('/'.join(p)) for x in d: t=tuple(sorted(d[x])) D.setdefault(t,[]).append(x) def ans(): for...
output
1
50,098
6
100,197
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,099
6
100,198
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` from itertools import groupby web_addresses_number = int(input()) prephix = "http://" def split_address(address): host = "" path = "" address = address[7:] i = 0 while i < len(address) and address...
output
1
50,099
6
100,199
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,100
6
100,200
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` import sys n = int(input()) domains = {} for full_request in sys.stdin: request = full_request[7:-1] domain, sep, path = request.partition('/') if domain in domains: domains[domain].add(sep + p...
output
1
50,100
6
100,201
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,101
6
100,202
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` n=int(input()) d={} D={} for i in range(n): h,*p=(input()[7:]+'/').split('/') d.setdefault(h,set()).add('/'.join(p)) for x in d: D.setdefault(frozenset(d[x]),[]).append(x) def ans(): for x in D: ...
output
1
50,101
6
100,203
Provide tags and a correct Python 3 solution for this coding contest problem. There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru. You are given a list of page addresses being querie...
instruction
0
50,102
6
100,204
Tags: *special, binary search, data structures, implementation, sortings, strings Correct Solution: ``` import sys d = dict() b='/' for line in sys.stdin: line=line[:-1].split(b) host,coso=b.join(line[:3]), b.join(line[3:]) if len(line)>3: coso='/'+coso if len(line)>1: if host in d: d[host].append("I"+coso) ...
output
1
50,102
6
100,205
Provide tags and a correct Python 3 solution for this coding contest problem. You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons ...
instruction
0
50,113
6
100,226
Tags: flows Correct Solution: ``` import sys from heapq import heappop, heappush class Edge: def __init__(self, u, v, cap, flow, cost, rev) -> None: self.u = u self.v = v self.cap = cap self.flow = flow self.cost = cost self.rev = rev def add_edge(adj, u, v, capv, f...
output
1
50,113
6
100,227
Provide tags and a correct Python 3 solution for this coding contest problem. You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons ...
instruction
0
50,114
6
100,228
Tags: flows Correct Solution: ``` import sys from heapq import heappop, heappush class Edge: def __init__(self, u, v, cap, flow, cost, rev) -> None: self.u = u self.v = v self.cap = cap self.flow = flow self.cost = cost self.rev = rev def add_edge(adj, u, v, capv, f...
output
1
50,114
6
100,229
Provide tags and a correct Python 3 solution for this coding contest problem. You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons ...
instruction
0
50,115
6
100,230
Tags: flows Correct Solution: ``` import sys from heapq import heappop, heappush class Edge: def __init__(self, u, v, cap, flow, cost, rev): self.u = u self.v = v self.cap = cap self.flow = flow self.cost = cost self.rev = rev def add_edge(adj, u, v, capv, flowv, co...
output
1
50,115
6
100,231
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,750
6
101,500
Tags: *special Correct Solution: ``` print('INTERCAL') ```
output
1
50,750
6
101,501
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,751
6
101,502
Tags: *special Correct Solution: ``` #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from io import BytesIO, IOBase from itertools import * from collections import * # sys.setrecursionlimit(10**5) if sys.version_info[0] ...
output
1
50,751
6
101,503
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,752
6
101,504
Tags: *special Correct Solution: ``` """==================================================================================== ==================================================================================== ___ _______ ___ _______ ___ ___ | /\ | | \ | ...
output
1
50,752
6
101,505
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,753
6
101,506
Tags: *special Correct Solution: ``` n=input();print("INTERCAL") ```
output
1
50,753
6
101,507
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,754
6
101,508
Tags: *special Correct Solution: ``` n=input() print("INTERCAL") ```
output
1
50,754
6
101,509
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program ...
instruction
0
50,755
6
101,510
Tags: *special Correct Solution: ``` #Fun.... print('INTERCAL') ```
output
1
50,755
6
101,511
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's lengt...
instruction
0
50,792
6
101,584
Tags: greedy Correct Solution: ``` def main(): n, k = map(int, input().split()) if n < k or k == 1 < n: print(-1) elif (n - k) & 1: print('ab' * ((n - k + 1) // 2) + 'acdefghijklmnopqrstuvwxyz'[:k - 1]) else: print('ab' * ((n - k) // 2) + 'abcdefghijklmnopqrstuvwxyz'[:k]) if __...
output
1
50,792
6
101,585
Provide tags and a correct Python 3 solution for this coding contest problem. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's lengt...
instruction
0
50,794
6
101,588
Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) if k>n: print(-1) elif n==1 and k==1: print("a") elif k==1: print(-1) else: ans="" k=k-2 n=n-k z=99 if n%2==0: ans+="ab"*(n//2) while(k>0): ans+=chr(z) z+=1 k-=1 else: ...
output
1
50,794
6
101,589
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,862
6
101,724
Tags: brute force, implementation, strings Correct Solution: ``` n = int(input()) s = input() l = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] for given in l: if len(given) != len(s): continue istrue = 1 for i in range(0, n): if given[i] != s[i] an...
output
1
50,862
6
101,725
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,863
6
101,726
Tags: brute force, implementation, strings Correct Solution: ``` '''input 7 .l.r.o. ''' n = int(input()) s = input() l = [i for i in ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] if len(i) == n] for x in l: for y in range(n): if all(s[y] == x[y] for y in range(n) if s[y] !=...
output
1
50,863
6
101,727
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,864
6
101,728
Tags: brute force, implementation, strings Correct Solution: ``` n = int(input()) s = input() a = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] for i in a: if (len(i) != len(s)): continue b = True for j in range(len(s)): if (s[j] != '.' and i[j] != ...
output
1
50,864
6
101,729
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,865
6
101,730
Tags: brute force, implementation, strings Correct Solution: ``` #!/usr/bin/env python3 import re def main(): input() p = re.compile(input()) pokemons = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] pokemons = sorted(pokemons, key=len) for x in pokemons...
output
1
50,865
6
101,731
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,866
6
101,732
Tags: brute force, implementation, strings Correct Solution: ``` l_6 = ["espeon"] l_7 = ["jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon"] l_8 = ["vaporeon"] input_length = input() input_string = input() if input_length == "6": print(l_6[0]) elif input_length == "8": print(l_8[0]) else: for x in l_...
output
1
50,866
6
101,733
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,867
6
101,734
Tags: brute force, implementation, strings Correct Solution: ``` def match(s, p): if len(s) != len(p): return False for chs, chp in zip(s, p): if chs != '.' and chs != chp: return False return True n = int(input()) s = input() for p in ['vaporeon', 'jolteon', 'flareon', 'espeon'...
output
1
50,867
6
101,735
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,868
6
101,736
Tags: brute force, implementation, strings Correct Solution: ``` import sys def get_single_int (): return int (sys.stdin.readline ().strip ()) def get_string (): return sys.stdin.readline ().strip () def get_ints (): return map (int, sys.stdin.readline ().strip ().split ()) def get_list (): return list...
output
1
50,868
6
101,737
Provide tags and a correct Python 3 solution for this coding contest problem. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different p...
instruction
0
50,869
6
101,738
Tags: brute force, implementation, strings Correct Solution: ``` def prov(s2): global s1 if len(s1)!=len(s2): return False for i in range(len(s1)): if s1[i]!=s2[i] and s1[i]!='.': return False print(s2) exit(0) n=int(input()) s1=input().strip() b=["vaporeon", "jolteon", "...
output
1
50,869
6
101,739
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,248
6
102,496
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 QS = [[] for i in range(17)] QS[1] = [a, b, c, d] L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1} H = [] get = L.get push = H.append for l in range(1, 16): Q = QS[l] li = 13-l; l3 = l+3; l1 = l+1 pop = Q.pop pushQN = QS[l1].append whi...
output
1
51,248
6
102,497
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,249
6
102,498
"Correct Solution: ``` def calc(s): def parse(a, b, c, d): nonlocal cur g = s[cur]; cur += 1 if g == '-': return 1 ^ parse(a, b, c, d) if g == '(': p = parse(a, b, c, d) cmd = s[cur]; cur += 1 q = parse(a, b, c, d) cur += 1 ...
output
1
51,249
6
102,499
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,250
6
102,500
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 L = {el: 1 for el in [a, b, c, d, e, 0]} for i in range(6): R = sorted(L.items(), key=lambda x: x[1]) for p, l in R: if l < 16: L[p ^ e] = min(L.get(p ^ e, 16), l+1) if l+3 < 16: for q, r in R: ...
output
1
51,250
6
102,501
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,251
6
102,502
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 def calc(s): res = eval(s.replace("-", "~").replace("*", "&").replace("1", "e")) return e ^ ~res if res < 0 else res base = [a, b, c, d, e, 0] L = {el: 1 for el in base} for i in range(6): R = dict(L) for p in R: if R[p] < 16: ...
output
1
51,251
6
102,503
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,252
6
102,504
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 from heapq import heappush, heappop base = [a, b, c, d, e, 0] Q = [(1, el) for el in base] L = {el: 1 for el in base} H = [] while Q: l, p = heappop(Q) if L[p] < l: continue if l+1 < L.get(p ^ e, 17): L[p^e] = l+1 if l+1 < 16...
output
1
51,252
6
102,505
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,253
6
102,506
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 from heapq import heappush, heappop base = [a, b, c, d, e, 0] Q = [(1, el) for el in base] L = {el: 1 for el in base} H = [] get = L.get push = H.append while Q: l, p = heappop(Q) if L[p] < l: continue if l+1 < get(p ^ e, 17): L[p ^ ...
output
1
51,253
6
102,507
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,254
6
102,508
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 QS = [[] for i in range(17)] QS[1] = [a, b, c, d] L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1} H = [] get = L.get push = H.append for l in range(1, 16): Q = QS[l] QN = QS[l+1] while Q: p = Q.pop() if L[p] < l: continue ...
output
1
51,254
6
102,509
Provide a correct Python 3 solution for this coding contest problem. Boolean Expression Compressor You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. The grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `...
instruction
0
51,255
6
102,510
"Correct Solution: ``` a=65280; b=61680; c=52428; d=43690; e=65535 from heapq import heappush, heappop base = [a, b, c, d, e, 0] Q = [(1, el) for el in base] L = {el: 1 for el in base} H = [] while Q: l, p = heappop(Q) if L[p] < l: continue if l+1 < L.get(p ^ e, 17): L[p ^ e] = l+1 if l+1 < ...
output
1
51,255
6
102,511