message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exce...
instruction
0
273
14
546
Tags: binary search, combinatorics, two pointers Correct Solution: ``` from collections import deque from math import factorial nd = input() nd = nd.split() n = int(nd[0]) d = int(nd[1]) xcorr = list(map(int, input().split())) dq = deque() g = 0 for x in xcorr: dq.append(x) while (x - dq[0]) > d: if le...
output
1
273
14
547
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exce...
instruction
0
274
14
548
Tags: binary search, combinatorics, two pointers Correct Solution: ``` n, k = list(map(int, input().split())) lis = list(map(int, input().split())) def find(s, lis, a, k): l = s r = len(lis) - 1 while (r - l) > 1: mid = (l + r) // 2 if lis[mid] < a + k: l = mid ...
output
1
274
14
549
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exce...
instruction
0
275
14
550
Tags: binary search, combinatorics, two pointers Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Mon May 16 17:14:14 2016 @author: Hangell """ from collections import deque str1=input() str2=input() n=int(str1.split()[0]) d=int(str1.split()[1]) numlist=str2.split() newdeque=deque() Sum=0 cha=0 way=0 for ...
output
1
275
14
551
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exce...
instruction
0
277
14
554
Tags: binary search, combinatorics, two pointers Correct Solution: ``` from sys import stdin,stdout,stderr def binary(lo,hi,value): global a ans=lo while lo<=hi: mid=(lo+hi)//2 if a[mid]<=value: ans=mid lo=mid+1 else:hi=mid-1 return ans n,d=map(int,input()...
output
1
277
14
555
Provide tags and a correct Python 3 solution for this coding contest problem. Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: * Each piece should contain at least l numb...
instruction
0
375
14
750
Tags: binary search, data structures, dp, two pointers Correct Solution: ``` def split(a,n,s,l): pieces = [] i = 1 tmpmin = a[0] tmpmax = a[0] tmppc = [a[0]] while i<n: if abs(a[i]-tmpmin)<=s and abs(a[i]-tmpmax)<=s: tmppc.append(a[i]) if a[i]<tmpmin: tmpmin=a[i...
output
1
375
14
751
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
471
14
942
Tags: brute force, greedy, implementation Correct Solution: ``` n, k = map(int, input().split()) l = list(map(int, input().split())) l = sorted(l, reverse=True) s = 0 for _ in range(n): if l[0] <= 0: break if l[0] <= 2: l[0] -= min(l[0],2) s += 1 l[0] -= min(l[0],4) l = sorted(...
output
1
471
14
943
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
472
14
944
Tags: brute force, greedy, implementation Correct Solution: ``` n,m=map(int,input().split()) l=list(map(int,input().split())) p=n for i in range(m) : b=l[i]//4 l[i]=l[i]-4*min(p,l[i]//4) p=p-min(p,b) p1=n*2 for i in range(m) : b=l[i]//2 l[i]=l[i]-2*min(p1,l[i]//2) p1=p1-min(p1,b) p2=p+p1 p3=p f...
output
1
472
14
945
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
473
14
946
Tags: brute force, greedy, implementation Correct Solution: ``` import sys n, k = [ int(x) for x in input().split() ] arr = list( map( int, input().split()) ) cnt_2 = 2 * n cnt_4 = n cnt_1 = 0 i = 0 while(cnt_4 > 0 and i < k): tmp = int(arr[i] / 4) if(tmp > 0 and cnt_4 > 0): arr[i] = arr[i] - 4 * min(...
output
1
473
14
947
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
474
14
948
Tags: brute force, greedy, implementation Correct Solution: ``` from math import ceil n,k = map(int, input().split()) a = list(map(int, input().split())) def solve(n,k,a): one,two,four = 0, n*2, n for size in a: while size >= 4: if four > 0: four -= 1 else: ...
output
1
474
14
949
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
475
14
950
Tags: brute force, greedy, implementation Correct Solution: ``` n,k = map(int,input().split(" ")) a = list(map(int,input().split(" "))) count = 0 for i in range(0,len(a)): if a[i]%2 == 0: count = count + 1 if k-count <= n*8-sum(a): if k-count < n and k==n*4: print("NO") else: prin...
output
1
475
14
951
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
476
14
952
Tags: brute force, greedy, implementation Correct Solution: ``` def solve(a, n, k): cnt =[0 for i in range(5)] duplas, quads, sozinhos = 2*n, n, 0 for i in a: for j in range(k): while i >= 3: if quads > 0: i -= 4; quads -= 1 elif duplas > 0: i -= 2; duplas -= 1 ...
output
1
476
14
953
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
477
14
954
Tags: brute force, greedy, implementation Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) c = [0, 0, 0, 0] for t in a: c[0] += t//4 if t%4: c[t%4] += 1 c[0] += c[3] c[3] = 0 if c[0] > n: c[2] += 2*(c[0]-n) c[0] = n t = min(n-c[0], c[1], c[2]) c[0] += t c[...
output
1
477
14
955
Provide tags and a correct Python 3 solution for this coding contest problem. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army th...
instruction
0
478
14
956
Tags: brute force, greedy, implementation Correct Solution: ``` # encoding:utf-8 def main(): n, k = list(map(int, input().split())) nums = list(map(int, input().split())) seat_two = n * 2 seat_four = n seat_one = 0 n_four = sum([x // 4 for x in nums]) nums = [x % 4 for x in nums] n_two = sum([x // 2 for x in...
output
1
478
14
957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
479
14
958
Yes
output
1
479
14
959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
480
14
960
Yes
output
1
480
14
961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
481
14
962
Yes
output
1
481
14
963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
482
14
964
Yes
output
1
482
14
965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
483
14
966
No
output
1
483
14
967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
484
14
968
No
output
1
484
14
969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
485
14
970
No
output
1
485
14
971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has r...
instruction
0
486
14
972
No
output
1
486
14
973
Provide tags and a correct Python 3 solution for this coding contest problem. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engi...
instruction
0
487
14
974
Tags: combinatorics, dfs and similar, dsu, graphs, trees Correct Solution: ``` n = int(input()) m = 2 * n + 1 u = [[] for i in range(m)] v = [0] * m s = [0] * m d = 10 ** 9 + 7 y = 1 for j in range(n): a, b = map(int, input().split()) v[a] = b if a != b: s[b] += 1 u[b].append(a) for b in r...
output
1
487
14
975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are ...
instruction
0
488
14
976
No
output
1
488
14
977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are ...
instruction
0
489
14
978
No
output
1
489
14
979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are ...
instruction
0
490
14
980
No
output
1
490
14
981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are ...
instruction
0
491
14
982
No
output
1
491
14
983
Provide a correct Python 3 solution for this coding contest problem. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \l...
instruction
0
789
14
1,578
"Correct Solution: ``` from itertools import accumulate import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, T = map(int, input().split()) time = [0] * (T + 2) for _ in range(N): l, r = map(int, input().split()) time[l] += 1 time[r] -= 1 print(max(accumulate(time))) ```
output
1
789
14
1,579
Provide a correct Python 3 solution for this coding contest problem. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \l...
instruction
0
791
14
1,582
"Correct Solution: ``` #!/usr/bin/env python3 # DSL_5_A: The Maximum Number of Customers def run(): n, t = [int(i) for i in input().split()] sch = [0] * (t+1) for _ in range(n): enter, leave = [int(i) for i in input().split()] sch[enter] += 1 sch[leave] -= 1 c = 0 maxc = ...
output
1
791
14
1,583
Provide a correct Python 3 solution for this coding contest problem. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \l...
instruction
0
792
14
1,584
"Correct Solution: ``` from itertools import accumulate n,t=map(int,input().split()) timeline=[0 for i in range(t+1)] for i in range(n): a,b=map(int,input().split()) timeline[a]+=1 timeline[b]-=1 print(max(accumulate(timeline))) ```
output
1
792
14
1,585
Provide a correct Python 3 solution for this coding contest problem. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \l...
instruction
0
795
14
1,590
"Correct Solution: ``` def main(): n,t = map(int,input().split()) t+=1 T = [0]*t for _ in range(n): l,r = map(int,input().split()) T[l]+=1 T[r]-=1 num = 0 res = 0 for i in range(t): num += T[i] res = max(num,res) print (res) if __name__ == '__main...
output
1
795
14
1,591
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
869
14
1,738
Tags: dfs and similar, graphs, trees Correct Solution: ``` import math as mt import sys,string input=sys.stdin.readline L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) from collections import defaultdict def dfs(n,dx): vis[n]=1...
output
1
869
14
1,739
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
870
14
1,740
Tags: dfs and similar, graphs, trees Correct Solution: ``` import sys from collections import deque class Graph(object): def __init__(self, n): self.root = [] self.adj = {} self.make_adj(n) def make_adj(self, n): for i in range(1, n+1): self.adj[i] = [] ...
output
1
870
14
1,741
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
871
14
1,742
Tags: dfs and similar, graphs, trees Correct Solution: ``` import sys sys.setrecursionlimit(100000000) n=int(input()) d={} de=[-1 for i in range(n+1)] for i in range(1,n+1): d[i]=int(input()) def depth(v): if de[v]!=-1: return de[v] if d[v]==-1: return 0 else: return 1+depth(d[v]...
output
1
871
14
1,743
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
872
14
1,744
Tags: dfs and similar, graphs, trees Correct Solution: ``` def find(i) : t = 0 while par[i] != 0 : i = par[i] t+=1 return (t) n = int(input()) t = 0 par = [0 for i in range (n+1)] d = {} for _ in range (1,n+1) : x = int(input()) if x != -1 : par[_] = x else : par...
output
1
872
14
1,745
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
873
14
1,746
Tags: dfs and similar, graphs, trees Correct Solution: ``` import sys import threading from collections import defaultdict n=int(input()) adj=defaultdict(list) for i in range(n): adj[int(input())].append(i+1) def fun(root,par,adj): ans=0 for ch in adj.get(root,[]): if ch != par: ...
output
1
873
14
1,747
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
874
14
1,748
Tags: dfs and similar, graphs, trees Correct Solution: ``` import math import sys p = [-1] * 5000 n = int(input()) f = -999999999 for i in range(0, n): x = int(input()) p[i + 1] = x for i in range(1, n + 1): y = i ans = 1 while(p[y] != -1): ans = ans + 1 y = p[y] f = max(f, ans) print(f) ```
output
1
874
14
1,749
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
875
14
1,750
Tags: dfs and similar, graphs, trees Correct Solution: ``` from collections import deque n = int(input()) g = [[] for i in range(n)] for i in range(n): finish = int(input()) - 1 if finish >= 0: g[i].append(finish) visited2 = [] def dfs(start): visited.append(start) for k in g[start]: ...
output
1
875
14
1,751
Provide tags and a correct Python 3 solution for this coding contest problem. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B i...
instruction
0
876
14
1,752
Tags: dfs and similar, graphs, trees Correct Solution: ``` n = int(input()) p=[int(input()) for i in range(n)] g=0 c=0 for i in range(n): c=0 while i>=0: i=p[i]-1 c+=1 g=max(g,c) print(g) ```
output
1
876
14
1,753
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
877
14
1,754
Yes
output
1
877
14
1,755
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
878
14
1,756
Yes
output
1
878
14
1,757
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
879
14
1,758
Yes
output
1
879
14
1,759
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
880
14
1,760
Yes
output
1
880
14
1,761
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
881
14
1,762
No
output
1
881
14
1,763
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
882
14
1,764
No
output
1
882
14
1,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
883
14
1,766
No
output
1
883
14
1,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is ...
instruction
0
884
14
1,768
No
output
1
884
14
1,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined ...
instruction
0
1,127
14
2,254
No
output
1
1,127
14
2,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined ...
instruction
0
1,128
14
2,256
No
output
1
1,128
14
2,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined ...
instruction
0
1,129
14
2,258
No
output
1
1,129
14
2,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The capital of Berland has the only movie theater in the country. Besides, it consists of only one room. The room is divided into n rows, each row consists of m seats. There are k people lined ...
instruction
0
1,130
14
2,260
No
output
1
1,130
14
2,261