message
stringlengths
2
30.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
237
109k
cluster
float64
10
10
__index_level_0__
int64
474
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar. Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating). Input The first line contains two integers n and m (2 ≀ n, m ≀ 100) β€” the number of employees and the number of languages. Then n lines follow β€” each employee's language list. At the beginning of the i-th line is integer ki (0 ≀ ki ≀ m) β€” the number of languages the i-th employee knows. Next, the i-th line contains ki integers β€” aij (1 ≀ aij ≀ m) β€” the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces. Output Print a single integer β€” the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating). Examples Input 5 5 1 2 2 2 3 2 3 4 2 4 5 1 5 Output 0 Input 8 7 0 3 1 2 3 1 1 2 5 4 2 6 7 1 3 2 7 4 1 1 Output 2 Input 2 2 1 2 0 Output 1 Note In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4. In the third sample employee 2 must learn language 2. Submitted Solution: ``` m,n = map(int,input().split()) adj = [[] for i in range(n)] vis = [0 for i in range(n)] mo = [[]] ans = 0 def dfs(x,tmp): vis[x] = 1 tmp += [x] flag = 0 for i in adj[x]: if(vis[i] == 0): flag = 1 dfs(i,tmp) if(flag == 0): mo[0] += [tmp] flag = 0 for i in range(m): l = list(map(int,input().split())) l = l[1:] if(l == [] and flag == 0): ans += 1 flag = 1 for i in l: for j in l: adj[i-1] += [j-1] adj[j-1] += [i-1] for i in range(n): if(vis[i] != 1 and adj[i]!=[]): dfs(i,[]) mo = mo[0] mo.sort() if(mo != []): ans +=1 for i in range(len(mo) - 1): if(mo[i][0] in mo[i+1]): continue ans += 1 print(ans-1) ```
instruction
0
33,677
10
67,354
No
output
1
33,677
10
67,355
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,066
10
68,132
"Correct Solution: ``` a,x,c=map(int,input().split()) k=x//a print(min(k,c)) ```
output
1
34,066
10
68,133
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,067
10
68,134
"Correct Solution: ``` a,b,c=map(int,input().split()) print(c if a*c<b else b//a) ```
output
1
34,067
10
68,135
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,068
10
68,136
"Correct Solution: ``` a, b, c = map(int, input().split()) print(min((b // a, c))) ```
output
1
34,068
10
68,137
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,069
10
68,138
"Correct Solution: ``` A,B,C=[int(i) for i in input().split()] print(min(int(B/A),C)) ```
output
1
34,069
10
68,139
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,070
10
68,140
"Correct Solution: ``` a,b,c=map(int, input().split()) print(c if (a*c) <= b else b//a ) ```
output
1
34,070
10
68,141
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,071
10
68,142
"Correct Solution: ``` a, b, c = list(map(int, input().split())) print(min(b // a, c)) ```
output
1
34,071
10
68,143
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,072
10
68,144
"Correct Solution: ``` a,b,c=map(int,input().split()) print(b//a if (b//a) <= c else c) ```
output
1
34,072
10
68,145
Provide a correct Python 3 solution for this coding contest problem. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0
instruction
0
34,073
10
68,146
"Correct Solution: ``` A, B, C = map(int, input().split(' ')) print(min(C, B // A)) ```
output
1
34,073
10
68,147
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` A, B, C = map(int, input().split()) print(min(C, int(B/A))) ```
instruction
0
34,074
10
68,148
Yes
output
1
34,074
10
68,149
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` a,b,c = map(int, input().split(' ' )) print(min(b//a, c)) ```
instruction
0
34,075
10
68,150
Yes
output
1
34,075
10
68,151
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` p = input().split() print(min(int(p[1]) // int(p[0]), int(p[2]))) ```
instruction
0
34,076
10
68,152
Yes
output
1
34,076
10
68,153
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` a,b,c=map(int,input().split()) d=b//a print([c,d][c>d]) ```
instruction
0
34,077
10
68,154
Yes
output
1
34,077
10
68,155
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` a, b, c = map(int, input().split()) n = int(b/a) print(n if b <= c else c) ```
instruction
0
34,078
10
68,156
No
output
1
34,078
10
68,157
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` A,B,K = map(int,input().split()) ans =[] for i in range(1,100): if (A % i)== 0 and (B % i) == 0: ans.append(i) ans_sort = ans[::-1] print(ans_sort[K-1]) ```
instruction
0
34,079
10
68,158
No
output
1
34,079
10
68,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` S=str(input()) l=list(S) # ['1', '2', '3'] ilength=len(l) bS=[1 for i in range(len(S))] recon=True while(recon): recon=False indeces=[] jump=False for i in range(len(l)-1): if(int(l[i])+int(l[i+1])==1 and not(jump)): indeces.append(i) indeces.append(i+1) i+=1 recon=True jump=True else: jump=False sl=[] for i in range(len(l)): if(not(i in indeces)): sl.append(l[i]) l=sl[:] flength=len(l) print(ilength-flength) ```
instruction
0
34,080
10
68,160
No
output
1
34,080
10
68,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Takahashi likes the sound when he buys a drink from a vending machine. That sound can be heard by spending A yen (the currency of Japan) each time. Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time. How many times will he hear the sound? Constraints * All values in input are integers. * 1 \leq A, B, C \leq 100 Input Input is given from Standard Input in the following format: A B C Output Print the number of times Takahashi will hear his favorite sound. Examples Input 2 11 4 Output 4 Input 3 9 5 Output 3 Input 100 1 10 Output 0 Submitted Solution: ``` class UnionFind(): def __init__(self, n): self.__parent = [i for i in range(n)] self.size = [1 for _ in range(n)] def union(self, x, y): pX, pY = self.find(x), self.find(y) if pX != pY: if pX < pY: self.__parent[pY] = pX self.size[pX] += self.size[pY] else: self.__parent[pX] = pY self.size[pY] += self.size[pX] def find(self, x): if self.__parent[x] != x: self.__parent[x] = self.find(self.__parent[x]) return self.__parent[x] N, M = map(int, input().split()) bridge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)] uf = UnionFind(N) num_disconnect = int(N*(N-1)/2) ans = [] for a, b in reversed(bridge): ans.append(num_disconnect) pA, pB = uf.find(a), uf.find(b) if pA != pB: num_disconnect -= uf.size[pA] * uf.size[pB] uf.union(a, b) for i in reversed(ans): print(i) ```
instruction
0
34,081
10
68,162
No
output
1
34,081
10
68,163
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,438
10
68,876
Tags: greedy, math Correct Solution: ``` t=int(input()) while(t>0): t-=1 n=int(input()) d=n//2 s=0 s+= (2**n) #print(s) for i in range(1,d): s+= (2**i) #print(s) s2=0 for i in range(d,n): s2+=(2**i) #print(s2) print(abs(s-s2)) ```
output
1
34,438
10
68,877
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,439
10
68,878
Tags: greedy, math Correct Solution: ``` t=int(input()) for i in range(0,t): n=int(input()) print((2**(n//2+1))-2) ```
output
1
34,439
10
68,879
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,440
10
68,880
Tags: greedy, math Correct Solution: ``` t = int(input()) for _ in range(t): n = int(input()) group1 = 0 group2 = 0 if n==2: print(2) else: for i in range(int(n/2)-1): group1 += 2**(i+1) group1 += 2**(n) for i in range(int(n/2)-1, n-1): group2 += 2**(i+1) print(group1 - group2) ```
output
1
34,440
10
68,881
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,441
10
68,882
Tags: greedy, math Correct Solution: ``` x=int(input()) for i in range(x): b=0 n=int(input()) b+=pow(2,n) for m in range(1,(n//2)): b+=pow(2,m) print(2*(b-pow(2,n)+1)) ```
output
1
34,441
10
68,883
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,442
10
68,884
Tags: greedy, math Correct Solution: ``` t = int(input()) vals = list(range(2, 56, 2)) for case in range(t): n = int(input()) # diff = 10 ** 9 # total = sum(2 ** x for x in vals) # for comb in combinations(vals, n // 2): # sum1 = sum(2 ** x for x in comb) # diff = min(abs(sum1 - (total - sum1)), diff) print((2 ** (vals.index(n) + 2)) - 2) ```
output
1
34,442
10
68,885
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,443
10
68,886
Tags: greedy, math Correct Solution: ``` import math import atexit import io import sys # input = sys.stdin.readline _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) def array_to_string(a): s = "" for i in a: s += str(i) + " " return s[0:len(s)-1] def gcd(a,b): if a == 0: return b return gcd(b % a, a) def lcm(a,b): return (a*b) / gcd(a,b) t = int(input()) while t>0: t = t-1 n = int(input()) a = [2**i for i in range(1,n+1)] s1 = 0 s2 = 0 half = n//2 s1 = sum(a[0:half-1]) + a[-1] s2 = sum(a)-s1 print(abs(s2-s1)) ```
output
1
34,443
10
68,887
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,444
10
68,888
Tags: greedy, math Correct Solution: ``` t=int(input()) for i in range(t): n=int(input()) if n==2: print(2) else: a=0 b=0 for j in range(1,n//2): a+=2**j a+=2**n for j in range(n//2,n): b+=2**j print(abs(a-b)) ```
output
1
34,444
10
68,889
Provide tags and a correct Python 3 solution for this coding contest problem. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6.
instruction
0
34,445
10
68,890
Tags: greedy, math Correct Solution: ``` j=2 p=2 q={} while(j<=30): q[j]=p p=p*2+2 j=j+2 for i in range(0,int(input())): n=int(input()) print(q[n]) ```
output
1
34,445
10
68,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` for i in range(int(input())): n=int(input()) x=[2**(i+1) for i in range(n)] a=x[:((n//2)-1)]+[x[-1]] b=x[((n//2)-1):n-1] print(abs(sum(a)-sum(b))) ```
instruction
0
34,446
10
68,892
Yes
output
1
34,446
10
68,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` output = [] for i in range(int(input())): n = int(input()) coins = [2**j for j in range(1,n+1)] output.append(coins[-1]+sum(coins[:n//2-1])-sum(coins[n//2-1:-1])) print(*output,sep="\n") ```
instruction
0
34,447
10
68,894
Yes
output
1
34,447
10
68,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` #!/usr/bin/python3 # Codeforces Round 638 # Author: Daniel Ruland # Problem A - Phoenix and Balance def read_int(): n = int(input()) return n def read_ints(): ints = [int(x) for x in input().split(" ")] return ints #--- def solve(n): p1 = [] p2 = [] for i in range(1, n+1): if i == n: p1.append(pow(2,i)) elif i < n//2: p1.append(pow(2,i)) else: p2.append(pow(2,i)) return sum(p1) - sum(p2) # Main t = read_int() for case in range(t): n = read_int() sol = solve(n) print (sol) ```
instruction
0
34,448
10
68,896
Yes
output
1
34,448
10
68,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) if(n%2!=0): print(2) elif(n==2): print(2) else: l = [] for i in range(1,n+1): l.append(pow(2,i)) i=2 index=1 s1=l[0]+l[-1] while(i<n//2): s1+=l[index] i+=1 index+=1 total = 2*(pow(2,n)-1) s2 = total-s1 print(abs(s1-s2)) ```
instruction
0
34,449
10
68,898
Yes
output
1
34,449
10
68,899
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) l = [2**j for j in range(1,n+1)] half = n//2 l1=[l[j] for j in range(half-1)] l1.append(l[n-1]) l.remove(l[n-1]) for j in range(half-1): l.remove(l[j]) print(sum(l1)-sum(l)) ```
instruction
0
34,450
10
68,900
No
output
1
34,450
10
68,901
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` from typing import Callable, Iterator, TypeVar, cast _F = TypeVar("_F", bound=Callable[[], None]) _I = TypeVar("_I", bound=Iterator[int]) def repeater(func: _F) -> _F: def wrapper(): for _ in range(int(input())): func() return cast(_F, wrapper) def get_num_input() -> _I: return map(int, input().split()) @repeater def main() -> None: print(2 ** (int(input()) + 1) - 2) if __name__ == "__main__": main() ```
instruction
0
34,451
10
68,902
No
output
1
34,451
10
68,903
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` from math import ceil def solve(): x , y = 0 , 0 cur = 0 n = int(input()) if(n == 2): print(2) return for i in range(1 , n // 2 + 1 , 1): if(cur == 0): x += 2 ** i x += 2 ** (n - i + 1) cur = 1 else: y += 2 ** (n - i + 1) y += 2 ** i cur = 0 if(n % 2 == 0): cur = 2 ** ceil(n / 2); cur += min(x , y) print(abs(x - y)) t = int(input()) for i in range(t): solve() ```
instruction
0
34,452
10
68,904
No
output
1
34,452
10
68,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Phoenix has n coins with weights 2^1, 2^2, ..., 2^n. He knows that n is even. He wants to split the coins into two piles such that each pile has exactly n/2 coins and the difference of weights between the two piles is minimized. Formally, let a denote the sum of weights in the first pile, and b denote the sum of weights in the second pile. Help Phoenix minimize |a-b|, the absolute value of a-b. Input The input consists of multiple test cases. The first line contains an integer t (1 ≀ t ≀ 100) β€” the number of test cases. The first line of each test case contains an integer n (2 ≀ n ≀ 30; n is even) β€” the number of coins that Phoenix has. Output For each test case, output one integer β€” the minimum possible difference of weights between the two piles. Example Input 2 2 4 Output 2 6 Note In the first test case, Phoenix has two coins with weights 2 and 4. No matter how he divides the coins, the difference will be 4-2=2. In the second test case, Phoenix has four coins of weight 2, 4, 8, and 16. It is optimal for Phoenix to place coins with weights 2 and 16 in one pile, and coins with weights 4 and 8 in another pile. The difference is (2+16)-(4+8)=6. Submitted Solution: ``` kup1=0 kup2=0 n=int(input()) for i in range(int(n/2)): a = int(input()) b=int(input()) if(kup1<=kup2): if(a>b): kup1+=a kup2+=b else: kup2 += a kup1 += b else: if (a > b): kup2 += a kup1 += b else: kup1 += a kup2 += b rezultat=kup2-kup1 print(abs(rezultat)) ```
instruction
0
34,453
10
68,906
No
output
1
34,453
10
68,907
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,814
10
69,628
Tags: implementation, math Correct Solution: ``` n,k=[int(x) for x in input().split(" ")] precios=[int(x) for x in input().split(" ")] resp=0 rem=precios[0]%k minimo=min(precios) for a in precios: if (a%k!=rem): resp=-1 break else: resp+=(a-minimo)//k print(resp) ```
output
1
34,814
10
69,629
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,815
10
69,630
Tags: implementation, math Correct Solution: ``` n, k = map(int, input().split()) a = sorted ( list(map(int, input().split()))) ans = 0 check = True for i in range(n): if (a[i]-a[0])%k != 0: check = False else: ans += int((a[i]-a[0])/k) if check: print(ans) else: print(-1) ```
output
1
34,815
10
69,631
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,816
10
69,632
Tags: implementation, math Correct Solution: ``` ###################################################1 import sys a, k = [int(i) for i in input().split()] in2 = [int(i) for i in input().split()] m = min(in2) in2.remove(m) res = 0 for r in in2: if (r - m)%k == 0: res += (r - m)//k else: print(-1) sys.exit(0) print(res) sys.exit(0) ###################################################1 ```
output
1
34,816
10
69,633
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,817
10
69,634
Tags: implementation, math Correct Solution: ``` # -*- coding: utf-8 -*- n,k = map(int,input().split(' ')) l = list(map(int, input().split(' '))) l.sort() min_ = l[0] c = 0 b = True for i in range(1,n): if (l[i]-min_)%k==0: c += (l[i]-min_)//k else: c = -1 break print(c) ```
output
1
34,817
10
69,635
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,818
10
69,636
Tags: implementation, math Correct Solution: ``` n,k = map(int,input().split(" ")) p = list(map(int,input().split(" "))) o = [] for x in p: o.append(x%k) ruzne = False x = o[0] for num in o: if num != x: ruzne = True if ruzne: print("-1") else: kroky = 0 mn = min(p) for i in range(n): kroky += (p[i] - mn) / k print(int(kroky)) ```
output
1
34,818
10
69,637
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,819
10
69,638
Tags: implementation, math Correct Solution: ``` import math n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() r=a[0]%k;t=0 for i in range(1,n): if a[i]%k!=r: print(-1) break else: t+=(a[i]-a[0])//k else: print(t) ```
output
1
34,819
10
69,639
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,820
10
69,640
Tags: implementation, math Correct Solution: ``` from math import floor a,b = map(int, input().split()) x = list(map(int, input().split())) mini = min(x) ar = list(map(lambda a: (a-mini)/b,x)) if len(list(filter(lambda a: floor(a)!=a,ar))) > 0: print(-1) else: print(int(sum(ar))) ```
output
1
34,820
10
69,641
Provide tags and a correct Python 3 solution for this coding contest problem. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
instruction
0
34,821
10
69,642
Tags: implementation, math Correct Solution: ``` n , k = map(int , input().split()) l = list(map(int, input().split())) minimum = min(l) ans = 0 for i in l: if (i-minimum)%k!=0: ans = -1 break else: ans = ans + (i-minimum)//k print(ans) ```
output
1
34,821
10
69,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n,k = map(int,input().split()) l = list(map(int,input().split())) p = min(l) sh = 0 for i in range(n): if (l[i]-p)%k!=0: sh = -1 break sh += (l[i]-p)//k print(sh) ```
instruction
0
34,822
10
69,644
Yes
output
1
34,822
10
69,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n, k = map(int, input().split()) a = tuple(map(int, input().split())) m = min(a) a = [(x - m) // k for x in a if (x - m) % k == 0] print(-1 if len(a) != n else sum(a)) ```
instruction
0
34,823
10
69,646
Yes
output
1
34,823
10
69,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` x=input().split(" ") N=int(x[0]) K=int(x[1]) mi=10**10 res=0 y=[int(a) for a in input().split(" ")] for i in range (len(y)): if y[i]<mi: mi=y[i] temp=y[0] y[0]=y[i] y[i]=temp for elem in y: temp=(elem-mi)%K if temp==0: res+=(elem-mi)//K else: res=-1 break print(res) ```
instruction
0
34,824
10
69,648
Yes
output
1
34,824
10
69,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n, k = map(int, input().split()) a = list(map(int,input().split())) minn = 10**9 + 1 for i in a: minn = min(minn,i) rs = 0 for i in a: if (i - minn)%k !=0: print(-1) exit() rs+= int((i-minn)/k) print(rs) ```
instruction
0
34,825
10
69,650
Yes
output
1
34,825
10
69,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n,k = list(map(int, input().split(" "))) x = list(map(int, input().split(" "))) if n==1: print(0) exit() for i in x: if i%k!=0: print(-1) exit() Min=min(x) print(sum((i-Min)//k for i in x)) ```
instruction
0
34,826
10
69,652
No
output
1
34,826
10
69,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n, k = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] if((sum(arr) - min(arr) * k) % n == 0): print( (sum(arr) - min(arr) * k) // n) else: print(-1) ```
instruction
0
34,827
10
69,654
No
output
1
34,827
10
69,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` nums = input().split(" ") n = int(nums[0]) k = int(nums[1]) prices = input().split(" ") pricesList = [] for i in range(0, len(prices)): pricesList.append(int(prices[i])) time = 1 possible = True for x in range(0, len(pricesList)): if pricesList[x] % k != 0: possible = False break pricesList.sort(reverse=True) for i in range(0, len(pricesList)): while pricesList[i] != pricesList[len(pricesList)-1]: pricesList[i] = pricesList[i] - k time+=1 if not possible: print(-1) else: print(time) ```
instruction
0
34,828
10
69,656
No
output
1
34,828
10
69,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input The first line contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109) β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the initial prices. Output Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Examples Input 3 3 12 9 15 Output 3 Input 2 2 10 9 Output -1 Input 4 1 1 1000000000 1000000000 1000000000 Output 2999999997 Note Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time. Submitted Solution: ``` n, k = input().split() n = int(n) k = int(k) a = list(map(int, input().split())) a.sort() l = [] i = 0 while i < n: l.append( -a[0] + a[i]) if (a[0] - a[i])%k != 0: print(-1) break i += 1 if i > 0 and len(l) >=1: print(sum(l)//k) ```
instruction
0
34,829
10
69,658
No
output
1
34,829
10
69,659
Provide tags and a correct Python 3 solution for this coding contest problem. A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets. The store does not sell single clothing items β€” instead, it sells suits of two types: * a suit of the first type consists of one tie and one jacket; * a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs e coins, and each suit of the second type costs f coins. Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused). Input The first line contains one integer a (1 ≀ a ≀ 100 000) β€” the number of ties. The second line contains one integer b (1 ≀ b ≀ 100 000) β€” the number of scarves. The third line contains one integer c (1 ≀ c ≀ 100 000) β€” the number of vests. The fourth line contains one integer d (1 ≀ d ≀ 100 000) β€” the number of jackets. The fifth line contains one integer e (1 ≀ e ≀ 1 000) β€” the cost of one suit of the first type. The sixth line contains one integer f (1 ≀ f ≀ 1 000) β€” the cost of one suit of the second type. Output Print one integer β€” the maximum total cost of some set of suits that can be composed from the delivered items. Examples Input 4 5 6 3 1 2 Output 6 Input 12 11 13 20 4 6 Output 102 Input 17 14 5 21 15 17 Output 325 Note It is possible to compose three suits of the second type in the first example, and their total cost will be 6. Since all jackets will be used, it's impossible to add anything to this set. The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is 9 β‹… 4 + 11 β‹… 6 = 102.
instruction
0
35,284
10
70,568
Tags: brute force, greedy, math Correct Solution: ``` from collections import Counter,deque,defaultdict,OrderedDict,namedtuple from bisect import bisect_left,bisect_right,insort from math import sqrt,ceil,floor,factorial,gcd from sys import stdin a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=int(input()) x=min(a,d) y=min(b,c,d-x) ans=x*e+y*f x=min(b,c,d) y=min(a,d-x) ans=max(ans,x*f+y*e) print(ans) ```
output
1
35,284
10
70,569