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. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
129
6
258
Tags: strings Correct Solution: ``` for _ in range(int(input())): n = int(input()) a = list(input()) b = list(input()) ml = [] for i in range(n-1): if a[i] != b[i]: if a[i] in a[i+1:]: ind = i+1+a[i+1:].index(a[i]) b[i], a[ind] = a[ind], b[i] ...
output
1
129
6
259
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
130
6
260
Tags: strings Correct Solution: ``` from sys import stdin, stdout from collections import Counter, deque from bisect import bisect_left from itertools import product #input = stdin.buffer.readline T = int(input()) for _ in range(T): n = int(input()) a, b = list(input()), list(input()) cc = Counter(a+b) ...
output
1
130
6
261
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
131
6
262
Tags: strings Correct Solution: ``` for _ in range(int(input())): n = int(input()) na = list(input()) nb = list(input()) k=0 zz = len(na) ans = [] for i in range(zz): f = 0 if(na[i]==nb[i]): f= 1 if(not f): for j in range(i+1,zz): if(na[j]==na[i]): ans.appe...
output
1
131
6
263
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
132
6
264
Tags: strings Correct Solution: ``` T = int(input()) for t in range(T): N = int(input()) s = list(input()) t = list(input()) i = 0 possible = True res = [] while i < N: # print("i : ", i) # print("res : ", res) # print("s[i], t[i] : ", s[i], t[i]) if s[i] != t...
output
1
132
6
265
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
133
6
266
Tags: strings Correct Solution: ``` for _ in range(int(input())): n = int(input()) lis=[0]*2 lis[0]=list(input()) lis[1]=list(input()) ans=[] gg=0 for i in range(n): a=lis[0][i] ind=-1 for j in range(i+1,n): if a==lis[0][j]: ind=j ...
output
1
133
6
267
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
134
6
268
Tags: strings Correct Solution: ``` import sys for t in range(int(sys.stdin.readline())): n = int(sys.stdin.readline()) s1 = [ord(c) - 97 for c in sys.stdin.readline().strip()] s2 = [ord(c) - 97 for c in sys.stdin.readline().strip()] pl = [] orde = True for i in range(26): st1 = {j for j...
output
1
134
6
269
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
135
6
270
Tags: strings Correct Solution: ``` from collections import defaultdict # input = sys.stdin.readline def case(): n = int(input()) s = input() s = [i for i in s] t = input() t = [i for i in t] d= defaultdict(int) for i in s: d[i]+=1 for i in t: d[i]+=1 for i in d.value...
output
1
135
6
271
Provide tags and a correct Python 3 solution for this coding contest problem. This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previo...
instruction
0
136
6
272
Tags: strings Correct Solution: ``` import sys input = sys.stdin.readline for q in range(int(input())): N = int(input()) s = list(input().rstrip()) t = list(input().rstrip()) ans = [] for i in range(N-1): if s[i] != t[i]: for j in range(i + 1, N): if s[j] == s[i]...
output
1
136
6
273
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
286
6
572
Tags: games, greedy Correct Solution: ``` from collections import Counter s=input() dic=Counter(s) count=0 for val in dic.values(): if val%2!=0: count+=1 if count==0: print("First") elif count%2==0: print("Second") else: print("First") ```
output
1
286
6
573
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
287
6
574
Tags: games, greedy Correct Solution: ``` from collections import Counter def iswin(c): if c == c[::-1]: return True, None else: co = Counter(c) ae = 0 k1 = c[0] for k, v in co.items(): if v%2==0: ae += 1 k1 = k if ae =...
output
1
287
6
575
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
288
6
576
Tags: games, greedy Correct Solution: ``` if __name__ == '__main__': s = input() c = [s.count(x) for x in set(s)] total = 0 for x in c: if x % 2 != 0: total += 1 if total % 2 == 0 and total != 0: print("Second") else: print("First") ```
output
1
288
6
577
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
289
6
578
Tags: games, greedy Correct Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/276/B s = input() d_e = {} n_o = 0 for c in s: if c not in d_e: d_e[c] = 0 d_e[c] += 1 if (d_e[c] % 2 == 1): n_o += 1 else: n_o -= 1 if n_o == 0: ...
output
1
289
6
579
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
290
6
580
Tags: games, greedy Correct Solution: ``` import sys arr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] def check(d): w = 0 for i in d: if(d[i]%2!=0): w = w+1 return w def deeznuts(n): b = [] for ...
output
1
290
6
581
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
291
6
582
Tags: games, greedy Correct Solution: ``` s=list(input()) for n in s: if n==' ': s.remove(n) def normalisation(s): c=[] b=set() for letter in s: if letter in b: continue if s.count(letter)%2==1: c.append(letter) ...
output
1
291
6
583
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
292
6
584
Tags: games, greedy Correct Solution: ``` s = input() dict = {} l = list(s) total = -1 for i in l: if i in dict: continue else: c = l.count(i) dict[i] = c if c%2: total += 1 if total == -1: print("First") elif total%2: print("Second") else: print("F...
output
1
292
6
585
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In o...
instruction
0
293
6
586
Tags: games, greedy Correct Solution: ``` word = input() count = 0 for char in set(word): if word.count(char) & 1: count += 1 if count == 0 or count&1: print("First") else: print("Second") ```
output
1
293
6
587
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,111
6
2,222
Tags: *special, data structures, implementation Correct Solution: ``` def cd(where): for s in where: if s == "..": directories.pop() else: directories.append(s) def pwd(): print("/", end="") for s in directories: print(s, "/", sep="", end="") print() n ...
output
1
1,111
6
2,223
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,112
6
2,224
Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) cur = list() for i in range(0,n): st = str(input()) if st.startswith('pwd'): ans = '/' for s in cur : ans = ans + s ans = ans + '/' print(ans) else : st = st.strip() temp = st.split('/') for s in temp: if s ==...
output
1
1,112
6
2,225
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,113
6
2,226
Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) dir = [] def pwd(dir): if len(dir) == 0: print("/") else: for i in dir: print("/"+i, end="") print("/") for i in range(n): line = input() #print("##"+line+"##") if line.startswith("cd"): dir_line = line.split()[1]....
output
1
1,113
6
2,227
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,114
6
2,228
Tags: *special, data structures, implementation Correct Solution: ``` def printPath(path): print('/', end='') if len(path): for dir in path: print(dir + '/', end='') print() # Get input data num_commands = int(input()) commands = [] for i in range(0, num_commands): commands.append...
output
1
1,114
6
2,229
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,115
6
2,230
Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) path = [] for _ in range(n): s = input().strip() if s == 'pwd': print('/' + '/'.join(path) + ['', '/'][bool(path)]) else: s = s.split(' ')[1] if s[0] == '/': s = s.lstrip('/') ...
output
1
1,115
6
2,231
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,116
6
2,232
Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) stacc = ["/"] while n > 0: line = input() linesplit = line.split() if len(linesplit) == 2: command = linesplit[0] parameter = linesplit[1] else: command = linesplit[0] if command == "pwd": print("".join(stacc)) el...
output
1
1,116
6
2,233
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,117
6
2,234
Tags: *special, data structures, implementation Correct Solution: ``` n = int(input()) dirs = ['/'] def ins_split(command): command = command.split('/') command[:] = [i for i in command if i != ""] command[:] = [i+'/' for i in command] return command def display(): # indexes to remove cou...
output
1
1,117
6
2,235
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directo...
instruction
0
1,118
6
2,236
Tags: *special, data structures, implementation Correct Solution: ``` def getNext(s): return s[3:] lines = int(input()) stack = ["/"] for x in range(lines): command = input() start = command[0] if start == "p": print("".join(stack)) elif start == "c": folders = getNext(command).split("/") if not...
output
1
1,118
6
2,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,119
6
2,238
Yes
output
1
1,119
6
2,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,120
6
2,240
Yes
output
1
1,120
6
2,241
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,121
6
2,242
Yes
output
1
1,121
6
2,243
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,122
6
2,244
Yes
output
1
1,122
6
2,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,123
6
2,246
No
output
1
1,123
6
2,247
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,124
6
2,248
No
output
1
1,124
6
2,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,125
6
2,250
No
output
1
1,125
6
2,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) an...
instruction
0
1,126
6
2,252
No
output
1
1,126
6
2,253
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,141
6
2,282
Tags: constructive algorithms Correct Solution: ``` a, b = input(), input() ca = a.count('1') cb = b.count('1') if ca + ca % 2 >= cb: print('YES') else: print('NO') ```
output
1
1,141
6
2,283
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,142
6
2,284
Tags: constructive algorithms Correct Solution: ``` ax, bx = 0, 0 for c in input(): if c == '1': ax += 1 for c in input(): if c == '1': bx += 1 print("YES" if bx <= ax + ax % 2 else "NO") ```
output
1
1,142
6
2,285
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,143
6
2,286
Tags: constructive algorithms Correct Solution: ``` a, b = input(), input() ax = sum([ord(c) - ord('0') for c in a]) bx = sum([ord(c) - ord('0') for c in b]) print("YES" if bx <= ax + ax % 2 else "NO") ```
output
1
1,143
6
2,287
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,144
6
2,288
Tags: constructive algorithms Correct Solution: ``` a=input() b=input() coa=0 cob=0 for i in a: if i=='1': coa+=1 for i in b: if i=='1': cob+=1 if coa+(coa&1)>=cob:print('YES') else:print('NO') ```
output
1
1,144
6
2,289
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,145
6
2,290
Tags: constructive algorithms Correct Solution: ``` def play(s, t): count1, count2 = 0, 0 for elem in s: if elem == '1': count1 += 1 for elem in t: if elem == '1': count2 += 1 if count2 - count1 > 1 or (count2 - count1 == 1 and count1 % 2 == 0): return "NO...
output
1
1,145
6
2,291
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,146
6
2,292
Tags: constructive algorithms Correct Solution: ``` print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO') ```
output
1
1,146
6
2,293
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,147
6
2,294
Tags: constructive algorithms Correct Solution: ``` a = input() b = input() if ((a.count('1') + 1) // 2 * 2) >= b.count('1'): print("YES") else: print("NO") ```
output
1
1,147
6
2,295
Provide tags and a correct Python 3 solution for this coding contest problem. You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. T...
instruction
0
1,148
6
2,296
Tags: constructive algorithms Correct Solution: ``` 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 file.mode or "r" not in file.mode ...
output
1
1,148
6
2,297
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,252
6
2,504
Tags: dfs and similar, graphs Correct Solution: ``` n = int(input()) g = {} ins = {} outs = {} vs = set() for _ in range(n): s = input().strip() left = s[:-1] right = s[1:] g.setdefault(left, []).append(right) outs[left] = outs.get(left, 0) + 1 ins[right] = ins.get(right, 0) + 1 vs.add...
output
1
1,252
6
2,505
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,253
6
2,506
Tags: dfs and similar, graphs Correct Solution: ``` # from debug import debug from collections import defaultdict, Counter, deque import sys; input = sys.stdin.readline n = int(input()) graph = defaultdict(list) d = Counter() for i in range(n): s = input().strip() a, b = s[:2], s[1:3] if i == 0: e = a graph[a].app...
output
1
1,253
6
2,507
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,254
6
2,508
Tags: dfs and similar, graphs Correct Solution: ``` from collections import defaultdict, Counter def quit(): print('NO') exit() def dfs(i): #topological sorting S = [i] while S: s = S[-1] if graph[s]: S.append(graph[s].pop()) else: S.pop() an...
output
1
1,254
6
2,509
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,255
6
2,510
Tags: dfs and similar, graphs Correct Solution: ``` import sys readline = sys.stdin.readline write = sys.stdout.write from string import ascii_lowercase, ascii_uppercase, digits def hierholzer(N, M, E): G = [[] for i in range(N)] deg = [0]*N rdeg = [0]*N for a, b in E: deg[a] += 1 rdeg...
output
1
1,255
6
2,511
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,256
6
2,512
Tags: dfs and similar, graphs Correct Solution: ``` def dfs(start_vertex, go_out): m = 0 last = {} for key, value in go_out.items(): last[key] = value - 1 # -1for each item from go_out m += value # And total count of ways stack = [start_vertex] # Init stack and put first vertex path = [] # Result path ...
output
1
1,256
6
2,513
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,257
6
2,514
Tags: dfs and similar, graphs Correct Solution: ``` def out(a): print('-'*len(a)) for i in range(len(a)): print(*[a[i][j] for j in range(len(a[0]))]) print('-'*len(a)) def get_point(p): return len(adj_list[p]) def find_way(p): if sum(adj_list[p])>0: for point in range(len(adj_li...
output
1
1,257
6
2,515
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,258
6
2,516
Tags: dfs and similar, graphs Correct Solution: ``` import collections def negation() : print("NO") exit() NumberOfCharacters = int(input()) vertex = collections.defaultdict(list) counterr = collections.Counter() for i in range(NumberOfCharacters): value = input() v1,v2 = value[:2],value[1:3] if i...
output
1
1,258
6
2,517
Provide tags and a correct Python 3 solution for this coding contest problem. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the pa...
instruction
0
1,259
6
2,518
Tags: dfs and similar, graphs Correct Solution: ``` INT_MAX = int(1e9 + 7) def dfs(start_vertex, go_out): m = 0 last = {} for key, value in go_out.items(): last[key] = value - 1 # -1for each item from go_out m += value # And total count of ways stack = [start_vertex] # Init stack and put first vertex pat...
output
1
1,259
6
2,519
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time ...
instruction
0
1,363
6
2,726
Tags: data structures, dfs and similar, dp, dsu, graphs Correct Solution: ``` f = lambda: input().split() n, m, k = map(int, f()) u = list(range(n + 1)) v = [n] * n s = {q: i for i, q in zip(u, f())} p = ['YES'] * m def g(i): k = u[i] while k != u[k]: k = u[k] while u[i] != k: i, u[i] = u[i], k return ...
output
1
1,363
6
2,727
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time ...
instruction
0
1,364
6
2,728
Tags: data structures, dfs and similar, dp, dsu, graphs Correct Solution: ``` def get_relation(synonyms, antonyms, word1, word2): if word1 not in synonyms or word2 not in synonyms: return '3' group1 = synonyms[word1] group2 = synonyms[word2] if group1 == group2: return '1' if group1 in antonyms a...
output
1
1,364
6
2,729