message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.
Input
The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.
Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.
Output
Output an integer k (0 ≤ k ≤ 5) — the length of your program.
Next k lines must contain commands in the same format as in the input.
Examples
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
Note
You can read about bitwise operations in <https://en.wikipedia.org/wiki/Bitwise_operation>.
Second sample:
Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
Submitted Solution:
```
'''input
3
& 1
& 3
& 5
'''
'''
Author : dhanyaabhirami
Great things never come from comfort zones
'''
from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
import math
mod=pow(10,9) +7
def inp(flag=0):
if flag==0:
return list(map(int,input().strip().split(' ')))
else:
return int(input())
# Code credits
# assert(debug()==true)
# for _ in range(int(input())):
# n=inp(1)
n=int(input())
a=0
b=1023
for i in range(n):
c,k= input().strip().split(' ')
k=int(k)
if (c=='|'):
a|=k
b|=k
elif (c=='^'):
a^=k
b^=k
elif (c=='&'):
a&=k
b&=k
OR = 0
XOR = 0
for i in range(10):
x=1<<i
if a&x and b&x:
XOR|=x
OR|=x
if ~a&x and b&x:
XOR|=x
if ~a&x and ~b&x:
OR|=x
print('2')
print('|',OR)
print('^',XOR)
``` | instruction | 0 | 99,190 | 20 | 198,380 |
No | output | 1 | 99,190 | 20 | 198,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.
Input
The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.
Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.
Output
Output an integer k (0 ≤ k ≤ 5) — the length of your program.
Next k lines must contain commands in the same format as in the input.
Examples
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
Note
You can read about bitwise operations in <https://en.wikipedia.org/wiki/Bitwise_operation>.
Second sample:
Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
Submitted Solution:
```
## necessary imports
import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;
def ceil(x):
if x != int(x):
x = int(x) + 1;
return x;
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
## gcd function
def gcd(a,b):
if b == 0:
return a;
return gcd(b, a % b);
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if(k > n - k):
k = n - k;
res = 1;
for i in range(k):
res = res * (n - i);
res = res / (i + 1);
return int(res);
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0 and n > 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0 and n > 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b;
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
ret = {};
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1;
x = x//spf[x]
return ret;
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()));
def float_array():
return list(map(float, input().strip().split()));
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
n = int(input());
ops = [];
for _ in range(n):
s = input().strip().split();
ops.append((s[0], int(s[1])));
if n <= 5:
print(n);
for i in range(n):
print(ops[i][0] + ' ' + str(ops[i][1]));
exit();
x = ops[1][1];
for i in range(2, n):
c = ops[i][0];
if c == '|':
x = x | ops[i][1];
elif c == '&':
x = x & ops[i][1];
else:
x = x ^ ops[i][1];
print(2);
print(ops[0][0] + ' ' + str(ops[0][1]));
print(ops[1][0] + ' ' + str(x));
``` | instruction | 0 | 99,191 | 20 | 198,382 |
No | output | 1 | 99,191 | 20 | 198,383 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,361 | 20 | 198,722 |
"Correct Solution:
```
#!/usr/bin/env python3
seven_seg = {
0: '0111111',
1: '0000110',
2: '1011011',
3: '1001111',
4: '1100110',
5: '1101101',
6: '1111101',
7: '0100111',
8: '1111111',
9: '1101111'
}
while True:
seven_seg_state = ['0'] * 7
n = int(input())
if n == -1:
break
for _ in range(n):
in_data = int(input())
for i in range(7):
if seven_seg[in_data][i] == seven_seg_state[i]:
print("0", end="")
else:
print("1", end="")
seven_seg_state[i] = seven_seg[in_data][i]
print()
``` | output | 1 | 99,361 | 20 | 198,723 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,362 | 20 | 198,724 |
"Correct Solution:
```
NUM = (
0b0111111,
0b0000110,
0b1011011,
0b1001111,
0b1100110,
0b1101101,
0b1111101,
0b0100111,
0b1111111,
0b1101111,
)
while 1:
n = int(input())
if n == -1:break
current = 0
for i in range(n):
num = NUM[int(input())]
print(format(current ^ num,'b').zfill(7))
current = num
``` | output | 1 | 99,362 | 20 | 198,725 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,363 | 20 | 198,726 |
"Correct Solution:
```
dic = {0:"0111111", 1:"0000110", 2:"1011011", 3:"1001111", 4:"1100110",
5:"1101101", 6:"1111101", 7:"0100111", 8:"1111111", 9:"1101111"}
while True:
n = int(input())
if n == -1:
break
dig = "0" * 7
for _ in range(n):
d = dic[int(input())]
put = ""
for i in range(7):
if dig[i] != d[i]:
put += "1"
else:
put += "0"
print(put)
dig = d
``` | output | 1 | 99,363 | 20 | 198,727 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,364 | 20 | 198,728 |
"Correct Solution:
```
Num_seg = [[0,1,1,1,1,1,1],[0,0,0,0,1,1,0],[1,0,1,1,0,1,1],[1,0,0,1,1,1,1],[1,1,0,0,1,1,0],[1,1,0,1,1,0,1],[1,1,1,1,1,0,1],[0,1,0,0,1,1,1],[1,1,1,1,1,1,1],[1,1,0,1,1,1,1]]
while True:
n = int(input())
if n == -1:
break
num_b = int(input())
seg = ""
for h in range(7):
seg = seg + str(Num_seg[num_b][h])
print(seg)
for i in range(n - 1):
num_a = int(input())
seg = ""
for j in range(7):
if Num_seg[num_b][j] == Num_seg[num_a][j]:
seg = seg + "0"
else:
seg = seg + "1"
num_b = num_a
print(seg)
``` | output | 1 | 99,364 | 20 | 198,729 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,365 | 20 | 198,730 |
"Correct Solution:
```
s=[0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0100111,0b1111111,0b1101111]
while 1:
n=int(input())
if n<0:break
a=0
for _ in range(n):
b=int(input())
print(bin(a^s[b])[2:].zfill(7))
a=s[b]
``` | output | 1 | 99,365 | 20 | 198,731 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,366 | 20 | 198,732 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0228
"""
import sys
from sys import stdin
input = stdin.readline
LED_pattern = [
##-gfedcba
0b0111111, # 0
0b0000110, # 1
0b1011011, # 2
0b1001111, # 3
0b1100110, # 4
0b1101101, # 5
0b1111101, # 6
0b0100111, # 7
0b1111111, # 8
0b1101111, # 9
0b0000000 # all OFF
]
def solve(cp, np):
a = LED_pattern[cp]
b = LED_pattern[np]
return bin(a ^ b)[2:].zfill(7)
def main(args):
while True:
n = int(input())
if n == -1:
break
cp = 10 # all OFF
for _ in range(n):
d = int(input())
ans = solve(cp, d)
cp = d
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 99,366 | 20 | 198,733 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,367 | 20 | 198,734 |
"Correct Solution:
```
nums = ["0111111", "0000110", "1011011", "1001111", "1100110",
"1101101", "1111101", "0100111", "1111111", "1101111"]
while 1:
n = int(input())
if n == -1:
break
sig = "0000000"
for _ in range(n):
d = int(input())
num = nums[d]
out = ""
for s, n in zip(sig, num):
if s == n:
out += "0"
else:
out += "1"
print(out)
sig = num
``` | output | 1 | 99,367 | 20 | 198,735 |
Provide a correct Python 3 solution for this coding contest problem.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111 | instruction | 0 | 99,368 | 20 | 198,736 |
"Correct Solution:
```
import sys
f = sys.stdin
segment =[0b0111111,
0b0000110,
0b1011011,
0b1001111,
0b1100110,
0b1101101,
0b1111101,
0b0100111,
0b1111111,
0b1101111]
while True:
n = int(f.readline())
if n == -1:
break
display = 0
for i in [int(f.readline()) for _ in range(n)]:
print(bin(display ^ segment[i])[2:].zfill(7))
display = segment[i]
``` | output | 1 | 99,368 | 20 | 198,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111
Submitted Solution:
```
seg = [[0, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 1, 1, 0],
[1, 0, 1, 1, 0, 1, 1],
[1, 0, 0, 1, 1, 1, 1],
[1, 1, 0, 0, 1, 1, 0],
[1, 1, 0, 1, 1, 0, 1],
[1, 1, 1, 1, 1, 0, 1],
[0, 1, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 0, 1, 1, 1, 1]]
while True :
n = int(input())
if n == -1 :
break
pre = [0]*7
for i in range(n) :
num = int(input())
post = seg[num]
for j in range(7) :
if pre[j] == post[j] :
print(0, end='')
else :
print(1, end='')
print()
pre = post
``` | instruction | 0 | 99,369 | 20 | 198,738 |
Yes | output | 1 | 99,369 | 20 | 198,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111
Submitted Solution:
```
# AOJ 0228: Seven Segments
# Python3 2018.6.25 bal4u
p = [[1,1,1,1,1,1,0], [0,1,1,0,0,0,0], [1,1,0,1,1,0,1], [1,1,1,1,0,0,1], [0,1,1,0,0,1,1], \
[1,0,1,1,0,1,1], [1,0,1,1,1,1,1], [1,1,1,0,0,1,0], [1,1,1,1,1,1,1], [1,1,1,1,0,1,1]]
while True:
n = int(input())
if n < 0: break
a = [0]*7
for i in range(n):
d = int(input())
ans = ''
for j in range(6,-1,-1):
k = (a[j] ^ p[d][j]) & 1
ans += '1' if k else '0'
if k: a[j] = 1-a[j]
print(ans)
``` | instruction | 0 | 99,370 | 20 | 198,740 |
Yes | output | 1 | 99,370 | 20 | 198,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111
Submitted Solution:
```
# Aizu Problem 0228: Seven Segments
import sys, math, os, bisect
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
digits = [63, 6, 91, 79, 102, 109, 125, 39, 127, 111]
while True:
n = int(input())
if n == -1:
break
e = 0
for i in range(n):
a = digits[int(input())]
print("{:07b}".format(a^e))
e = a
``` | instruction | 0 | 99,371 | 20 | 198,742 |
Yes | output | 1 | 99,371 | 20 | 198,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments).
The new product to be launched by Wakamatsu will incorporate a 7-segment display into the product, and as an employee, you will create a program to display the given number on the 7-segment display.
This 7-segment display will not change until the next switch instruction is sent. By sending a signal consisting of 7 bits, the display information of each corresponding segment can be switched. Bits have a value of 1 or 0, where 1 stands for "switch" and 0 stands for "as is".
The correspondence between each bit and segment is shown in the figure below. The signal sends 7 bits in the order of "gfedcba". For example, in order to display "0" from the hidden state, "0111111" must be sent to the display as a signal. To change from "0" to "5", send "1010010". If you want to change "5" to "1" in succession, send "1101011".
<image>
Create a program that takes n (1 ≤ n ≤ 100) numbers that you want to display and outputs the signal sequence required to correctly display those numbers di (0 ≤ di ≤ 9) on the 7-segment display. please. It is assumed that the initial state of the 7-segment display is all hidden.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. Each dataset is given in the following format:
n
d1
d2
::
dn
The number of datasets does not exceed 120.
Output
For each input dataset, output the sequence of signals needed to properly output the numbers to the display.
Example
Input
3
0
5
1
1
0
-1
Output
0111111
1010010
1101011
0111111
Submitted Solution:
```
#!/usr/bin/env python3
seven_seg = {
0: '0111111',
1: '0000110',
2: '1011011',
3: '1001111',
4: '1100110',
5: '1101101',
6: '1111101',
7: '0100111',
8: '1111111',
9: '1101111'
}
while True:
seven_seg_state = ['0'] * 7
n = int(input())
if n == -1:
break
for _ in range(n):
in_data = int(input())
for i, s in enumerate(seven_seg_state):
if seven_seg[in_data][i] == s:
print("0", end="")
else:
print("1", end="")
s = seven_seg[in_data][i]
print()
``` | instruction | 0 | 99,372 | 20 | 198,744 |
No | output | 1 | 99,372 | 20 | 198,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,663 | 20 | 199,326 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import sys,math
r=sys.stdin.readline
for _ in range(int(r())):
n,k=map(int,r().split())
lst=list(map(int,r().split()))
st=set(lst)
if k in st:
print("YES")
continue
lst.sort()
g=0
for i in range(len(lst)):
g=math.gcd(g,lst[i]-lst[0])
if (k-lst[0])%g==0:
print("YES")
else:
print("NO")
``` | output | 1 | 99,663 | 20 | 199,327 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,665 | 20 | 199,330 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from math import gcd
def solve(n,k,x):
if k in x:
return 'YES'
y = x[1]-x[0]
for i in range(1,n):
y = gcd(y,x[i]-x[0])
if (k-x[0])%y:
return 'NO'
else:
return 'YES'
def main():
for _ in range(int(input())):
n,k = map(int,input().split())
x = list(map(int,input().split()))
print(solve(n,k,x))
#Fast IO Region
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 | 99,665 | 20 | 199,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,666 | 20 | 199,332 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
from math import gcd
import sys
input = sys.stdin.buffer.readline
def prog():
for _ in range(int(input())):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
d = 0
for i in range(n-1):
d = gcd(d,a[i+1]-a[i])
print("YES" if (k - a[0])%d == 0 else "NO")
prog()
``` | output | 1 | 99,666 | 20 | 199,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,667 | 20 | 199,334 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import sys
input = sys.stdin.readline
from math import gcd
t=int(input())
for tests in range(t):
n,k=map(int,input().split())
X=list(map(int,input().split()))
G=0
for i in range(1,n):
G=gcd(G,X[i]-X[i-1])
#print(G)
if k%G==X[0]%G:
print("YES")
else:
print("NO")
``` | output | 1 | 99,667 | 20 | 199,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,668 | 20 | 199,336 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
"""
#If FastIO not needed, use this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
self.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")
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
#start_time = time.time()
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
def getMat(n):
return [getInts() for _ in range(n)]
def isInt(s):
return '0' <= s[0] <= '9'
MOD = 10**9 + 7
"""
If the diffs have GCD 1, we definitely can reach
"""
def solve():
N, K = getInts()
A = getInts()
A.sort()
G = A[1]-A[0]
for i in range(1,N-1):
G = math.gcd(G,A[i+1]-A[i])
if G == 1: return "YES"
for i in range(N):
if (A[i] - K) % G == 0: return "YES"
return "NO"
for _ in range(getInt()):
print(solve())
#solve()
#print(time.time()-start_time)
``` | output | 1 | 99,668 | 20 | 199,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
n distinct integers x_1,x_2,…,x_n are written on the board. Nezzar can perform the following operation multiple times.
* Select two integers x,y (not necessarily distinct) on the board, and write down 2x-y. Note that you don't remove selected numbers.
Now, Nezzar wonders if it is possible to have his favorite number k on the board after applying above operation multiple times.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The first line of each test case contains two integers n,k (2 ≤ n ≤ 2 ⋅ 10^5, -10^{18} ≤ k ≤ 10^{18}).
The second line of each test case contains n distinct integers x_1,x_2,…,x_n (-10^{18} ≤ x_i ≤ 10^{18}).
It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.
Output
For each test case, print "YES" on a single line if it is possible to have k on the board. Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
2 1
1 2
3 0
2 3 7
2 -1
31415926 27182818
2 1000000000000000000
1 1000000000000000000
2 -1000000000000000000
-1000000000000000000 123
6 80
-5 -20 13 -14 -2 -11
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, the number 1 is already on the board.
In the second test case, Nezzar could perform the following operations to write down k=0 on the board:
* Select x=3 and y=2 and write down 4 on the board.
* Select x=4 and y=7 and write down 1 on the board.
* Select x=1 and y=2 and write down 0 on the board.
In the third test case, it is impossible to have the number k = -1 on the board. | instruction | 0 | 99,669 | 20 | 199,338 |
Tags: constructive algorithms, math, number theory
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
def __init__(self, file):
self.newlines = 0
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()
# --------------------------------------------------------------------
def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def S(): return input().strip()
def print_list(l): print(' '.join(map(str, l)))
# sys.setrecursionlimit(200000)
# import random
from functools import reduce
# from functools import lru_cache
# from heapq import *
# from collections import deque as dq
import math
# import bisect as bs
# from collections import Counter
# from collections import defaultdict as dc
for _ in range(N()):
_, k = RL()
a = RLL()
print('YES' if (k - a[0]) % reduce(math.gcd, [v - a[0] for v in a[1:]]) == 0 else 'NO')
``` | output | 1 | 99,669 | 20 | 199,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | instruction | 0 | 99,777 | 20 | 199,554 |
Tags: bitmasks, constructive algorithms
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
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")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def ctd(chr): return ord(chr)-ord("a")
mod = 998244353
INF = float('inf')
# ------------------------------
def main():
for _ in range(N()):
l, r = RL()
bl = int(r).bit_length()
res = 0
for i in range(bl-1, -1, -1):
nb = 1<<i
if l&nb==r&nb:
if l&nb==nb: res+=nb
else:
res+=(1<<i)-1
if '0' not in bin(r)[-i-1:]: res+=1<<i
break
print(res)
if __name__ == "__main__":
main()
``` | output | 1 | 99,777 | 20 | 199,555 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | instruction | 0 | 99,780 | 20 | 199,560 |
Tags: bitmasks, constructive algorithms
Correct Solution:
```
for i in range(int(input())):
l,r=map(int,input().split())
L=list(bin(l))
R=list(bin(r))
L=L[2:]
R=R[2:]
w=0
c=0
L=['0']*(len(R)-len(L))+L
#print(L,R)
ans=0
if l==r:
print(l)
continue
for i in range(len(R)):
if L[i]!=R[i]:
for j in range(i+1,len(R)):
if(R[j]=='0'):
w=1
if w==1:
ans=c+(2**(len(R)-i-1))-1
# print(ans)
break
else:
ans=c+(2**(len(R)-i))-1
break
elif L[i]=='1':
c=c+(2**(len(R)-i-1))
print(ans)
``` | output | 1 | 99,780 | 20 | 199,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | instruction | 0 | 99,781 | 20 | 199,562 |
Tags: bitmasks, constructive algorithms
Correct Solution:
```
n=int(input())
for k in range(n):
l,r=map(int,input().split())
a=[]
for i in range(62):
a.append('0')
lbin=list(bin(l))
lbin=lbin[2:]
ans=l
num=l
for i in range(len(lbin)):
a[61-i]=lbin[len(lbin)-1-i]
blah=0
for i in range(61,-1,-1):
if(a[i]=='0'):
a[i]='1'
num=num+2**(61-i)
if(num<=r):
ans=num
else:
break
print(ans)
``` | output | 1 | 99,781 | 20 | 199,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | instruction | 0 | 99,782 | 20 | 199,564 |
Tags: bitmasks, constructive algorithms
Correct Solution:
```
from sys import stdin
def parseline(line):
return list(map(int, line.split()))
def round_to_power_of_2(k):
k |= k >> 1
k |= k >> 2
k |= k >> 4
k |= k >> 8
k |= k >> 16
k += 1
return k
def is_power_of_2(k):
return 0 == k & (k-1)
if __name__ == "__main__":
lines = list(filter(None, stdin.read().split('\n')))
lines = list(map(parseline, lines))
n, = lines[0]
for li, ri in lines[1:n+1]:
z = round_to_power_of_2((li ^ ri))
mask = z - 1
if is_power_of_2((ri & mask) + 1):
print(ri)
else:
pos = z >> 1
print((ri ^ pos ) | (pos - 1))
``` | output | 1 | 99,782 | 20 | 199,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102 | instruction | 0 | 99,784 | 20 | 199,568 |
Tags: bitmasks, constructive algorithms
Correct Solution:
```
import sys
def binary(a):
s = ""
for i in range(64):
if(a%2 == 0):
s += "0"
else:
s += "1"
a //= 2
return s
def dec(s):
resp = 0;
for k in s:
resp *= 2
if(k == '1'):
resp += 1
return resp
def solve(a, b):
x = binary(a)
y = binary(b)
resp = 0
gen = ""
for i in range(len(x)-1, -1, -1):
if(x[i] == y[i]):
gen += x[i]
else:
ones = True
for j in range(i, -1, -1):
if(y[j] == '0'):
ones = False
break
if(ones):
gen += "1"
else:
gen += "0"
for j in range(i-1, -1, -1):
gen += "1"
break
# print(x, y, gen)
return dec(gen)
casos = int(input())
for i in range(casos):
line = input()
v = [int(x) for x in line.split()]
print(solve(v[0], v[1]))
``` | output | 1 | 99,784 | 20 | 199,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,792 | 20 | 199,584 |
Tags: dp, greedy, implementation
Correct Solution:
```
toInt = lambda x : int(''.join(map(str,x[-1::-1])))
import sys
#sys.stdin=open('note.txt')
pre=0
ans=[0]*1000
sum=0
for n in range(int(input())):
sum=int(input())
d=sum-pre
pre=sum
if d>0:
for i,dig in enumerate(ans):
if d+dig<=9:
ans[i]=dig+d
break
d-=9-dig
ans[i]=9
print(toInt(ans))
else: #d is minus
d=-d+1
d2=0
for i, dig in enumerate(ans):
d2+=dig
ans[i]=0
if ans[i+1]<9 and d2>=d:
break
ans[i+1]+=1
d2-=d
cnt = d2//9
ans[:cnt]=[9]*cnt
ans[cnt]=d2 % 9
print(toInt(ans))
``` | output | 1 | 99,792 | 20 | 199,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,793 | 20 | 199,586 |
Tags: dp, greedy, implementation
Correct Solution:
```
def get_digit(number,n):
return int((number // 10**n)/10),number // 10**n % 10
def last_k(new_sum_to_make,k):
last_sum = 0
for i in range(k+1):
#print(new_sum_to_make,k)
if new_sum_to_make > 9:
new_sum_to_make = new_sum_to_make - 9
last_sum = 9 * (10**i) + last_sum
else:
new_num = new_sum_to_make
last_sum = new_num * (10**i) + last_sum
break
return last_sum
n = int(input())
prev_num = 0
prev_sum = 0
for i in range(n):
new_sum = int(input())
prev_num_str = str(prev_num)
l_prev_num_str = len(prev_num_str)
k = 0
curr_digit_sum = 0
found = False
digit_index = l_prev_num_str - 1
while found == False:
#prev_digit,curr_digit = get_digit(prev_num,k)
if digit_index > 0:
curr_digit = int(prev_num_str[digit_index])
prev_digit = int(prev_num_str[0:digit_index])
elif digit_index == 0:
curr_digit = int(prev_num_str[digit_index])
prev_digit = 0
else:
curr_digit = 0
prev_digit = 0
digit_index = digit_index - 1
curr_digit_sum = curr_digit_sum + curr_digit
prev_digit_sum = prev_sum - curr_digit_sum
if prev_digit_sum > new_sum:
k = k + 1
else:
sum_to_make = new_sum - prev_digit_sum
#print(prev_digit,curr_digit,curr_digit_sum,prev_digit_sum,new_sum,prev_sum)
new_curr_digit = curr_digit + 1
while new_curr_digit != 10 and found == False:
new_sum_to_make = sum_to_make - new_curr_digit
if new_sum_to_make >= 0 and new_sum_to_make <= 9*k:
#print(new_curr_digit,new_sum_to_make,k)
last_k_digit = last_k(new_sum_to_make,k)
#print(last_k_digit)
last_k_digit = new_curr_digit *(10**k) + last_k_digit
#first_digits = prev_digit * 10 + new_curr_digit
#print(first_digits)
first_digits = prev_digit * (10**(k+1)) + last_k_digit
print(first_digits)
found = True
break
new_curr_digit = new_curr_digit + 1
if new_curr_digit == 10:
k = k + 1
else:
prev_num = first_digits
prev_sum = new_sum
break
``` | output | 1 | 99,793 | 20 | 199,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,794 | 20 | 199,588 |
Tags: dp, greedy, implementation
Correct Solution:
```
# written with help of editorial
def get_smallest(dig_sum):
ret = str(dig_sum % 9) + '9' * (dig_sum // 9)
return int(ret)
def f(n):
ret = 0
while n:
ret += n % 10
n //= 10
return ret
def nx(n):
s = str(n)
sm = 0
for i in range(len(s) - 1, -1, -1):
if s[i] < '9' and sm > 0:
return int(s[:i] + str(int(s[i]) + 1) + \
str(get_smallest(sm - 1)).zfill(len(s) - i - 1))
sm += int(s[i])
return int('1' + str(get_smallest(sm - 1)).zfill(len(s)))
def after(d, low):
s = '0' * 600 + str(low)
n = len(s)
has = f(low)
for i in range(n - 1, -1, -1):
has -= int(s[i])
for x in range(int(s[i]) + 1, 10):
if s[i] < '9' and has + x <= d <= has + x + 9 * (n - i - 1):
if i == n - 1:
return int(s[:i] + str(x))
return int(s[:i] + str(x) + \
str(get_smallest(d - has - x)).zfill(n - i - 1))
n = int(input())
low = 0
for i in range(n):
ds = int(input())
cur = after(ds, low)
print(cur)
low = cur
``` | output | 1 | 99,794 | 20 | 199,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,795 | 20 | 199,590 |
Tags: dp, greedy, implementation
Correct Solution:
```
__author__ = 'PrimuS'
n = int(input())
b = [0] * n
for i in range(n):
b[i] = int(input())
last = 0
import math
def build_smallest(csum, length):
if math.ceil(csum / 9) == length:
f = csum % 9
if f == 0:
f = 9
return int(str(f) + "9" * (length-1))
csum -= 1
s = ""
while csum > 0:
s = str(min(csum, 9)) + s
csum -= min(csum, 9)
return int("1" + "0" * (length - 1 - len(s)) + s)
def build_greater(csum, x):
x = [int(y) for y in x]
last_possible = -1
i = len(x) - 1
while i >= 0:
if x[i] < 9:
last_possible = i
break
i -= 1
if last_possible == -1:
return 0
if x[0] >= csum:
return 0
last_avail = -1
ac_sum = 0
for i in range(len(x)):
ac_sum += x[i]
if ac_sum >= csum:
last_avail = i - 1
break
if last_avail == -1:
last_avail = len(x) - 1
pos = last_avail
while pos >= 0:
if x[pos] < 9:
break
pos -= 1
if pos == -1:
return 0
res = list(x)
res[pos] += 1
for i in range(pos+1):
csum -= res[i]
i = len(res) - 1
while i > pos:
res[i] = min(9, csum)
csum -= res[i]
i -= 1
if csum > 0:
i = len(res) - 1
while i >= 0:
if res[i] < 9:
u = min(csum, 9 - res[i])
res[i] = res[i] + u
csum -= u
i -= 1
if csum > 0:
return 0
res2 = 0
for y in res:
res2 = res2 * 10 + y
return res2
for i in range(n):
bx = b[i]
cur = bx % 9
bx -= cur
while bx > 0:
cur = cur * 10 + 9
bx -= 9
if cur <= last:
cur = build_greater(b[i], str(last))
if cur <= last:
cur = build_smallest(b[i], len(str(last)) + 1)
print(cur)
last = cur
``` | output | 1 | 99,795 | 20 | 199,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,796 | 20 | 199,592 |
Tags: dp, greedy, implementation
Correct Solution:
```
def fill9(x,u):
k=x//9
for i in range(k):
u[i]=9
if x%9:
u[k]=x%9
return k+1
else:
return k
n=input()
n=int(n)
u=[0 for i in range(300//9*150+150)]
k=1
for i in range(n):
x=input()
x=int(x)
t=k-1
while t>=0:
if u[t]+9*t<x:
t=fill9(x,u)
if t>k:
k=t
break
elif u[t]>=x:
t+=1
u[t]+=1
x-=1
while u[t]==10:
u[t]=0
t+=1
u[t]+=1
x+=9
if t+1>k:
k=t+1
for t in range(fill9(x,u),t):
u[t]=0
break
else:
x-=u[t]
t-=1
v=[str(j) for j in u[k-1:-len(u)-1:-1]]
print(''.join(v))
``` | output | 1 | 99,796 | 20 | 199,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,797 | 20 | 199,594 |
Tags: dp, greedy, implementation
Correct Solution:
```
def naive(S, n):
arr = [0] * n
for i in range(n):
plus = min(S, 9)
arr[i] += plus
S -= plus
return arr
def less_than(pre_arr, pre_S, cur_S):
S = pre_S - cur_S
n = len(pre_arr)
cur_arr = [0] * n
for i in range(n):
sub = min(S, pre_arr[i])
cur_arr[i] = pre_arr[i] - sub
S -= sub
ind = 0
for x in cur_arr:
if x>0:
break
ind+=1
for j in range(ind+1, n):
if cur_arr[j] < 9:
cur_arr[ind] -= 1
cur_arr[j] += 1
return sorted(cur_arr[:j], reverse=True) + cur_arr[j:]
return naive(cur_S-1, n) + [1]
def remain_plus(pre_arr, pre_S, cur_S):
S = cur_S - pre_S
n = len(pre_arr)
cur_arr = [0] * n
for i in range(n):
add = min(S, 9 - pre_arr[i])
cur_arr[i] = pre_arr[i] + add
S -= add
return cur_arr
n = int(input())
a = [int(input()) for _ in range(n)]
S = []
import math
for i, cur_S in enumerate(a):
if i == 0:
n = math.ceil(cur_S/9)
S.append(naive(cur_S, n))
else:
pre_S = a[i-1]
n = len(S[-1])
if cur_S > 9*n:
S.append(naive(cur_S, math.ceil(cur_S/9)))
elif cur_S > pre_S:
S.append(remain_plus(S[-1], pre_S, cur_S))
else:
S.append(less_than(S[-1], pre_S, cur_S))
for x_arr in S:
print(''.join([str(x) for x in x_arr[::-1]]))
``` | output | 1 | 99,797 | 20 | 199,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,798 | 20 | 199,596 |
Tags: dp, greedy, implementation
Correct Solution:
```
def getnum(digsum):
if digsum < 0:
return 0
if digsum < 10:
return digsum
else:
nnine = digsum // 9
res = digsum % 9
for i in range(nnine):
res = 10 * res + 9
return res
def digsumf(n):
return sum([int(i) for i in str(n)])
def getnext(bnum, last):
if last == 0:
return getnum(bnum)
k = last + 1
digsum = digsumf(k)
diff = bnum - digsum
if diff >= 0 and 9 - k % 10 >= diff:
return k + diff
omitsum = 0
startdigsum = digsumf(last)
lastl = [int(i) for i in str(last)]
digsum = digsumf(last)
l = 10
i = 1
while True:
if i == 1 and len(str(l)) - 1 <= len(lastl):
omitsum += lastl[-(len(str(l)) - 1)]
if (last // l) % 10 + i > 9:
l *= 10
i = 1
continue
k = (last // l) * l + l * i
digsum = startdigsum - omitsum + i
diff = bnum - digsum
r = getnum(diff)
if diff >= 0 and len(str(r)) <= len(str(l // 10)):
return r + k
if diff < 0:
l *= 10
i = 1
else:
i += 1
n = int(input())
last = 0
for i in range(n):
last = getnext(int(input()), last)
print(last)
``` | output | 1 | 99,798 | 20 | 199,597 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100 | instruction | 0 | 99,799 | 20 | 199,598 |
Tags: dp, greedy, implementation
Correct Solution:
```
t = [0] * 400
x = k = 0
for q in range(int(input())):
y = int(input())
d, x = y - x, y
j = 0
while d < 1 or t[j] > min(8, 9 * j + 9 - d):
d += t[j]
t[j] = 0
j += 1
t[j] += 1
k = max(k, j)
a, b = divmod(d - 1, 9)
t[:a] = [9] * a
t[a] += b
print(''.join(map(str, t[k::-1])))
# Made By Mostafa_Khaled
``` | output | 1 | 99,799 | 20 | 199,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
def nd(n):
v = 0
while n:
n, v = n // 10, v + 1
return v
def sd(n):
v = 0
while n:
n, v = n // 10, v + n % 10
return v
def mina(s):
d9 = s // 9
return (s % 9 + 1) * 10 ** d9 - 1
def maxan(s, n):
v = 0
for i in range(n - 1, -1, -1):
c = min(s, 9)
s -= c
v += c * 10 ** i
return v
def minan(s, n):
d9 = (s - 1) // 9
return 10 ** d9 - 1 + 10 ** (n - 1) + (s - 1) % 9 * 10 ** d9
def f(s, m):
a1 = mina(s)
if a1 > m:
return a1
n = nd(m)
if m >= maxan(s, n):
return minan(s, n + 1)
for i in range(n):
if m // 10 ** i % 10 == 9:
continue
x = m - m % 10 ** i + 10 ** i
sx = sd(x)
if sx > s:
continue
for j in range(i + 1):
d = x // 10 ** j % 10
c = min(9 - d, s - sx)
x += c * 10 ** j
sx += c
if sx == s:
return x
return minan(s, n + 1)
v = 0
for i in range(int(input())):
v = f(int(input()), v)
print(v)
``` | instruction | 0 | 99,800 | 20 | 199,600 |
Yes | output | 1 | 99,800 | 20 | 199,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
def cr_mn(sm):
d = 1
res = 0
while sm > 0:
res += min(9, sm) * d
sm -= min(9, sm)
d *= 10
return res
def cr_ln(sm, ln):
if sm == 0:
return '0' * ln
res = int('1' + '0' * (ln - 1))
d = 1
sm -= 1
while sm > 0:
res += min(9, sm) * d
sm -= min(9, sm)
d *= 10
return str(res)
def cr_min(sm, lst):
r1 = cr_mn(sm)
if r1 > int(lst):
r1 = str(r1)
return '0' * (len(lst) - len(r1)) + str(r1)
ln = len(lst)
lfs = int(lst[0])
if lfs >= sm:
return '-1'
if ln == 1:
return sm
r1 = cr_min(sm - lfs, lst[1:])
if r1 == '-1':
if lfs == 9:
return '-1'
r1 = str(cr_mn(sm - lfs - 1))
return str(lfs + 1) + '0' * (ln - 1 - len(r1)) + r1
return lst[0] + r1
n = int(input())
a = []
for i in range(n):
a += [int(input())]
b = [-1 for i in range(n)]
b[0] = str(cr_mn(a[0]))
print(b[0])
for i in range(1, n):
b[i] = cr_min(a[i], b[i - 1])
if b[i] == '-1':
b[i] = cr_ln(a[i], len(b[i - 1]) + 1)
print(b[i])
``` | instruction | 0 | 99,801 | 20 | 199,602 |
Yes | output | 1 | 99,801 | 20 | 199,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
#!/usr/bin/env python
def add(c, v, p=0):
assert(v < 10 and p < len(c))
for i in range(p, len(c)):
c[i] += v
if c[i] >= 10:
c[i] %= 10
v = 1
else:
return
c.append(v)
def find_min(xsum, l):
csum = sum(l)
if csum == xsum:
return l
if csum < xsum:
for i, e in enumerate(l):
delta = min(9 - e, xsum - csum)
l[i] += delta
csum += delta
while csum != xsum:
delta = min(9, xsum - csum)
l.append(delta)
csum += delta
else:
for i in range(0, len(l)):
c = l[i]
if c != 0:
delta = 10 - c
add(l, delta, i)
csum = sum(l)
if csum <= xsum:
return find_min(xsum, l)
n = int(input())
c = [0]
for i in range(n):
b = int(input())
find_min(b, c)
print(''.join(map(str, c[::-1])))
add(c, 1)
``` | instruction | 0 | 99,802 | 20 | 199,604 |
Yes | output | 1 | 99,802 | 20 | 199,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 30 12:04:02 2015
@author: Mary
"""
n = int(input())
prev_b = 0
r = [0] * 500
for _ in range(n):
b = int(input())
if b > prev_b:
delta = b - prev_b
i = 0
while delta > 0:
if r[i] < 9:
delta_i = min(delta, 9 - r[i])
r[i] += delta_i
delta -= delta_i
i += 1
else:
max_i = -1
s = 0
while s < prev_b:
max_i += 1
s += r[max_i]
max_i += 1
sum_ge_max_i = 0
i = max_i
s = 0
while b > s + r[i-1]:
s += r[i-1]
i -= 1
if r[i] < 9:
max_i = i
sum_ge_max_i = s
r[max_i] += 1
sum_ge_max_i += 1
delta = b - sum_ge_max_i
for i in range(max_i):
if delta > 0:
delta_i = min(delta, 9)
r[i] = delta_i
delta -= delta_i
else:
r[i] = 0
res = ''.join(map(str, reversed(r)))
print(res.lstrip('0'))
prev_b = b
``` | instruction | 0 | 99,803 | 20 | 199,606 |
Yes | output | 1 | 99,803 | 20 | 199,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
def sum(i):
s = str(i)
sum = 0
for i in s:
x = int(i)
sum+=x
return sum
N = int(input())
minv = -1
for i in range(N):
x = int(input())
#output the min number > minv whose digits add to x
m = x%9
if(minv==-1):
minv = 0
while(m-minv<0):
m+=9
minv += m-minv
while(sum(minv)!=x):
minv+=9
print(minv)
# 1 2 3 4 5 6 7 8 9 1
# 2 3 4 5 6 7 8 9 10 2
# 3 4 5 6 7 8 9 10 11 3
``` | instruction | 0 | 99,804 | 20 | 199,608 |
No | output | 1 | 99,804 | 20 | 199,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
def gen_min(x):
return int(str(x % 9) + '9' * (x // 9))
def gen_next(x):
S = list(str(x))
f = True
for i in range(1, len(S)):
if S[i] != '0':
f = False
break
if f and S[0] == '1':
return x * 10
for i in range(len(S) - 1, -1, -1):
if int(S[i]) > 0:
S[i] = str(int(S[i]) - 1)
if i > 0:
S[i - 1] = str(int(S[i - 1]) + 1)
else:
S = S + ['1']
S[0], S[-1] = S[-1], S[0]
break
return int(''.join(S))
'''
x = -1
for i in range(100):
n = int(input())
x = gen_min(n) if n != -1 else gen_next(x)
print(x)
exit(0)
'''
n = int(input())
b = [int(input()) for i in range(n)]
a = [0] * (n + 1)
for i in range(1, n + 1):
l = a[i - 1]
cur = gen_min(b[i - 1])
while cur <= l:
cur = gen_next(cur)
a[i] = cur
print(cur)
``` | instruction | 0 | 99,805 | 20 | 199,610 |
No | output | 1 | 99,805 | 20 | 199,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
def give(r, s, n, k): # делает минимально возможное число с такой суммой цифр и кол-вом разрядов
for i in range(n-1, n-k-1, -1):
s = s - r[i] + 9
r[i] = 9
if (s < b) and (b-s < 10):
r[n-k-1] += b-s
s += b-s
elif s > b:
p = '1'+'0'*n
while sum_c(p) != b:
p = str(int(p)+1)
r = list(map(int, list(p)))
return r
def sum_c(s):
sum = 0
for i in s:
sum += int(i)
return sum
t = int(input())
b = 0
b_prev = 0 # прошлое значение b
a = [0] # будущий ответ
for i in range(t):
b = int(input())
n = b // 9
if b % 9 != 0:
n += 1
# посчитали количество разрядов
pr = len(str(a[i]))
if n > pr: # можно свободно создавать число
r = give([1]+[0]*(n-1), 1, n, b // 9)
else: # придется увеличивать прошлое
r = give(list(map(int, list(str(a[i])))), b_prev, pr, b // 9)
new = ''
for i in r:
new += str(i)
a.append(int(new))
# записали число в массив
b_prev = b
# обновили b_prev
for i in range(t):
print(a[i+1])
``` | instruction | 0 | 99,806 | 20 | 199,612 |
No | output | 1 | 99,806 | 20 | 199,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi.
Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence.
It is guaranteed that such a sequence always exists.
Input
The first line contains a single integer number n (1 ≤ n ≤ 300).
Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Output
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi.
If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes.
Examples
Input
3
1
2
3
Output
1
2
3
Input
3
3
2
1
Output
3
11
100
Submitted Solution:
```
n=int(input());a=[0]*n
for i in range(n):
b = int(input())
if sum(int(i) for i in list(str(a[max(0,i-1)]))) > b:
k = 10**(len(a[max(0,i-1)]))
else:
k = a[max(0,i-1)]
for j in range(k, k*10):
if sum(int(i) for i in list(str(j))) == b:
a[i]=j
break
print(*a,sep="\n")
``` | instruction | 0 | 99,807 | 20 | 199,614 |
No | output | 1 | 99,807 | 20 | 199,615 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,277 | 20 | 200,554 |
"Correct Solution:
```
def solve(n):
length = len(n)
dp = [[0 for j in range(11)] for i in range(length)]
for i in range(length):
q = int(n[i])
if q == 0:
tmp = dp[i-1][1:]
tmp.reverse()
dp[i] = [dp[i-1][0]]+tmp
else:
tmp = dp[i-1][1:]
tmp.reverse()
tmp = [dp[i-1][0]]+tmp
dp[i] = tmp[-q:]+tmp[:-q]
dp[i][q] += 1
return(sum([i[0] for i in dp]))
while True:
n=input()
if n== str(0):
break
else:
print(solve(n))
``` | output | 1 | 100,277 | 20 | 200,555 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,278 | 20 | 200,556 |
"Correct Solution:
```
INF = 10 ** 7
def solve(N):
ans = 0
for i in range(len(N)):
if i == 0:
before = [0] * 11
before[int(N[i])] += 1
ans += before[0]
elif N[i] == '0':
now = [0] * 11
for j in range(11):
k = j*10%11
now[k] += before[j]
ans += now[0]
before = now
else:
M = int(N[i])
now = [0] * 11
for j in range(11):
k = (j*10 + M)%11
now[k] += before[j]
now[M%11] += 1
ans += now[0]
before = now
print(ans)
def main():
while True:
N = input()
if N == '0':
return
solve(N)
if __name__ == '__main__':
main()
``` | output | 1 | 100,278 | 20 | 200,557 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,279 | 20 | 200,558 |
"Correct Solution:
```
#教室内の位置は右*中央
#問題は「Eleven Lover」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2182&lang=jp)
#本当は問題「Planning Rolling Blackouts」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1176&lang=jp)
#を解こうとしたのですが、小区間での分割をひたすら統合する解法までは立ったものの実装力がなかったので一旦やめました
while(True):
#今回はinputの数字を文字列として一桁ずつ扱った方が嬉しいのでint()しません
s = input()
m = len(s)
#0を弾くやつ
if s == "0":
quit()
#pdfに書いていた方針と全く同じやり方をします
#配列dpをA_i,jとしてとります
dp = [[0 for j in range(11)] for i in range(m)]
for i in range(m):
n = int(s[i])
#ここで、どこかの桁が0になってる時に注意します
#というのも、問題文中に「0から始まる数は11の倍数に含めない」としてあるからです
#したがって0が出た時はそこまでの数字を10倍する効果しか持たないことになります
if n == 0:
tmp = dp[i-1][1:]
tmp.reverse()
#dp[i][0]=dp[i-1][0]
#dp[i][k]=dp[i-1][11-k] (if k >= 1)となります(これがtmp.reverse()の意図)
dp[i] = [dp[i-1][0]]+tmp
else:
#やるだけ
tmp = dp[i-1][1:]
tmp.reverse()
#10倍なのでA[i][k] (k>=1)をリバース(上と同じ)
tmp = [dp[i-1][0]]+tmp
#i桁目の数字を見てその分A_i,jをずらします
#添字に注意
dp[i] = tmp[-n:]+tmp[:-n]
dp[i][n] += 1 #インクリメントも忘れずに
#あとはdp[k][0]を足すだけ
print(sum([i[0] for i in dp]))
``` | output | 1 | 100,279 | 20 | 200,559 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,280 | 20 | 200,560 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
s = S()
if s == '0':
break
d = collections.defaultdict(int)
r = 0
for c in s:
c = int(c)
nd = collections.defaultdict(int)
for k,v in d.items():
nd[(k*10+c) % 11] = v
if c > 0:
nd[c] += 1
r += nd[0]
d = nd
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 100,280 | 20 | 200,561 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,281 | 20 | 200,562 |
"Correct Solution:
```
a = input()
while (int(a) != 0):
remain = [0for i in range(11)]
remain[int(a[0])] = remain[int(a[0])] + 1 ##V0
n = len(a)
cnt = 0
for i in range(1,n):
copy = remain[:]
remain = [0for i in range(11)]
a_i = int(a[i])
if (a_i != 0):
for k in range(11):
rem = (k*10 + a_i)%11
remain[rem] += copy[k]
remain[a_i] += 1
elif (a_i == 0):
for k in range(11):
rem = (k*10 + a_i)%11
remain[rem] += copy[k]
cnt += remain[0]
print(cnt)
a = input()
``` | output | 1 | 100,281 | 20 | 200,563 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,282 | 20 | 200,564 |
"Correct Solution:
```
def solve():
N=list(input())
if N==["0"]:
exit()
else:
ans=0
cnt={i:0 for i in range(11)}
sums=0
cnt[0]=1
N=N[::-1]
for i in range(len(N)):
sums+=pow(10,i,11)*int(N[i])
sums%=11
cnt[sums]+=1
if int(N[i])==0:
ans-=(cnt[sums]-1)
for i in range(11):
K=cnt[i]
ans+=(K*(K-1))//2
print(ans)
return solve()
if __name__=="__main__":
solve()
``` | output | 1 | 100,282 | 20 | 200,565 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,283 | 20 | 200,566 |
"Correct Solution:
```
while 1:
N = input()
if N == "0":
break
dp = [[0 for i in range(11)] for j in range(len(N) + 1)]
for i, c in enumerate(N, 1):
for j, kazu in enumerate(dp[i - 1]):
if kazu != 0:
dp[i][(j * 10 + int(c)) % 11] = kazu
if int(c) != 0:
dp[i][int(c) % 11] += 1
ans = 0
for d in dp:
ans += d[0]
print(ans)
``` | output | 1 | 100,283 | 20 | 200,567 |
Provide a correct Python 3 solution for this coding contest problem.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38 | instruction | 0 | 100,284 | 20 | 200,568 |
"Correct Solution:
```
while(True):
s = input()
m = len(s)
if s == "0":
quit()
dp = [[0 for j in range(11)] for i in range(m)]
for i in range(m):
n = int(s[i])
if n == 0:
tmp = dp[i-1][1:]
tmp.reverse()
dp[i] = [dp[i-1][0]]+tmp
else:
tmp = dp[i-1][1:]
tmp.reverse()
tmp = [dp[i-1][0]]+tmp
dp[i] = tmp[-n:]+tmp[:-n]
dp[i][n] += 1
ans = 0
for i in range(m):
ans += dp[i][0]
print(ans)
``` | output | 1 | 100,284 | 20 | 200,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a good number. He would like to find out a very good number. As the first step, he wants an easy way to count how many 11-sequences are there in a given number. Even for him, counting them from a big number is not easy. Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program to count the number of 11-sequences. Note that an 11-sequence must be a positive number without leading zeros.
Input
The input is a sequence of lines each of which contains a number consisting of less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which should not be processed.
Output
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer.
Example
Input
17819
1111
11011
1234567891011121314151617181920
0
Output
1
4
4
38
Submitted Solution:
```
targ = input()
while True:
ans = [[0 for n in range(len(targ))] for m in range(len(targ) -1)]
for o in range(len(targ)):
for i in range(o+1,len(targ)):
if targ[o] == '0':
ans[o][i] = ans[o-1][i]
elif i == len(ans):
ans[o][i] = int((int(targ[o] + targ[o+1:i+1])) % 11 == 0) + ans[o][i-1] + ans[o-1][i]
else:
ans[o][i] = int((int(targ[o] + targ[o+1:i+1])) % 11 == 0) + ans[o][i-1]
print(ans[-1][-1])
targ = input()
if targ == '0':
break
``` | instruction | 0 | 100,285 | 20 | 200,570 |
No | output | 1 | 100,285 | 20 | 200,571 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.