message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
42
109k
cluster
float64
5
5
__index_level_0__
int64
84
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` for _ in range(int(input())): a,b=map(int,input().split()) cnt2=0 temp=b temp1=a if b==1: b=2 ans = float("inf") for i in range(0,32): cnt1=0 while a!=0: a=a//b cnt1+=1 ans=min(ans,(cnt1+cnt2)) b += 1 a=temp1 cnt2+= 1 if cnt1>temp1: break if temp==1: print(ans+1) else: print(ans) ```
instruction
0
11,852
5
23,704
Yes
output
1
11,852
5
23,705
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` for t in range(int(input())): a,b = [int(x) for x in input().split()]; lst = []; bcount = 0 acopy = a bplus = b + 10 if a<b: print(1) elif a == b: print(2) else: while True: if b == bplus: break else: count = 0 if b == 1: b += 1 bcount += 1 a = acopy while True: if int(a) == 0: break else: a = a/b count += 1 b += 1 lst.append(count+bcount) bcount += 1 print(min(lst)) ```
instruction
0
11,853
5
23,706
Yes
output
1
11,853
5
23,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` def solve(a,b): res = 32 for i in range(0,6): if (b+i) == 1: continue c = 0 tmp = a while tmp > 0: c += 1 tmp = tmp // (b + i) res = min(res, i+c) return res no_of_lines = int(input()) while no_of_lines: no_of_lines -= 1 a,b = input().split(" ") print(solve(int(a),int(b))) ```
instruction
0
11,854
5
23,708
Yes
output
1
11,854
5
23,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` for i in range(int(input())): n,m=map(int,input().split()) p=[] for j in range(10): c=0 k=m+j c+=j o=n while(o>=1): if k==1 or k==o: k+=1 c+=1 else: o=o//k c+=1 p.append(c) print(min(p)) ```
instruction
0
11,855
5
23,710
Yes
output
1
11,855
5
23,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` def check(M): b1 = b + M b2 = b1 if b1 == 1: return 10 ** 18 ans = 1 while b1 <= a: b1 *= b2 ans += 1 return ans + M ans = [] for _ in range(int(input())): a, b = map(int, input().split()) L = 0 R = a + 1 while R - L > 2: M1 = L + (R - L) // 3 M2 = L + (R - L) // 3 * 2 if check(M1) < check(M2): R = M2 else: L = M1 ans.append(min(check(L), check((L + R) // 2), check(R))) print('\n'.join(map(str, ans))) ```
instruction
0
11,856
5
23,712
No
output
1
11,856
5
23,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` from math import ceil,floor,log import sys from heapq import heappush,heappop from collections import Counter,defaultdict,deque input=lambda : sys.stdin.readline().strip() c=lambda x: 10**9 if(x=="?") else int(x) class node: def __init__(self,x,y): self.a=[x,y] def __lt__(self,b): return b.a[0]<self.a[0] def __repr__(self): return str(self.a[0])+" "+str(self.a[1]) def main(): for _ in range(int(input())): a,b=map(int,input().split()) k=10**18 for i in range(1000): if(b+i==1): continue k=min(k,floor(log(a,b+i))+1+i) print(k) main() ```
instruction
0
11,857
5
23,714
No
output
1
11,857
5
23,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` import math t = int(input()) def truncate(n, decimals=0): multiplier = 10 ** decimals return int(n * multiplier) / multiplier for _ in range(t): a, b = map(int, input().split()) mn = 1000000 if b > a: print(1) continue for i in range(500): if b+i == 1: res = a+1 else: res = str(truncate(math.log(a)/math.log(b+i), 12)) if res[-1] == '9': res = int(round(float(res)))+1 else: res = int(float(res))+1 if res+i < mn: mn = res + i print(mn) ```
instruction
0
11,858
5
23,716
No
output
1
11,858
5
23,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b ⌋ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations required to make a=0. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. The only line of the description of each test case contains two integers a, b (1 ≤ a,b ≤ 10^9). Output For each test case, print a single integer: the minimum number of operations required to make a=0. Example Input 6 9 2 1337 1 1 1 50000000 4 991026972 997 1234 5678 Output 4 9 2 12 3 1 Note In the first test case, one of the optimal solutions is: 1. Divide a by b. After this operation a = 4 and b = 2. 2. Divide a by b. After this operation a = 2 and b = 2. 3. Increase b. After this operation a = 2 and b = 3. 4. Divide a by b. After this operation a = 0 and b = 3. Submitted Solution: ``` from math import * t=int(input()) for i in range(t): y=list(map(int,input().split())) a=y[0] b=y[1] lst=[] if a<b: print(1) elif a==b: print(2) else: for j in range(b,b+200): if j-a>2: break if j==1: lst.append(floor(log(a,j+1))+2) # print(floor(log(a,j+1))+2) else: lst.append(floor(log(a,j))+1+j-b) # print(floor(log(a,j))+1+j-b) lst.sort() print(lst[0]) ```
instruction
0
11,859
5
23,718
No
output
1
11,859
5
23,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>. Input The first line contains integer n (1 ≤ n ≤ 5·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| ≤ 109) — the elements of array a. Output Print a single integer — the number of ways to split the array into three parts with the same sum. Examples Input 5 1 2 3 0 3 Output 2 Input 4 0 1 -1 0 Output 1 Input 2 4 1 Output 0 Submitted Solution: ``` n=int(input()) a=[int(x) for x in input().split()] s=sum(a) if s%3!=0: print(0) else: s1=s/3;s2=2*s1 tick1=tick2=num=0 for i in range(n-1): tick2+=a[i] if tick2==s2: num+=tick1 if tick2==s1: tick1+=1 print(num) ```
instruction
0
12,018
5
24,036
Yes
output
1
12,018
5
24,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>. Input The first line contains integer n (1 ≤ n ≤ 5·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| ≤ 109) — the elements of array a. Output Print a single integer — the number of ways to split the array into three parts with the same sum. Examples Input 5 1 2 3 0 3 Output 2 Input 4 0 1 -1 0 Output 1 Input 2 4 1 Output 0 Submitted Solution: ``` n=int(input()) num=input() list=[int(x) for x in num.split()] tol=sum(list) s=0 t=0 w=0 if tol%3!=0: print(0) else: t3=int(tol/3) for i in range(n): s+=list[i] if s==t3: t=0 for j in range(i+1,n-1): t+=list[j] if t==t3: w+=0 print(w) ```
instruction
0
12,021
5
24,042
No
output
1
12,021
5
24,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>. Input The first line contains integer n (1 ≤ n ≤ 5·105), showing how many numbers are in the array. The second line contains n integers a[1], a[2], ..., a[n] (|a[i]| ≤ 109) — the elements of array a. Output Print a single integer — the number of ways to split the array into three parts with the same sum. Examples Input 5 1 2 3 0 3 Output 2 Input 4 0 1 -1 0 Output 1 Input 2 4 1 Output 0 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Fri Nov 20 17:44:41 2020 @author: 17831 """ n = int(input()) a = [int(x) for x in input().split()] b = int(sum(a)/3) def factorial(num): if num == 0 or num == 1: return 1 else: return (num*factorial(num-1)) if b != int(b): print(0) elif b == 0: q = 0 num = 0 for i in range(n): q+=a[i] if q == b or q == 2*b: num+=1 else: pass print(num) print(int(factorial(num-1)/(factorial(num-3)*2))) else: p = 0 first = 0 second = 0 third = 0 for i in range(n): p+=a[i] if p == b: first+=1 elif p == 2*b: second+=1 elif p == 3*b: third+=1 else: pass print(first*second*third) ```
instruction
0
12,024
5
24,048
No
output
1
12,024
5
24,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n,x=list(map(int,input().split())) xor = x if(n==1): print("YES") print(x) elif(n==2): if(x==0): print("NO") else: print("YES") print(0,x) else: print("YES") k=1 for u in range(n-2): while(xor^k==0): k+=1 xor=xor^k print(k,end=" ") k+=1 xor=xor^524287 print(524287,end=" ") print(xor) ```
instruction
0
12,219
5
24,438
Yes
output
1
12,219
5
24,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n, x = map(int, input().split()) if n == 1: print("Yes") print(x) elif n == 2: if x == 0: print("No") else: print("Yes") print(0, x) else: print("Yes") for i in range(n-3): print(i, end=' ') x ^= i print(1<<18, 1<<19, x^(1<<18)^(1<<19)) ```
instruction
0
12,220
5
24,440
Yes
output
1
12,220
5
24,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n,x=map(int,input().split()) if(n==1): print("YES") print(x) elif(n==2): if(x): print("YES") print(0,x) else:print('NO') else: print("YES") k=1 for _ in ' '*(n-2): while(x^k==0): k+=1 x=x^k print(k,end=" ") k+=1 x=x^524287 print(524287,x) ```
instruction
0
12,221
5
24,442
Yes
output
1
12,221
5
24,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` from functools import reduce n, x = list(map(int, input().split(' '))) if n == 1: print('YES') print(x) elif n == 2: if x == 0: print('NO') else: print('YES') print(0, x) elif n == 3: print('YES') if x == 0: print(1, 2, 3) else: print(0, (1 << 17), (1 << 17) ^ x) else: res = [] if x != 0: res += [x] n -= 1 i = 4 while n >= 3: if n == 3 or n == 6: res += [(0b11 << 17), (0b101 << 17), (0b110 << 17)] n -= 3 if n == 3: res += [(0b11 << 17) ^ 1, (0b101 << 17) ^ 2, (0b110 << 17) ^ 3] n -= 3 elif n == 5: #print('B', n) res += [(0b100 << 17) ^ i, (0b101 << 17) ^ i, (0b110 << 17) ^ i, (0b111 << 17) ^ i, 0] n -= 5 else: #print('A', n) res += [(0b100 << 17) ^ i, (0b101 << 17) ^ i, (0b110 << 17) ^ i, (0b111 << 17) ^ i] n -= 4 #print('C', n) i += 1 print('YES') print(' '.join(map(str, res))) #print(reduce(lambda a, b: a ^ b, res)) #print(len(set(res))) ```
instruction
0
12,222
5
24,444
Yes
output
1
12,222
5
24,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n, x = tuple(map(int, input().split())) # table n # --------- # | | # 19 | | # --------- def get_4_n_numbrs(n): a, b, c, d = 5, 10, 12, 3 res = [] for i in range(n): pref = "1{0:014b}".format(i) pref += '{0:04b}' res.append((pref.format(a))) res.append((pref.format(b))) res.append((pref.format(c))) res.append((pref.format(d))) return res def get_3_nums(x): if x not in [1, 2]: x = 1 ^ 2 ^ x return [1, 2, x] else: x = 8 ^ 4 ^ x return [8, 4, x] def get_4_nums(x): if x not in [1, 2, 4]: x = 1 ^ 2 ^ 4 ^ x return [1, 2, 4, x] else: x = 8 ^ 16 ^ 32 ^ x return [8,16,32, x] def get_2_nums(x): if x == 0: return [33, 3, 6, 12, 24, 48] else: return [0, x] # Нужно уметь находить четное число чисел которые дают 0 в xor # Начиная с четырех это риал. # Тогда в зависимости от кратности четырем. # Если остаток 1 то это то число которое хотели # Если два то то что хотели и ноль. # Нужно уметь исать 2 и 3 числа которые на хоре дают нужное # Это брутфорсится # # # def get_numbers(n, x): if n == 1: return [x] fours = (n - 1) // 4 res = [] left = n - (fours * 4) if left == 2 and x == 0: if n == 2: return -1 fours -= 1 res.extend([int(xx, 2) for xx in get_4_n_numbrs(fours)]) if left == 1: res.append(x) if left == 2: res.extend(get_2_nums(x)) if left == 3: res.extend(get_3_nums(x)) if left == 4: res.extend(get_4_nums(x)) return res res = get_numbers(n, x) if res != -1: print("YES") print(' '.join(map(str, get_numbers(n, x)))) else: print("NO") ```
instruction
0
12,223
5
24,446
No
output
1
12,223
5
24,447
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n,x = map(int,input().split()) # 2,0 => NO # 10**6 > 2**19 # 10**5 < 2**17 if n == 1: print('YES') print(x) elif n == 2: if x == 0: print('NO') else: print('YES') print(0,x) else: a = 1 << 19 c = a if x+3 < n: from itertools import chain for i in chain(range(1,x+1),range(x+2,n-1)): c ^= i it = chain(range(1,x+1),range(x+2,n-1)) else: for i in range(1,n-2): c ^= i it = range(1,n-2) d = x+1 e = x ^ c ^ d print('YES') if n == 3: print(a, d, e) else: print(a, ' '.join(map(str,it)), d, e) ```
instruction
0
12,224
5
24,448
No
output
1
12,224
5
24,449
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` def readints(): return [int(s) for s in input().strip().split()] def to_s(int_objs): return [str(obj) for obj in int_objs] class Solver: def main(self): n, x = readints() if n == 1: print('Yes\n{}'.format(x)) return if x == 0 and n == 2: print('No') return if n == 2: print('Yes\n{} {}'.format(0, x)) return results = [] searched = 0 for i in range(n - 3): results.append(i) searched = searched ^ i results.append((1 << 17) + searched) results.append((1 << 17) + (1 << 19)) results.append(1 << 19) print(' '.join(to_s(results))) Solver().main() ```
instruction
0
12,225
5
24,450
No
output
1
12,225
5
24,451
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets. Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106. Input The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively. Output If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. Examples Input 5 5 Output YES 1 2 4 5 7 Input 3 6 Output YES 1 2 5 Note You can read more about the bitwise-xor operation here: <https://en.wikipedia.org/wiki/Bitwise_operation#XOR> For the first sample <image>. For the second sample <image>. Submitted Solution: ``` n,x=map(int,input().split()) a=x A=[] for i in range(1,n): a^=i A.append(i) if a==0 or a>n-1: A.append(a) else: a=0 if x>n-1: A.pop(a-1) A.append(0) A.append(x) else: if x>a: A.pop(x-1) A.pop(a-1) else: A.pop(a-1) A.pop(x-1) A.append(500000) A.append(x^500000) A.append(0) print("YES") for i in A: print(i,end=' ') ```
instruction
0
12,226
5
24,452
No
output
1
12,226
5
24,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` N = int(input()) S = input() ans, gap = S.count('R') * S.count('G') * S.count('B'), 1 while gap * 2 + 1 <= N: ans -= sum([1 for i in range(N - gap * 2) if {'R', 'G', 'B'} == {S[i], S[i + gap], S[i + 2 * gap]}]) gap += 1 print(ans) ```
instruction
0
12,307
5
24,614
Yes
output
1
12,307
5
24,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` N = int(input()) S = input() ans = S.count('R') * S.count('G') * S.count('B') for i in range(N-1): for j in range(i+1, N): k = 2*j-i if k <= N-1 and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: ans -= 1 print(ans) ```
instruction
0
12,308
5
24,616
Yes
output
1
12,308
5
24,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` n=int(input()) a = input() c = 0 for i in range(1,n//2 +1): for j in range(n-2*i): if a[j] != a[j+i] and a[j+i] != a[j+2*i] and a[j] != a[j+2*i]: c+=1 ans = a.count("R") * a.count("G") * a.count("B") - c print(ans) ```
instruction
0
12,309
5
24,618
Yes
output
1
12,309
5
24,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` n = int(input()) s = list(input()) cnt = 0 cnt += s.count('R')*s.count('G')*s.count('B') for i in range(1,n-1): for j in range(1,min(i,n-i-1)+1): if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i+j]!=s[i-j]: cnt -= 1 print(cnt) ```
instruction
0
12,310
5
24,620
Yes
output
1
12,310
5
24,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` c =0 N = int(input())+1 S = tuple(input()) for i in range(1,N): for j in range(1,N): if i > j: continue elif S[i-1] == S[j-1]: continue for k in range(1,N): if j > k: continue elif S[i-1] == S[k-1]: continue elif S[j-1] == S[k-1]: continue elif j - i == k - j: continue else: c += 1 print(c) ```
instruction
0
12,312
5
24,624
No
output
1
12,312
5
24,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. Constraints * 1 \leq N \leq 4000 * S is a string of length N consisting of `R`, `G`, and `B`. Input Input is given from Standard Input in the following format: N S Output Print the number of triplets in question. Examples Input 4 RRGB Output 1 Input 39 RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB Output 1800 Submitted Solution: ``` N = int(input()) I = input() R = I.count('R') G = I.count('G') B = I.count('B') sum = R * G * B for i in range(N): for j in range(i+1,N): if I[i] != I[j]: k = j + j - i if k >= N: continue if I[i] != I[k] and I[j] != I[k]: sum -= 1 print(sum) ```
instruction
0
12,314
5
24,628
No
output
1
12,314
5
24,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. Examples Input 5 3 2 Output 2 4 1 5 3 Input 7 7 1 Output 1 2 3 4 5 6 7 Input 300000 300000 300000 Output -1 Submitted Solution: ``` r,p=range,print n,a,b=map(int,input().split()) if a+b>n+1or a*b<n:exit(p(-1)) l=[[]for i in r(b-1)]+[list(r(1,a+1))] for i in r(a+1,n+1):l[-2-(i-a-1)%(b-1)].append(i) for i in l:p(*i,end=" ") ```
instruction
0
12,357
5
24,714
Yes
output
1
12,357
5
24,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. Examples Input 5 3 2 Output 2 4 1 5 3 Input 7 7 1 Output 1 2 3 4 5 6 7 Input 300000 300000 300000 Output -1 Submitted Solution: ``` import sys N,A,B = map(int,input().split()) if A+B-1 > N or A*B < N: print (-1) sys.exit() ans = [] for i in range(N-A+1,N+1,1): ans.append(i) now = [] for i in range(1,N-A+1,1): now.append(i) if len(now) == B-1: now.reverse() for j in now: ans.append(j) now = [] now.reverse() for j in now: ans.append(j) print (" ".join(map(str,ans))) ```
instruction
0
12,359
5
24,718
Yes
output
1
12,359
5
24,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. Examples Input 5 3 2 Output 2 4 1 5 3 Input 7 7 1 Output 1 2 3 4 5 6 7 Input 300000 300000 300000 Output -1 Submitted Solution: ``` N,A,B = map(int,input().split()) if A+B-1>N or N>A*B: print(-1) else: G = {i:[] for i in range(1,A+1)} i = A cnt = 0 cur = N while cur>A: G[i].append(cur) cnt += 1 cur -= 1 if cnt==B-1: cnt = 0 i -= 1 C = [] for i in range(1,A+1): C += G[i] C.append(i) print(*C) ```
instruction
0
12,360
5
24,720
Yes
output
1
12,360
5
24,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. Examples Input 5 3 2 Output 2 4 1 5 3 Input 7 7 1 Output 1 2 3 4 5 6 7 Input 300000 300000 300000 Output -1 Submitted Solution: ``` # -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 N, A, B = MAP() remain = N - A if remain < B - 1: print(-1) exit() d = ceil(remain, B-1) if B > 1 else 0 li = [[] for i in range(B)] li[0] = list(range(1, A+1)) j = A + 1 for i in range(1, B): tmp = [] for _ in range(d): tmp.append(j) j += 1 if j > N: break li[i] = tmp li = li[::-1] ans = [] for grp in li: ans += grp print(*ans) ```
instruction
0
12,362
5
24,724
No
output
1
12,362
5
24,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence. Constraints * 1 \leq N,A,B \leq 3\times 10^5 * All input values are integers. Input Input is given from Standard Input in the following format: N A B Output If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. Examples Input 5 3 2 Output 2 4 1 5 3 Input 7 7 1 Output 1 2 3 4 5 6 7 Input 300000 300000 300000 Output -1 Submitted Solution: ``` n,a,b = map(int,input().split()) if not (a+b-1 <= n <= a*b): print(-1) exit() k = a*b - n ans = [x + (b-1)*10**6 for x in range(a)] for i in range(b-2,-1,-1): t = min(a-1,k) ans += [x+i*10**6 for x in range(a)][:-t] k -= t dic = {x:str(i+1) for i,x in enumerate(sorted(ans))} print(" ".join(list(map(lambda x:dic[x],ans)))) ```
instruction
0
12,363
5
24,726
No
output
1
12,363
5
24,727
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,390
5
24,780
"Correct Solution: ``` import sys import math r = sys.stdin.readlines() n = [[float(i) for i in (j.split())] for j in r] for l in n: y = (l[2]*l[3]-l[0]*l[5])/(l[1]*l[3]-l[0]*l[4])+0 x = (l[2]*l[4]-l[5]*l[1])/(l[0]*l[4]-l[3]*l[1])+0 print("%.3f %.3f" %(x, y)) ```
output
1
12,390
5
24,781
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,391
5
24,782
"Correct Solution: ``` import sys inputNum = sys.stdin.readlines() for i in inputNum: new = [] n = i[:-1].split(' ', 6) for s in n: new.append(float(s)) k = new[0] q = 0 for a in new[0:3]: new[q] = a/k q = q + 1 l = new[3] for a in new[3:6]: new[q] = a - l*new[q-3] q = q + 1 if new[4] == 0: y = new[5] else: y = new[5]/new[4] x = new[2]-(new[1]*y) print("{0:.3f}".format(x)+" "+"{0:.3f}".format(y)) ```
output
1
12,391
5
24,783
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,392
5
24,784
"Correct Solution: ``` # input inputs = [] while True: try: inputs.append(list(map(float,input().split()))) except EOFError: break # calculation for i in inputs: x=(i[2]*i[4]-i[1]*i[5])/(i[0]*i[4]-i[1]*i[3]) y=(i[0]*i[5]-i[2]*i[3])/(i[0]*i[4]-i[1]*i[3]) if x == -0.000:x=0 if y == -0.000:y=0 print("{0:.3f} {1:.3f}".format(x,y)) ```
output
1
12,392
5
24,785
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,393
5
24,786
"Correct Solution: ``` while True: try: a, b, c, d, e, f = map(float, input().split()) x = (c*e - b*f)/(a*e - b*d) y = (f*a - c*d)/(a*e - d*b) print( "{0:.3f} {1:.3f}".format(x+0, y+0)) except: break ```
output
1
12,393
5
24,787
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,394
5
24,788
"Correct Solution: ``` import sys for line in sys.stdin.readlines(): a, b, c, d, e, f=map(float,line.split()) k=(a*e)-(b*d) xval=(c*e)-(b*f) yval=(a*f)-(c*d) g=xval/k h=yval/k if(xval==0): g=0 if(yval==0): h=0 print("%.3f %.3f"%(g,h)) ```
output
1
12,394
5
24,789
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,395
5
24,790
"Correct Solution: ``` while True: try: (a, b, e, c, d, f) = map(float, input().split()) D = a * d - b * c x = (d * e - b * f) / D y = (a * f - c * e) / D if abs(x) < 1e-4: x = 0.0 if abs(y) < 1e-4: y = 0.0 print("{0:.3f} {1:.3f}".format(x, y)) except EOFError: break ```
output
1
12,395
5
24,791
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,396
5
24,792
"Correct Solution: ``` while True: try: a, b, c, d, e, f = map(int, input(). split()) D = (a * e) - (b * d) x = (e * c) - (b * f) y = (a * f) - (d * c) x /= D y /= D if x / D == 0: x = 0 if y / D == 0: y = 0 print("%.3f %.3f" % (round(x, 3), round(y, 3))) except: break ```
output
1
12,396
5
24,793
Provide a correct Python 3 solution for this coding contest problem. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000
instruction
0
12,397
5
24,794
"Correct Solution: ``` while True: try: a, b, c, d, e, f = [float(x) for x in input().split()] except: exit() m = [[a,b,c],[d,e,f]] row = len(m) col = len(m[0]) for k in range(row): for j in range(k+1,col): m[k][j] /=m[k][k] for i in range(row): if(i != k): for j in range(k+1,col): m[i][j] -= m[i][k] * m[k][j] print ("%.3f %.3f" % (m[0][2],m[1][2])) ```
output
1
12,397
5
24,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution. Input The input consists of several data sets, 1 line for each data set. In a data set, there will be a, b, c, d, e, f separated by a single space. The input terminates with EOF. Output For each data set, print x and y separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places. Examples Input 1 2 3 4 5 6 2 -1 -2 -1 -1 -5 Output -1.000 2.000 1.000 4.000 Input 2 -1 -3 1 -1 -3 2 -1 -3 -9 9 27 Output 0.000 3.000 0.000 3.000 Submitted Solution: ``` try: while 1: a,b,c,d,e,f = list(map(int,input().split())) y = (c * d - f * a) / (d * b - a * e) x = (c - b * y) / a print("{:.3f} {:.3f}".format(x, y)) except Exception: pass ```
instruction
0
12,400
5
24,800
Yes
output
1
12,400
5
24,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i. Input The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — array a. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case output the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i. Example Input 4 6 3 5 1 4 6 6 3 1 2 3 4 1 3 3 4 6 1 6 3 4 5 6 Output 1 3 3 10 Submitted Solution: ``` t=int(input()) for i in range(t): n=int(input()) s=0 m=0 mn=100000000 arr=list(map(int, input().split())) for j in range(n): arr[j]=arr[j]-j m=max(m, arr[j]) mn=min(mn, arr[j]) kol=[0]*(m+1+abs(mn)) #print(arr) for j in range(n): kol[arr[j]+abs(mn)]+=1 #print(kol) for j in range(m+1+abs(mn)): s+=(kol[j]*(kol[j]-1))/2 print(int(s)) ```
instruction
0
12,709
5
25,418
Yes
output
1
12,709
5
25,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a of n integers. Count the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i. Input The first line contains one integer t (1 ≤ t ≤ 10^4). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5). The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — array a. It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5. Output For each test case output the number of pairs of indices (i, j) such that i < j and a_j - a_i = j - i. Example Input 4 6 3 5 1 4 6 6 3 1 2 3 4 1 3 3 4 6 1 6 3 4 5 6 Output 1 3 3 10 Submitted Solution: ``` from collections import defaultdict, Counter from bisect import bisect, bisect_left from math import sqrt, gcd def read(): return list(map(int, input().strip().split())) ans_ = [] for _ in range(int(input())): n = int(input()); arr = read() c = 0 for i in range(n): arr[i] -= i+1 c += [0, 1][arr[i] == 0] ans_.append((c*(c-1))//2) # print(ans_) for i in ans_: print(i) """ 1 1 2 1 2 3 4 3 1 2 3 4 5 6 7 8 9 1 3 5 4 6 """ ```
instruction
0
12,712
5
25,424
No
output
1
12,712
5
25,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0. Write the program which finds the number of points in the intersection of two given sets. Input The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive. Output Print the number of points in the intersection or -1 if there are infinite number of points. Examples Input 1 1 0 2 2 0 Output -1 Input 1 1 0 2 -2 0 Output 1 Submitted Solution: ``` a1,b1,c1 = map(int, input().split()) a2,b2,c1 = map(int, input().split()) if a2*b1 == a1*b2: print(1) else: print(-1) ```
instruction
0
12,744
5
25,488
No
output
1
12,744
5
25,489
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,767
5
25,534
Tags: brute force, data structures Correct Solution: ``` # import itertools # import bisect # import math from collections import defaultdict, Counter import os import sys from io import BytesIO, IOBase # sys.setrecursionlimit(10 ** 5) ii = lambda: int(input()) lmii = lambda: list(map(int, input().split())) slmii = lambda: sorted(map(int, input().split())) li = lambda: list(input()) mii = lambda: map(int, input().split()) msi = lambda: map(str, input().split()) def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return (a * b) // gcd(a, b) def main(): # for _ in " " * int(input()): n, m = mii() a = lmii() fac = [1, 1] for i in range(10 ** 5): fac.append((fac[-1] + fac[-2] % 10 ** 9)) for i in range(m): lst = lmii() if lst[0] == 1: a[lst[1] - 1] = lst[2] elif lst[0] == 2: s = 0 for j in range(lst[2] - lst[1] + 1): s += ((fac[j] * a[lst[1] - 1 + j]) % 10 ** 9) print(s % 10 ** 9) else: for j in range(lst[1], lst[2] + 1): a[j - 1] += lst[3] BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main() ```
output
1
12,767
5
25,535
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,768
5
25,536
Tags: brute force, data structures Correct Solution: ``` from sys import * from math import * mod = 1000000000 f = [0 for i in range(200)] f[0] = f[1] = 1 for i in range(2, 200): f[i] = f[i - 1] + f[i - 2] n, m = stdin.readline().split() n = int(n) m = int(m) a = list(map(int, stdin.readline().split())) for i in range(m): tp, x, y = stdin.readline().split() tp = int(tp) x = int(x) y = int(y) if tp == 1: x -= 1 a[x] = y else: s = 0 x -= 1 y -= 1 for p in range(y - x + 1): s += f[p] * a[x + p] print(s % mod) ```
output
1
12,768
5
25,537
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,769
5
25,538
Tags: brute force, data structures Correct Solution: ``` n,m = map(int,input().split()) a = list(map(int,input().split())) f = [1,1] for i in range(2,n+1): f.append(f[i-1] + f[i-2]) for q in range(m): z,l,r = map(int,input().split()) if z == 1: a[l-1] = r else: s = 0 for j in range(l-1,r): s += (a[j] * f[j-l+1]) s %= 10 ** 9 print(s) ```
output
1
12,769
5
25,539
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,770
5
25,540
Tags: brute force, data structures Correct Solution: ``` n,m = map(int,input().split()) d = [int(x) for x in input().split()] f = [1,1] for i in range(n): f.append((f[-1]+f[-2])% 1000000000) for i in range(m): s = [int(x) for x in input().split()] if s[0] == 1: x = s[1]-1 v = s[2] d[x] = v elif s[0] == 2: r = s[2]-1 l = s[1]-1 ans = 0 for i in range(r-l+1): #print("(",f[i],d[i+l],ans,")") ans = (ans % 10**9 + d[i+l]% 10**9 * f[i] % 10**9)% 10**9 print(ans) elif s[0] == 3: r = s[2]-1 l = s[1]-1 x = s[3] for i in range(l,r+1): d[i] += x ```
output
1
12,770
5
25,541
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,771
5
25,542
Tags: brute force, data structures Correct Solution: ``` n,m = map(int, input().split()) a = list(map(int, input().split())) f = [1]*n for i in range(2,n): f[i] = f[i-1]+f[i-2] for i in range(m): t,l,r = map(int, input().split()) if t==1: a[l-1] = r else: sum_lr = 0 for x in range(r-l+1): sum_lr += f[x] * a[l+x-1] print(sum_lr%1000000000) ```
output
1
12,771
5
25,543
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,772
5
25,544
Tags: brute force, data structures Correct Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): t, l, r = map(int, input().split()) if t == 1: a[l-1] = r else: s = 0 fiba = fibb = 1 for i in range(l-1, r): s += fiba * a[i] fiba, fibb = fibb, fiba + fibb print(s % 1000000000) ```
output
1
12,772
5
25,545
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,773
5
25,546
Tags: brute force, data structures Correct Solution: ``` mod = 10**9 FibArray = [1,1] def fibonacci(n): if n<=len(FibArray): return FibArray[n-1] else: temp_fib = fibonacci(n-1)+fibonacci(n-2) FibArray.append(temp_fib) return temp_fib n, m = map(int, input().split()) a = list(map(int, input().split())) for _ in range(m): query = list(map(int, input().split())) if query[0]==1: a[query[1]-1] = query[2] elif query[0]==3: d = query[3] for i in range(query[1]-1, query[2]): a[i]+=d else: l, r = query[1], query[2] s = 0 for x in range(r-l+1): # print(fibonacci(x+1), a[l+x-1]) s+=((fibonacci(x+1)*a[l+x-1])) print(s%mod) ```
output
1
12,773
5
25,547
Provide tags and a correct Python 3 solution for this coding contest problem. By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher: You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type: 1. For given numbers xi and vi assign value vi to element axi. 2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2. 3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri). Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type: * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105); * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n); * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105). The input limits for scoring 30 points are (subproblem E1): * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type. The input limits for scoring 70 points are (subproblems E1+E2): * It is guaranteed that there will be queries of the 1-st and 2-nd type only. The input limits for scoring 100 points are (subproblems E1+E2+E3): * No extra limitations. Output For each query print the calculated sum modulo 1000000000 (109). Examples Input 5 5 1 3 1 2 4 2 1 4 2 1 5 2 2 4 1 3 10 2 1 5 Output 12 32 8 50 Input 5 4 1 3 1 2 4 3 1 4 1 2 2 4 1 2 10 2 1 5 Output 12 45
instruction
0
12,774
5
25,548
Tags: brute force, data structures Correct Solution: ``` import sys f = [-1] * 200000 def fib(n): if f[n] == -1: k = n//2 while k > 0 and f[k] == -1: k = k/2 for i in range(k, n): f[i+1] = f[i] + f[i-1]; return f[n] def solve(numbers, t, l, r, d): if t == 1: numbers[l-1] = r elif t == 2: total = 0 for j in range(l-1, r): total = (total + numbers[j] * fib(j-l+1)) % (10**9) print(total) else: for j in range(l-1, r): numbers[j] = numbers[j] + d n, m = sys.stdin.readline().rstrip().split() n = int(n) m = int(m) numbers = list(map(lambda x: int (x), sys.stdin.readline().rstrip().split())) f[0] = f[1] = 1 for i in range(m): line = sys.stdin.readline().rstrip().split() t = int(line[0]) d = 0 if t == 1: l = int(line[1]) r = int(line[2]) elif t == 2: l = int(line[1]) r = int(line[2]) else: l = int(line[1]) r = int(line[2]) d = int(line[3]) solve(numbers, t, l, r, d) ```
output
1
12,774
5
25,549