message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
We all know that GukiZ often plays with arrays.
Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: <image>? Here operation <image> means bit... | instruction | 0 | 59,256 | 12 | 118,512 |
Tags: combinatorics, implementation, math, matrices, number theory
Correct Solution:
```
"""
Codeforces Contest 307 Div 2 Problem D
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def multiply(M1, M2):
if len(M1[0]) != len(M2): raise ValueError
a ... | output | 1 | 59,256 | 12 | 118,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,834 | 12 | 119,668 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
# Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): re... | output | 1 | 59,834 | 12 | 119,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,835 | 12 | 119,670 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
nei = []
default = 0
for x, y in zip(a, a[1:]):
if x==-1 and y!=-1:
nei.append(y)
if x!=-1 and y==-1:
ne... | output | 1 | 59,835 | 12 | 119,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,836 | 12 | 119,672 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
def print(*vals):
sys.stdout.write(" ".join(map(str,vals)) + '\n')
def max_diff(integers,k,n):
max_diff = 0
for i in range(n-1):
if integers[i] == -1 and integers[i+1] != -1:
ma... | output | 1 | 59,836 | 12 | 119,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,837 | 12 | 119,674 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
l, h = 1000010000, -1
for i in range(n):
if a[i] >= 0:
if (i and a[i - 1] < 0) or (i + 1 < n and a[i + 1] < 0):
l = min... | output | 1 | 59,837 | 12 | 119,675 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,838 | 12 | 119,676 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
t = int(input())
while t > 0:
n = int(input())
a = [int(ele) for ele in input().split()]
b = set([])
for i in range(n):
if a[i] == -1:
if i == 0:
if a[i+1] != -1:
b.add(a[i+1])
... | output | 1 | 59,838 | 12 | 119,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,839 | 12 | 119,678 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
#1301B
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(len(a)):
if a[i] == -1:
if i > 0 and a[i-1] != -1:
ans.append(a[i-1])
if i < n-1 and a[i+1] != -1:
ans.append(a[i+1])
i... | output | 1 | 59,839 | 12 | 119,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,840 | 12 | 119,680 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
def calc(val,lista):
mx=0
for i in range(1,len(lista)):
x,y=lista[i],lista[i-1]
if x==-1:
x=val
if y==-1:
y=val
mx=max(mx,abs(x-y))
return(mx)
for _ in range(int(input())):
n=int(inp... | output | 1 | 59,840 | 12 | 119,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some elements in that array disappeared. Dark knows... | instruction | 0 | 59,841 | 12 | 119,682 |
Tags: binary search, greedy, ternary search
Correct Solution:
```
num_t = int(input())
for _ in range(num_t):
input()
arr = [int(i) for i in input().split()]
min_p = float('inf')
max_p = float('-inf')
found = False
for i in range(len(arr)):
if arr[i] == -1 and i - 1 >= 0 and arr[i ... | output | 1 | 59,841 | 12 | 119,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,842 | 12 | 119,684 |
Yes | output | 1 | 59,842 | 12 | 119,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,843 | 12 | 119,686 |
Yes | output | 1 | 59,843 | 12 | 119,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,844 | 12 | 119,688 |
Yes | output | 1 | 59,844 | 12 | 119,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,845 | 12 | 119,690 |
Yes | output | 1 | 59,845 | 12 | 119,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,846 | 12 | 119,692 |
No | output | 1 | 59,846 | 12 | 119,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,847 | 12 | 119,694 |
No | output | 1 | 59,847 | 12 | 119,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,848 | 12 | 119,696 |
No | output | 1 | 59,848 | 12 | 119,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array a of n non-negative integers.
Dark created that array 1000 years ago, so some... | instruction | 0 | 59,849 | 12 | 119,698 |
No | output | 1 | 59,849 | 12 | 119,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,850 | 12 | 119,700 |
Tags: greedy, implementation
Correct Solution:
```
for _ in range(int(input())):
num=int(input())
li=[int(i) for i in input().split()]
print(len(set(li)))
``` | output | 1 | 59,850 | 12 | 119,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,851 | 12 | 119,702 |
Tags: greedy, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
k = inp()
for i in range(k):
count = 0
n = inp()
l = inlt()
print(len(list(set(l))))
``` | output | 1 | 59,851 | 12 | 119,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,852 | 12 | 119,704 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
while t:
n = int(input())
a = list(map(int , input().split()))
print(len(set(a)))
t = t - 1
``` | output | 1 | 59,852 | 12 | 119,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,853 | 12 | 119,706 |
Tags: greedy, implementation
Correct Solution:
```
from sys import stdin
inf=stdin
for qw in range(int(inf.readline())):
n=int(inf.readline())
arr=list(map(int,inf.readline().split(" ")))
print(len(set(arr)))
#n=int(inf.readline())
#s=inf.readline()
# s="bacabcab"
# changed=False
# while not changed:
# print(s)
... | output | 1 | 59,853 | 12 | 119,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,854 | 12 | 119,708 |
Tags: greedy, implementation
Correct Solution:
```
t=int(input())
for i in range(t):
n=int(input())
l=[int(s) for s in input().split()]
print(len(set(l)))
``` | output | 1 | 59,854 | 12 | 119,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,855 | 12 | 119,710 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for i in range (0, t):
n = int(input())
a = list(map(int, input().split()))
print(len(set(a)))
``` | output | 1 | 59,855 | 12 | 119,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,856 | 12 | 119,712 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ans = len(set(a))
print(ans)
``` | output | 1 | 59,856 | 12 | 119,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence a is a su... | instruction | 0 | 59,857 | 12 | 119,714 |
Tags: greedy, implementation
Correct Solution:
```
import sys
t=int(sys.stdin.readline().strip())
for i in range(0,t):
len1=int(sys.stdin.readline().strip())
array=list(map(int,sys.stdin.readline().strip().split()))
print(len(set(array)))
``` | output | 1 | 59,857 | 12 | 119,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,858 | 12 | 119,716 |
Yes | output | 1 | 59,858 | 12 | 119,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,859 | 12 | 119,718 |
Yes | output | 1 | 59,859 | 12 | 119,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,860 | 12 | 119,720 |
Yes | output | 1 | 59,860 | 12 | 119,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,861 | 12 | 119,722 |
Yes | output | 1 | 59,861 | 12 | 119,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,862 | 12 | 119,724 |
No | output | 1 | 59,862 | 12 | 119,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,863 | 12 | 119,726 |
No | output | 1 | 59,863 | 12 | 119,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,864 | 12 | 119,728 |
No | output | 1 | 59,864 | 12 | 119,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array's longes... | instruction | 0 | 59,865 | 12 | 119,730 |
No | output | 1 | 59,865 | 12 | 119,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,900 | 12 | 119,800 |
Tags: constructive algorithms
Correct Solution:
```
def proA(n,arr,arr2,arr3):
temp=[]
for i in range(n):
for j in [arr,arr2,arr3]:
if(len(temp)==n-1 and temp[0]==j[i]):
continue
if(temp!=[]):
if(temp[-1]==j[i]):
... | output | 1 | 59,900 | 12 | 119,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,901 | 12 | 119,802 |
Tags: constructive algorithms
Correct Solution:
```
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists... | output | 1 | 59,901 | 12 | 119,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,902 | 12 | 119,804 |
Tags: constructive algorithms
Correct Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
# biesect_left is essentially an equivalent of lower_bound function in
# cpp and returns the first index not smaller than x.
from bisect import bisect_left;
from bisect import bisect_right;
from math import ce... | output | 1 | 59,902 | 12 | 119,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,903 | 12 | 119,806 |
Tags: constructive algorithms
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
res=[]
last = -1
for i in range(n):
if i==n-1:
if A[i] !=last and A[i]!=int(... | output | 1 | 59,903 | 12 | 119,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,904 | 12 | 119,808 |
Tags: constructive algorithms
Correct Solution:
```
from collections import *
from itertools import *
from bisect import *
def inp():
return int(input())
def arrinp():
return [int(x) for x in input().split()]
def main():
t = inp()
for _ in range(t):
n = inp()
A = arrinp()
B = a... | output | 1 | 59,904 | 12 | 119,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,905 | 12 | 119,810 |
Tags: constructive algorithms
Correct Solution:
```
T = int(input())
for t in range(T):
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
R = []
for i in range(N):
if i == 0:
R.append(A[i])
... | output | 1 | 59,905 | 12 | 119,811 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,906 | 12 | 119,812 |
Tags: constructive algorithms
Correct Solution:
```
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1408",questionID = "A",method = "GET")>.h>
"""
Author : thekushalghosh
Team : CodeDiggers
I prefer Python language over the C++ language :p :D
Visit my websi... | output | 1 | 59,906 | 12 | 119,813 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three sequences: a_1, a_2, β¦, a_n; b_1, b_2, β¦, b_n; c_1, c_2, β¦, c_n.
For each i, a_i β b_i, a_i β c_i, b_i β c_i.
Find a sequence p_1, p_2, β¦, p_n, that satisfy the following conditions:
* p_i β \\{a_i, b_i, c_i\}
* p_... | instruction | 0 | 59,907 | 12 | 119,814 |
Tags: constructive algorithms
Correct Solution:
```
def func(a, b, c):
p = [i for i in a]
lenp = len(p)
for i in range(lenp-1):
next = (i + 1) % lenp
# print("now and next", i, next)
if p[i] == p[next]:
if p[i] != b[next]:
p[next] = b[next]
els... | output | 1 | 59,907 | 12 | 119,815 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element nu... | instruction | 0 | 60,034 | 12 | 120,068 |
Tags: combinatorics, math, number theory
Correct Solution:
```
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
p=10**9+7
n,k=m... | output | 1 | 60,034 | 12 | 120,069 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element nu... | instruction | 0 | 60,035 | 12 | 120,070 |
Tags: combinatorics, math, number theory
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def main():
mod = 10**9+7
n,k = map(int,input().split())
a = list(map(int,input().split()))
coeff = [1]
for i in range(n):
... | output | 1 | 60,035 | 12 | 120,071 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element nu... | instruction | 0 | 60,036 | 12 | 120,072 |
Tags: combinatorics, math, number theory
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = 1000000007
r = [ 0, 1 ]
for i in range(2, n+1):
r.append( (- (m // i) * r[m % i]) % m )
c = [ 1 ]
for i in range(1, n):
c.append((c[i-1] * (k+i-1) * r[i]) % m)
ans = []
for ... | output | 1 | 60,036 | 12 | 120,073 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of partial sums, consisting of n elements. Element nu... | instruction | 0 | 60,037 | 12 | 120,074 |
Tags: combinatorics, math, number theory
Correct Solution:
```
n, k = map(int, input().split())
num = list(map(int, input().split()))
MOD = 10 ** 9 + 7
cf = [1]
for i in range(1, 2020):
cf.append((cf[-1] * (k + i - 1) * pow(i, MOD - 2, MOD)) % MOD)
ans = [0 for i in range(n)]
for i in range(n):
for j in range... | output | 1 | 60,037 | 12 | 120,075 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
1. First we build by the array a an array s of par... | instruction | 0 | 60,038 | 12 | 120,076 |
No | output | 1 | 60,038 | 12 | 120,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 β€ i β€ j β€ n.
Input
The first line contains one integer n (1 β€ n β€ 200000) β ... | instruction | 0 | 60,348 | 12 | 120,696 |
Tags: data structures, math
Correct Solution:
```
def update(fenwick, idx, val, n):
while idx<n:
fenwick[idx]+=val
idx+=(idx & (-idx))
def get_sum(fenwick, idx):
sum=0
while idx>0:
sum+=fenwick[idx]
idx-=(idx & (-idx))
return sum
def count_smaller_elements(arr):
tem... | output | 1 | 60,348 | 12 | 120,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 β€ i β€ j β€ n.
Input
The first line contains one integer n (1 β€ n β€ 200000) β ... | instruction | 0 | 60,349 | 12 | 120,698 |
Tags: data structures, math
Correct Solution:
```
maxN = 2 * 10**5
n = int(input())
bad = 0
ghabl = 0
a = list(map(int, input().split()))
for i in range(n):
if (i):
bad += a[i] - a[0]
Sum = bad
for i in range(1, n):
bad -= (a[i] - a[i - 1])
bad -= ((n - 1) - i) * (a[i] - a[i - 1])
Sum += bad
maP... | output | 1 | 60,349 | 12 | 120,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 β€ i β€ j β€ n.
Input
The first line contains one integer n (1 β€ n β€ 200000) β ... | instruction | 0 | 60,350 | 12 | 120,700 |
Tags: data structures, math
Correct Solution:
```
n = int(input())
t = input().split()
x = {int(i): 0 for i in t}
result = 0
for i in range(1, n + 1):
a = int(t[i - 1])
x[a] += 1
result += a * (2 * i - n - 1)
if a + 1 in x:
result += x[a + 1]
if a - 1 in x:
result -= x[a - 1]
print(... | output | 1 | 60,350 | 12 | 120,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote a function
<image>
You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 β€ i β€ j β€ n.
Input
The first line contains one integer n (1 β€ n β€ 200000) β ... | instruction | 0 | 60,351 | 12 | 120,702 |
Tags: data structures, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
p = [0] * (n+1)
for i in range(n) :
p[i+1] = p[i] + a[i]
mp = dict()
cnt = 0
for i in range(n) :
f1 = mp.setdefault(a[i])
f2 = mp.setdefault(a[i] - 1)
f3 = mp.setdefault(a[i] + 1)
if (f1 == Non... | output | 1 | 60,351 | 12 | 120,703 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.