message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
Output
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
Submitted Solution:
```
from sys import stdin
inp = lambda: stdin.readline().strip()
t = int(inp())
for _ in range(t):
n = int(inp())
a = [int(x) for x in inp().split()]
arr = list(range(n))
for i in range(n):
arr[i] = (arr[i]+a[i%n])%n
if len(arr) == len(set(arr)):
print("YES")
else:
print("NO")
``` | instruction | 0 | 44,005 | 8 | 88,010 |
Yes | output | 1 | 44,005 | 8 | 88,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
Output
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
Submitted Solution:
```
def main():
import sys, math
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
out = sys.stdout.write
# sys.setrecursionlimit(100000)
INF = int(1e9)
mod = int(1e9)+7
for t in range(int(data())):
n=int(data())
A=list(mdata())
d=dd(int)
m=0
m2=INF
for i in range(1,2*n+1):
k=i+A[i%n]
m=max(k,m)
m2=min(k,m)
d[k]+=1
m1=max(d.values())
if (m!=len(d) or m2!=1) and m1==1:
out("YES"+'\n')
else:
out("NO" + '\n')
if __name__ == '__main__':
main()
``` | instruction | 0 | 44,006 | 8 | 88,012 |
No | output | 1 | 44,006 | 8 | 88,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
Output
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
Submitted Solution:
```
import math
import sys
from collections import defaultdict,Counter,deque,OrderedDict
import bisect
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#INF = 10 ** 18
#MOD = 1000000000 + 7
from itertools import accumulate,groupby
for _ in range(int(input())):
N = int(input())
A = alele()
B = [];mark ={};f=0
for i in range(N):
x = A[i]%N
if A[i]>0:
B.append(x)
z = (i+x)%N
#print(x,z)
if mark.get(z,-1) == -1:
mark[z] = i
else:
f=1
break
else:
B.append(-x)
z = (i-x)%N
#print(x,z)
if mark.get(z,-1) == -1:
mark[z] = i
else:
f=1
break
#print(A,B,mark)
if f==0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 44,007 | 8 | 88,014 |
No | output | 1 | 44,007 | 8 | 88,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
Output
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
Submitted Solution:
```
#map(int,input().split())
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
for i in range(n):
l[i]=l[i]%n
flag=0
for i in range(n):
if l[i]>i:
if l[l[i]]-l[i]==i-l[i]:
flag=1
break
elif l[i]<i:
if i-l[i]==l[i]-l[l[i]]:
flag==1
break
elif i!=n-1:
if l[i+1]-l[i]==1:
flag=1
break
if flag==1:
print('NO')
else:
print('YES')
``` | instruction | 0 | 44,008 | 8 | 88,016 |
No | output | 1 | 44,008 | 8 | 88,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).
For any integer k and positive integer n, let kmod n denote the remainder when k is divided by n. More formally, r=kmod n is the smallest non-negative integer such that k-r is divisible by n. It always holds that 0≤ kmod n≤ n-1. For example, 100mod 12=4 and (-1337)mod 3=1.
Then the shuffling works as follows. There is an array of n integers a_0,a_1,…,a_{n-1}. Then for each integer k, the guest in room k is moved to room number k+a_{kmod n}.
After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.
Input
Each test consists of multiple test cases. The first line contains a single integer t (1≤ t≤ 10^4) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of each test case contains a single integer n (1≤ n≤ 2⋅ 10^5) — the length of the array.
The second line of each test case contains n integers a_0,a_1,…,a_{n-1} (-10^9≤ a_i≤ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅ 10^5.
Output
For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).
Example
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case, every guest is shifted by 14 rooms, so the assignment is still unique.
In the second test case, even guests move to the right by 1 room, and odd guests move to the left by 1 room. We can show that the assignment is still unique.
In the third test case, every fourth guest moves to the right by 1 room, and the other guests move to the right by 5 rooms. We can show that the assignment is still unique.
In the fourth test case, guests 0 and 1 are both assigned to room 3.
In the fifth test case, guests 1 and 2 are both assigned to room 2.
Submitted Solution:
```
import math
t = int(input())
while (t):
n = int(input())
a = input().split()
a = [(n + int(x) % n) % n for x in a]
next = [0 for i in range(n)]
for i in range(n):
next[i] = (i + a[i]) % n
visited = [-1 for i in range(n)]
flag = True
for i in range(n):
if (visited[i] == -1):
u = i
tmp = []
while (True):
if (visited[u] == 1):
flag = False
break
elif (visited[u] == 0):
break
else:
visited[u] = 0
tmp.append(u)
u = next[u]
if (not flag):
break
for x in tmp:
visited[x] = 1
if (not flag):
break
if (flag):
print('YES')
else:
print('NO')
t -= 1
``` | instruction | 0 | 44,009 | 8 | 88,018 |
No | output | 1 | 44,009 | 8 | 88,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
Output
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Examples
Input
3 3
Output
1
AAA
.A.
.A.
Input
5 6
Output
4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D
Input
2 2
Output
0
..
.. | instruction | 0 | 44,042 | 8 | 88,084 |
Tags: brute force, dp
Correct Solution:
```
n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n == 3 and m == 3:
ans = '''1
.A.
.A.
AAA'''
if n == 4 and m == 1:
ans = '''0
.
.
.
.'''
if n == 4 and m == 2:
ans = '''0
..
..
..
..'''
if n == 4 and m == 3:
ans = '''1
.A.
.A.
AAA
...'''
if n == 4 and m == 4:
ans = '''2
...A
BAAA
BBBA
B...'''
if n == 5 and m == 1:
ans = '''0
.
.
.
.
.'''
if n == 5 and m == 2:
ans = '''0
..
..
..
..
..'''
if n == 5 and m == 3:
ans = '''2
..A
AAA
.BA
.B.
BBB'''
if n == 5 and m == 4:
ans = '''2
.A..
.A..
AAAB
.BBB
...B'''
if n == 5 and m == 5:
ans = '''4
BBB.A
.BAAA
DB.CA
DDDC.
D.CCC'''
if n == 6 and m == 1:
ans = '''0
.
.
.
.
.
.'''
if n == 6 and m == 2:
ans = '''0
..
..
..
..
..
..'''
if n == 6 and m == 3:
ans = '''2
.A.
.A.
AAA
.B.
.B.
BBB'''
if n == 6 and m == 4:
ans = '''3
.A..
.A..
AAAB
CBBB
CCCB
C...'''
if n == 6 and m == 5:
ans = '''4
.A..B
.ABBB
AAACB
.D.C.
.DCCC
DDD..'''
if n == 6 and m == 6:
ans = '''5
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E..DDD'''
if n == 7 and m == 1:
ans = '''0
.
.
.
.
.
.
.'''
if n == 7 and m == 2:
ans = '''0
..
..
..
..
..
..
..'''
if n == 7 and m == 3:
ans = '''3
..A
AAA
B.A
BBB
BC.
.C.
CCC'''
if n == 7 and m == 4:
ans = '''4
...A
BAAA
BBBA
B..C
DCCC
DDDC
D...'''
if n == 7 and m == 5:
ans = '''5
.A..B
.ABBB
AAACB
.CCC.
.D.CE
.DEEE
DDD.E'''
if n == 7 and m == 6:
ans = '''6
.A..B.
.ABBB.
AAACB.
EEECCC
.EDC.F
.EDFFF
.DDD.F'''
if n == 7 and m == 7:
ans = '''8
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
GDHHHFE
GGGH.F.
G..HFFF'''
if n == 8 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.'''
if n == 8 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..'''
if n == 8 and m == 3:
ans = '''3
.A.
.A.
AAA
..B
BBB
.CB
.C.
CCC'''
if n == 8 and m == 4:
ans = '''4
.A..
.A..
AAAB
CBBB
CCCB
CD..
.D..
DDD.'''
if n == 8 and m == 5:
ans = '''6
.A..B
.ABBB
AAACB
DDDC.
.DCCC
FD.E.
FFFE.
F.EEE'''
if n == 8 and m == 6:
ans = '''7
.A..B.
.ABBB.
AAA.BC
DDDCCC
.DGGGC
.DFGE.
FFFGE.
..FEEE'''
if n == 8 and m == 7:
ans = '''9
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
FD.IIIE
FFFHIG.
FHHHIG.
...HGGG'''
if n == 9 and m == 8:
ans = '''12
.A..BDDD
.ABBBCD.
AAAEBCD.
FEEECCCG
FFFEHGGG
FKKKHHHG
.IKLH.J.
.IKLLLJ.
IIIL.JJJ'''
if n == 8 and m == 8:
ans = '''10
.A..BCCC
.A..B.C.
AAABBBCD
E.GGGDDD
EEEGJJJD
EF.GIJH.
.FIIIJH.
FFF.IHHH'''
if n == 9 and m == 9:
ans = '''13
AAA.BCCC.
.ABBB.CD.
.AE.BFCD.
EEEFFFDDD
G.E.HFIII
GGGJHHHI.
GK.JHL.IM
.KJJJLMMM
KKK.LLL.M'''
if n == 9 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.
.'''
if n == 9 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..
..'''
if n == 9 and m == 3:
ans = '''4
..A
AAA
B.A
BBB
B.C
CCC
.DC
.D.
DDD'''
if n == 9 and m == 4:
ans = '''5
.A..
.A..
AAAB
CBBB
CCCB
C..D
EDDD
EEED
E...'''
if n == 9 and m == 5:
ans = '''7
.A..B
.ABBB
AAACB
DCCC.
DDDCF
DEFFF
.E.GF
EEEG.
..GGG'''
if n == 9 and m == 6:
ans = '''8
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E.GDDD
.FGGGH
.FGHHH
FFF..H'''
if n == 9 and m == 7:
ans = '''10
.ACCC.B
.A.CBBB
AAACD.B
...EDDD
FEEED.G
FFFEGGG
FHJJJIG
.H.J.I.
HHHJIII'''
if swapped:
cnt = ans.split('\n')[0]
lst = ans.split('\n')[1:]
ans = ''
for j in range(m):
for i in range(n):
ans = ans + lst[i][j]
ans += '\n'
ans = cnt + '\n' + ans
print(ans)
# Made By Mostafa_Khaled
``` | output | 1 | 44,042 | 8 | 88,085 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
Output
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Examples
Input
3 3
Output
1
AAA
.A.
.A.
Input
5 6
Output
4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D
Input
2 2
Output
0
..
.. | instruction | 0 | 44,043 | 8 | 88,086 |
Tags: brute force, dp
Correct Solution:
```
r={}
r[(1,1)]='''0
.
'''
r[(1,2)]='''0
..
'''
r[(1,3)]='''0
...
'''
r[(1,4)]='''0
....
'''
r[(1,5)]='''0
.....
'''
r[(1,6)]='''0
......
'''
r[(1,7)]='''0
.......
'''
r[(1,8)]='''0
........
'''
r[(1,9)]='''0
.........
'''
r[(2,2)]='''0
..
..
'''
r[(2,3)]='''0
...
...
'''
r[(2,4)]='''0
....
....
'''
r[(2,5)]='''0
.....
.....
'''
r[(2,6)]='''0
......
......
'''
r[(2,7)]='''0
.......
.......
'''
r[(2,8)]='''0
........
........
'''
r[(2,9)]='''0
.........
.........
'''
r[(3,3)]='''1
.A.
.A.
AAA
'''
r[(3,4)]='''1
.A..
.A..
AAA.
'''
r[(3,5)]='''2
BBBA.
.B.A.
.BAAA
'''
r[(3,6)]='''2
.B.A..
.B.AAA
BBBA..
'''
r[(3,7)]='''3
A.BBBC.
AAAB.C.
A..BCCC
'''
r[(3,8)]='''3
.BCCC.A.
.B.CAAA.
BBBC..A.
'''
r[(3,9)]='''4
BBBDAAA.C
.B.D.ACCC
.BDDDA..C
'''
r[(4,4)]='''2
BBB.
.BA.
.BA.
.AAA
'''
r[(4,5)]='''2
....A
.BAAA
.BBBA
.B...
'''
r[(4,6)]='''3
..A...
.CAAAB
.CABBB
CCC..B
'''
r[(4,7)]='''4
...ACCC
BAAADC.
BBBADC.
B..DDD.
'''
r[(4,8)]='''4
BBB.A...
.BD.AAAC
.BD.ACCC
.DDD...C
'''
r[(4,9)]='''5
...ACCC..
DAAAECBBB
DDDAEC.B.
D..EEE.B.
'''
r[(5,5)]='''4
D.BBB
DDDB.
DA.BC
.ACCC
AAA.C
'''
r[(5,6)]='''4
A..DDD
AAA.D.
ABBBDC
..BCCC
..B..C
'''
r[(5,7)]='''5
.A.EEE.
.AAAEB.
CA.DEB.
CCCDBBB
C.DDD..
'''
r[(5,8)]='''6
A..D.FFF
AAADDDF.
AB.DECF.
.BEEECCC
BBB.EC..
'''
r[(5,9)]='''7
..CAAAB..
CCC.AGBBB
F.CDAGBE.
FFFDGGGE.
F.DDD.EEE
'''
r[(6,6)]='''5
AAA...
.ABCCC
.AB.C.
DBBBCE
DDDEEE
D....E
'''
r[(6,7)]='''6
..A...B
AAA.BBB
E.ADDDB
EEECDF.
ECCCDF.
...CFFF
'''
r[(6,8)]='''7
F.DDD..G
FFFDBGGG
F.ADBBBG
AAAEBC..
..AE.CCC
..EEEC..
'''
r[(6,9)]='''8
F..AAAGGG
FFFCA.BG.
FCCCA.BG.
HHHCDBBBE
.HDDD.EEE
.H..D...E
'''
r[(7,7)]='''8
H..AEEE
HHHA.E.
HDAAAEC
.DDDCCC
BDFFFGC
BBBF.G.
B..FGGG
'''
r[(7,8)]='''9
F.III..G
FFFIAGGG
FH.IAAAG
.HHHADDD
EHBBBCD.
EEEB.CD.
E..BCCC.
'''
r[(7,9)]='''10
...BJJJ.A
.BBBGJAAA
E..BGJC.A
EEEGGGCCC
EHDDDFC.I
.H.D.FIII
HHHDFFF.I
'''
r[(8,8)]='''10
A..BBB..
AAAJBIII
AH.JB.I.
.HJJJGI.
HHHC.GGG
ECCCDG.F
EEECDFFF
E..DDD.F
'''
r[(8,9)]='''12
DDDLLL..H
.DC.LGHHH
.DC.LGGGH
ECCCBGKKK
EEEABBBK.
EI.ABJ.KF
.IAAAJFFF
III.JJJ.F
'''
r[(9,9)]='''13
K.DDDEMMM
KKKD.E.M.
KA.DEEEMF
.AAALGFFF
HALLLGGGF
HHHBLGCCC
HI.B..JC.
.IBBB.JC.
III..JJJ.
'''
n,m=map(int,input().split())
if n<m:
print(r[(n,m)]),
else:
s=r[(m,n)].strip().split('\n')
print(s[0])
s=s[1:]
s=zip(*s)
for t in s:
print(''.join(t))
``` | output | 1 | 44,043 | 8 | 88,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
Output
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Examples
Input
3 3
Output
1
AAA
.A.
.A.
Input
5 6
Output
4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D
Input
2 2
Output
0
..
.. | instruction | 0 | 44,044 | 8 | 88,088 |
Tags: brute force, dp
Correct Solution:
```
n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n == 3 and m == 3:
ans = '''1
.A.
.A.
AAA'''
if n == 4 and m == 1:
ans = '''0
.
.
.
.'''
if n == 4 and m == 2:
ans = '''0
..
..
..
..'''
if n == 4 and m == 3:
ans = '''1
.A.
.A.
AAA
...'''
if n == 4 and m == 4:
ans = '''2
...A
BAAA
BBBA
B...'''
if n == 5 and m == 1:
ans = '''0
.
.
.
.
.'''
if n == 5 and m == 2:
ans = '''0
..
..
..
..
..'''
if n == 5 and m == 3:
ans = '''2
..A
AAA
.BA
.B.
BBB'''
if n == 5 and m == 4:
ans = '''2
.A..
.A..
AAAB
.BBB
...B'''
if n == 5 and m == 5:
ans = '''4
BBB.A
.BAAA
DB.CA
DDDC.
D.CCC'''
if n == 6 and m == 1:
ans = '''0
.
.
.
.
.
.'''
if n == 6 and m == 2:
ans = '''0
..
..
..
..
..
..'''
if n == 6 and m == 3:
ans = '''2
.A.
.A.
AAA
.B.
.B.
BBB'''
if n == 6 and m == 4:
ans = '''3
.A..
.A..
AAAB
CBBB
CCCB
C...'''
if n == 6 and m == 5:
ans = '''4
.A..B
.ABBB
AAACB
.D.C.
.DCCC
DDD..'''
if n == 6 and m == 6:
ans = '''5
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E..DDD'''
if n == 7 and m == 1:
ans = '''0
.
.
.
.
.
.
.'''
if n == 7 and m == 2:
ans = '''0
..
..
..
..
..
..
..'''
if n == 7 and m == 3:
ans = '''3
..A
AAA
B.A
BBB
BC.
.C.
CCC'''
if n == 7 and m == 4:
ans = '''4
...A
BAAA
BBBA
B..C
DCCC
DDDC
D...'''
if n == 7 and m == 5:
ans = '''5
.A..B
.ABBB
AAACB
.CCC.
.D.CE
.DEEE
DDD.E'''
if n == 7 and m == 6:
ans = '''6
.A..B.
.ABBB.
AAACB.
EEECCC
.EDC.F
.EDFFF
.DDD.F'''
if n == 7 and m == 7:
ans = '''8
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
GDHHHFE
GGGH.F.
G..HFFF'''
if n == 8 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.'''
if n == 8 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..'''
if n == 8 and m == 3:
ans = '''3
.A.
.A.
AAA
..B
BBB
.CB
.C.
CCC'''
if n == 8 and m == 4:
ans = '''4
.A..
.A..
AAAB
CBBB
CCCB
CD..
.D..
DDD.'''
if n == 8 and m == 5:
ans = '''6
.A..B
.ABBB
AAACB
DDDC.
.DCCC
FD.E.
FFFE.
F.EEE'''
if n == 8 and m == 6:
ans = '''7
.A..B.
.ABBB.
AAA.BC
DDDCCC
.DGGGC
.DFGE.
FFFGE.
..FEEE'''
if n == 8 and m == 7:
ans = '''9
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
FD.IIIE
FFFHIG.
FHHHIG.
...HGGG'''
if n == 9 and m == 8:
ans = '''12
.A..BDDD
.ABBBCD.
AAAEBCD.
FEEECCCG
FFFEHGGG
FKKKHHHG
.IKLH.J.
.IKLLLJ.
IIIL.JJJ'''
if n == 8 and m == 8:
ans = '''10
.A..BCCC
.A..B.C.
AAABBBCD
E.GGGDDD
EEEGJJJD
EF.GIJH.
.FIIIJH.
FFF.IHHH'''
if n == 9 and m == 9:
ans = '''13
AAA.BCCC.
.ABBB.CD.
.AE.BFCD.
EEEFFFDDD
G.E.HFIII
GGGJHHHI.
GK.JHL.IM
.KJJJLMMM
KKK.LLL.M'''
if n == 9 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.
.'''
if n == 9 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..
..'''
if n == 9 and m == 3:
ans = '''4
..A
AAA
B.A
BBB
B.C
CCC
.DC
.D.
DDD'''
if n == 9 and m == 4:
ans = '''5
.A..
.A..
AAAB
CBBB
CCCB
C..D
EDDD
EEED
E...'''
if n == 9 and m == 5:
ans = '''7
.A..B
.ABBB
AAACB
DCCC.
DDDCF
DEFFF
.E.GF
EEEG.
..GGG'''
if n == 9 and m == 6:
ans = '''8
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E.GDDD
.FGGGH
.FGHHH
FFF..H'''
if n == 9 and m == 7:
ans = '''10
.ACCC.B
.A.CBBB
AAACD.B
...EDDD
FEEED.G
FFFEGGG
FHJJJIG
.H.J.I.
HHHJIII'''
if swapped:
cnt = ans.split('\n')[0]
lst = ans.split('\n')[1:]
ans = ''
for j in range(m):
for i in range(n):
ans = ans + lst[i][j]
ans += '\n'
ans = cnt + '\n' + ans
print(ans)
``` | output | 1 | 44,044 | 8 | 88,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
Output
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Examples
Input
3 3
Output
1
AAA
.A.
.A.
Input
5 6
Output
4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D
Input
2 2
Output
0
..
..
Submitted Solution:
```
n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n == 3 and m == 3:
ans = '''1
.A.
.A.
AAA'''
if n == 4 and m == 1:
ans = '''0
.
.
.
.'''
if n == 4 and m == 2:
ans = '''0
..
..
..
..'''
if n == 4 and m == 3:
ans = '''1
.A.
.A.
AAA
...'''
if n == 4 and m == 4:
ans = '''2
...A
BAAA
BBBA
B...'''
if n == 5 and m == 1:
ans = '''0
.
.
.
.
.'''
if n == 5 and m == 2:
ans = '''0
..
..
..
..
..'''
if n == 5 and m == 3:
ans = '''2
..A
AAA
.BA
.B.
BBB'''
if n == 5 and m == 4:
ans = '''2
.A..
.A..
AAAB
.BBB
...B'''
if n == 5 and m == 5:
ans = '''4
BBB.A
.BAAA
DB.CA
DDDC.
D.CCC'''
if n == 6 and m == 1:
ans = '''0
.
.
.
.
.
.'''
if n == 6 and m == 2:
ans = '''0
..
..
..
..
..
..'''
if n == 6 and m == 3:
ans = '''2
.A.
.A.
AAA
.B.
.B.
BBB'''
if n == 6 and m == 4:
ans = '''3
.A..
.A..
AAAB
CBBB
CCCB
C...'''
if n == 6 and m == 5:
ans = '''4
.A..B
.ABBB
AAACB
.D.C.
.DCCC
DDD..'''
if n == 6 and m == 6:
ans = '''5
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E..DDD'''
if n == 7 and m == 1:
ans = '''0
.
.
.
.
.
.
.'''
if n == 7 and m == 2:
ans = '''0
..
..
..
..
..
..
..'''
if n == 7 and m == 3:
ans = '''3
..A
AAA
B.A
BBB
BC.
.C.
CCC'''
if n == 7 and m == 4:
ans = '''4
...A
BAAA
BBBA
B..C
DCCC
DDDC
D...'''
if n == 7 and m == 5:
ans = '''5
.A..B
.ABBB
AAACB
.CCC.
.D.CE
.DEEE
DDD.E'''
if n == 7 and m == 6:
ans = '''6
.A..B.
.ABBB.
AAACB.
EEECCC
.EDC.F
.EDFFF
.DDD.F'''
if n == 7 and m == 7:
ans = '''8
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
GDHHHFE
GGGH.F.
G..HFFF'''
if n == 8 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.'''
if n == 8 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..'''
if n == 8 and m == 3:
ans = '''3
.A.
.A.
AAA
..B
BBB
.CB
.C.
CCC'''
if n == 8 and m == 4:
ans = '''4
.A..
.A..
AAAB
CBBB
CCCB
CD..
.D..
DDD.'''
if n == 8 and m == 5:
ans = '''6
.A..B
.ABBB
AAACB
DDDC.
.DCCC
FD.E.
FFFE.
F.EEE'''
if n == 8 and m == 6:
ans = '''7
.A..B.
.ABBB.
AAA.BC
DDDCCC
.DGGGC
.DFGE.
FFFGE.
..FEEE'''
if n == 8 and m == 7:
ans = '''9
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
FD.IIIE
FFFHIG.
FHHHIG.
...HGGG'''
if n == 9 and m == 8:
ans = '''12
.A..BDDD
.ABBBCD.
AAAEBCD.
FEEECCCG
FFFEHGGG
FKKKHHHG
.IKLH.J.
.IKLLLJ.
IIIL.JJJ'''
if n == 8 and m == 8:
ans = '''10
.A..BCCC
.A..B.C.
AAABBBCD
E.GGGDDD
EEEGJJJD
EF.GIJH.
.FIIIJH.
FFF.IHHH'''
if n == 9 and m == 9:
ans = '''12
.A..B..C.
.A..BCCC.
AAABBBDC.
HHHGDDDE.
.HFGGGDE.
.HFG.JEEE
KFFFIJJJL
KKK.IJLLL
K..III..L'''
if n == 9 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.
.'''
if n == 9 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..
..'''
if n == 9 and m == 3:
ans = '''4
..A
AAA
B.A
BBB
B.C
CCC
.DC
.D.
DDD'''
if n == 9 and m == 4:
ans = '''5
.A..
.A..
AAAB
CBBB
CCCB
C..D
EDDD
EEED
E...'''
if n == 9 and m == 5:
ans = '''7
.A..B
.ABBB
AAACB
DCCC.
DDDCF
DEFFF
.E.GF
EEEG.
..GGG'''
if n == 9 and m == 6:
ans = '''8
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E.GDDD
.FGGGH
.FGHHH
FFF..H'''
if n == 9 and m == 7:
ans = '''10
.ACCC.B
.A.CBBB
AAACD.B
...EDDD
FEEED.G
FFFEGGG
FHJJJIG
.H.J.I.
HHHJIII'''
if swapped:
cnt = ans.split('\n')[0]
lst = ans.split('\n')[1:]
ans = ''
for j in range(m):
for i in range(n):
ans = ans + lst[i][j]
ans += '\n'
ans = cnt + '\n' + ans
print(ans)
``` | instruction | 0 | 44,045 | 8 | 88,090 |
No | output | 1 | 44,045 | 8 | 88,091 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):
### ..# .#. #..
.#. ### .#. ###
.#. ..# ### #..
Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.
Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?
Input
The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).
Output
In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.
Examples
Input
3 3
Output
1
AAA
.A.
.A.
Input
5 6
Output
4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D
Input
2 2
Output
0
..
..
Submitted Solution:
```
n, m = map(int, input().split())
swapped = False
if n < m:
n, m = m, n
swapped = True
ans = ''
if n == 1 and m == 1:
ans = '''0
.'''
if n == 2 and m == 1:
ans = '''0
.
.'''
if n == 2 and m == 2:
ans = '''0
..
..'''
if n == 3 and m == 1:
ans = '''0
.
.
.'''
if n == 3 and m == 2:
ans = '''0
..
..
..'''
if n == 3 and m == 3:
ans = '''1
.A.
.A.
AAA'''
if n == 4 and m == 1:
ans = '''0
.
.
.
.'''
if n == 4 and m == 2:
ans = '''0
..
..
..
..'''
if n == 4 and m == 3:
ans = '''1
.A.
.A.
AAA
...'''
if n == 4 and m == 4:
ans = '''2
...A
BAAA
BBBA
B...'''
if n == 5 and m == 1:
ans = '''0
.
.
.
.
.'''
if n == 5 and m == 2:
ans = '''0
..
..
..
..
..'''
if n == 5 and m == 3:
ans = '''2
..A
AAA
.BA
.B.
BBB'''
if n == 5 and m == 4:
ans = '''2
.A..
.A..
AAAB
.BBB
...B'''
if n == 5 and m == 5:
ans = '''4
BBB.A
.BAAA
DB.CA
DDDC.
D.CCC'''
if n == 6 and m == 1:
ans = '''0
.
.
.
.
.
.'''
if n == 6 and m == 2:
ans = '''0
..
..
..
..
..
..'''
if n == 6 and m == 3:
ans = '''2
.A.
.A.
AAA
.B.
.B.
BBB'''
if n == 6 and m == 4:
ans = '''3
.A..
.A..
AAAB
CBBB
CCCB
C...'''
if n == 6 and m == 5:
ans = '''4
.A..B
.ABBB
AAACB
.D.C.
.DCCC
DDD..'''
if n == 6 and m == 6:
ans = '''5
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E..DDD'''
if n == 7 and m == 1:
ans = '''0
.
.
.
.
.
.
.'''
if n == 7 and m == 2:
ans = '''0
..
..
..
..
..
..
..'''
if n == 7 and m == 3:
ans = '''3
..A
AAA
B.A
BBB
BC.
.C.
CCC'''
if n == 7 and m == 4:
ans = '''4
...A
BAAA
BBBA
B..C
DCCC
DDDC
D...'''
if n == 7 and m == 5:
ans = '''5
.A..B
.ABBB
AAACB
.CCC.
.D.CE
.DEEE
DDD.E'''
if n == 7 and m == 6:
ans = '''6
.A..B.
.ABBB.
AAACB.
EEECCC
.EDC.F
.EDFFF
.DDD.F'''
if n == 7 and m == 7:
ans = '''8
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
GDHHHFE
GGGH.F.
G..HFFF'''
if n == 8 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.'''
if n == 8 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..'''
if n == 8 and m == 3:
ans = '''3
.A.
.A.
AAA
..B
BBB
.CB
.C.
CCC'''
if n == 8 and m == 4:
ans = '''4
.A..
.A..
AAAB
CBBB
CCCB
CD..
.D..
DDD.'''
if n == 8 and m == 5:
ans = '''6
.A..B
.ABBB
AAACB
DDDC.
.DCCC
FD.E.
FFFE.
F.EEE'''
if n == 8 and m == 6:
ans = '''7
.A..B.
.ABBB.
AAA.BC
DDDCCC
.DGGGC
.DFGE.
FFFGE.
..FEEE'''
if n == 8 and m == 7:
ans = '''9
B..ACCC
BBBA.C.
BDAAACE
.DDDEEE
FD.IIIE
FFFHIG.
FHHHIG.
...HGGG'''
if n == 9 and m == 8:
ans = '''11
.A..B..C
.A..BCCC
AAABBBDC
GGGFDDD.
.GEFFFDI
.GEFHIII
KEEEH.JI
KKKHHHJ.
K....JJJ'''
if n == 8 and m == 8:
ans = '''10
.A..BCCC
.A..B.C.
AAABBBCD
E.GGGDDD
EEEGJJJD
EF.GIJH.
.FIIIJH.
FFF.IHHH'''
if n == 9 and m == 9:
ans = '''12
.A..B..C.
.A..BCCC.
AAABBBDC.
HHHGDDDE.
.HFGGGDE.
.HFG.JEEE
KFFFIJJJL
KKK.IJLLL
K..III..L'''
if n == 9 and m == 1:
ans = '''0
.
.
.
.
.
.
.
.
.'''
if n == 9 and m == 2:
ans = '''0
..
..
..
..
..
..
..
..
..'''
if n == 9 and m == 3:
ans = '''4
..A
AAA
B.A
BBB
B.C
CCC
.DC
.D.
DDD'''
if n == 9 and m == 4:
ans = '''5
.A..
.A..
AAAB
CBBB
CCCB
C..D
EDDD
EEED
E...'''
if n == 9 and m == 5:
ans = '''7
.A..B
.ABBB
AAACB
DCCC.
DDDCF
DEFFF
.E.GF
EEEG.
..GGG'''
if n == 9 and m == 6:
ans = '''8
.A..B.
.ABBB.
AAACB.
ECCCD.
EEECD.
E.GDDD
.FGGGH
.FGHHH
FFF..H'''
if n == 9 and m == 7:
ans = '''10
.ACCC.B
.A.CBBB
AAACD.B
...EDDD
FEEED.G
FFFEGGG
FHJJJIG
.H.J.I.
HHHJIII'''
if swapped:
cnt = ans.split('\n')[0]
lst = ans.split('\n')[1:]
ans = ''
for j in range(m):
for i in range(n):
ans = ans + lst[i][j]
ans += '\n'
ans = cnt + '\n' + ans
print(ans)
``` | instruction | 0 | 44,046 | 8 | 88,092 |
No | output | 1 | 44,046 | 8 | 88,093 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
input()
attractivenes_list = [int(i) for i in input().split()]
max_total = sum(attractivenes_list)
max1 = sum(attractivenes_list[::2])
max2 = sum(attractivenes_list[1::2])
print(max(max_total, max1, max2))
``` | instruction | 0 | 44,088 | 8 | 88,176 |
No | output | 1 | 44,088 | 8 | 88,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them.
After Bizon painted the fence he decided to put a "for sale" sign on it. The sign will be drawn on a rectangular piece of paper and placed on the fence so that the sides of the sign are parallel to the fence panels and are also aligned with the edges of some panels. Bizon the Champion introduced the following constraints for the sign position:
1. The width of the sign should be exactly w meters.
2. The sign must fit into the segment of the fence from the l-th to the r-th panels, inclusive (also, it can't exceed the fence's bound in vertical direction).
The sign will be really pretty, So Bizon the Champion wants the sign's height to be as large as possible.
You are given the description of the fence and several queries for placing sign. For each query print the maximum possible height of the sign that can be placed on the corresponding segment of the fence with the given fixed width of the sign.
Input
The first line of the input contains integer n — the number of panels in the fence (1 ≤ n ≤ 105).
The second line contains n space-separated integers hi, — the heights of the panels (1 ≤ hi ≤ 109).
The third line contains an integer m — the number of the queries (1 ≤ m ≤ 105).
The next m lines contain the descriptions of the queries, each query is represented by three integers l, r and w (1 ≤ l ≤ r ≤ n, 1 ≤ w ≤ r - l + 1) — the segment of the fence and the width of the sign respectively.
Output
For each query print the answer on a separate line — the maximum height of the sign that can be put in the corresponding segment of the fence with all the conditions being satisfied.
Examples
Input
5
1 2 2 3 3
3
2 5 3
2 5 2
1 5 5
Output
2
3
1
Note
The fence described in the sample looks as follows:
<image>
The possible positions for the signs for all queries are given below.
<image> The optimal position of the sign for the first query. <image> The optimal position of the sign for the second query. <image> The optimal position of the sign for the third query.
Submitted Solution:
```
lenn=input()
list_histogram=input().split()
lenq=int(input())
list_query=[]
for x in range(lenq) :
list_query.append(input().split())
for x in range (len(list_histogram)):
list_histogram[x]=int(list_histogram[x])
for x in range (len(list_query)):
for t in range (len(list_query[x])):
list_query[x][t]=int(list_query[x][t])
def getmax(l,r,w):
cutlist=list_histogram[(l-1):r]
lencut=len(cutlist)
nowmin = min(cutlist[0:w])
maxmin=nowmin
print(nowmin)
for n in range(lencut-w):
vout=cutlist[n]
vin=cutlist[n+w]
if vin<=nowmin :
nowmin=vin
elif vout==nowmin :
nowmin=min(cutlist[n+1:n+w+1])
if nowmin>maxmin :
maxmin=nowmin
print(nowmin)
print('*'+str(maxmin))
def getlrw(lia,n) :
return (lia[n][0],lia[n][1],lia[n][2])
for x in range(lenq) :
(l,r,w)=getlrw(list_query,x)
getmax(l,r,w)
``` | instruction | 0 | 44,225 | 8 | 88,450 |
No | output | 1 | 44,225 | 8 | 88,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n.
He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.
He wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?
Input
The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.
For each test case, the only line contains a single integer n (1 ≤ n ≤ 10^{9}).
Output
For each test case, print a single integer — the answer to the problem.
Example
Input
4
1
2
3
4
Output
1
1
2
2
Note
In the third case, he can connect two sticks with lengths 1 and 2 and he will get one stick with length 3. So, he will have two sticks with lengths 3.
In the fourth case, he can connect two sticks with lengths 1 and 3 and he will get one stick with length 4. After that, he will have three sticks with lengths \{2, 4, 4\}, so two sticks have the same length, and one stick has the other length.
Submitted Solution:
```
import collections as cc
import math as mt
I=lambda:list(map(int,input().split()))
for tc in range(int(input())):
n,=I()
if n==1:
print(1)
elif n==2:
print(1)
else:
if n%2==0:
print(n//2)
else:
print((n+1)//2)
``` | instruction | 0 | 44,764 | 8 | 89,528 |
Yes | output | 1 | 44,764 | 8 | 89,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,821 | 8 | 89,642 |
Tags: greedy, implementation
Correct Solution:
```
def check(heights, start):
if len(heights) == 1:
return heights[0] >= start
if heights[0] < start:
return False
else:
heights[1] += (heights[0] - start)
return check(heights[1:], start+1)
T = int(input())
for _ in range(T):
n = int(input())
heights = [int(h) for h in input().split()]
if check(heights, 0):
print('YES')
else:
print('NO')
``` | output | 1 | 44,821 | 8 | 89,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,822 | 8 | 89,644 |
Tags: greedy, implementation
Correct Solution:
```
import sys
# sys.setrecursionlimit(300000)
# Get out of main functoin
def main():
pass
# decimal to binary
def binary(n):
return (bin(n).replace("0b", ""))
# binary to decimal
def decimal(s):
return (int(s, 2))
# power of a number base 2
def pow2(n):
p = 0
while n > 1:
n //= 2
p += 1
return (p)
# if number is prime in √n time
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
# list to string ,no spaces
def lts(l):
s = ''.join(map(str, l))
return s
# String to list
def stl(s):
# for each character in string to list with no spaces -->
l = list(s)
# for space in string -->
# l=list(s.split(" "))
return l
# Returns list of numbers with a particular sum
def sq(a, target, arr=[]):
s = sum(arr)
if (s == target):
return arr
if (s >= target):
return
for i in range(len(a)):
n = a[i]
remaining = a[i + 1:]
ans = sq(remaining, target, arr + [n])
if (ans):
return ans
# Sieve for prime numbers in a range
def SieveOfEratosthenes(n):
cnt = 0
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
for p in range(2, n + 1):
if prime[p]:
cnt += 1
# print(p)
return (cnt)
# for positive integerse only
def nCr(n, r):
f = math.factorial
return f(n) // f(r) // f(n - r)
# 1000000007
mod = int(1e9) + 7
def ssinp(): return sys.stdin.readline().strip()
# s=input()
def iinp(): return int(input())
# n=int(input())
def nninp(): return map(int, sys.stdin.readline().strip().split())
# n, m, a=[int(x) for x in input().split()]
def llinp(): return list(map(int, sys.stdin.readline().strip().split()))
# a=list(map(int,input().split()))
def p(xyz): print(xyz)
def p2(a, b): print(a, b)
import math
########################list.sort(key=lambda x:x[1]) for sorting a list according to second element in sublist
#d1.setdefault(key, []).append(value)
###################ASCII of A-Z= 65-90
##########################ASCII of a-z= 97-122
#import random
#######################from collections import OrderedDict
#from fractions import Fraction
#=#####################===========Speed: STRING < LIST < SET,DICTIONARY==========================
#######################from collections import deque
for __ in range(iinp()):
n=iinp()
h=llinp()
prev=0
f=0
for i in range(n-1):
if(h[i]<prev):
f=1
break
elif(h[i]==prev):
prev+=1
else:
h[i+1]+=h[i]-prev
h[i]=prev
prev+=1
if(h[-1]>=prev and f==0):
print("YES")
else:
print("NO")
""" Stuff you should look for
int overflow, array bounds
special cases (n=1?)
do something instead of nothing and stay organized
WRITE STUFF DOWN
DON'T GET STUCK ON ONE APPROACH"""
``` | output | 1 | 44,822 | 8 | 89,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,823 | 8 | 89,646 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
st = list(map(int, input().split()))
n_sum = 0
for i in range(n):
c_sum = st[i] + n_sum
th = i
n_sum = c_sum - th
if n_sum < 0:
print("NO")
break
else:
print("YES")
``` | output | 1 | 44,823 | 8 | 89,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,824 | 8 | 89,648 |
Tags: greedy, implementation
Correct Solution:
```
def solve() -> bool:
n = int(input())
hs = input().split()
balance = 0
for i in range(0, n):
balance += int(hs[i])
balance -= i
if balance < 0:
return False
return True
if __name__ == '__main__':
t = int(input())
for _ in range(0, t):
ans = solve()
if ans:
print('YES')
else:
print('NO')
pass
``` | output | 1 | 44,824 | 8 | 89,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,825 | 8 | 89,650 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
need = 0
have = 0
ans = True
a = [int(i) for i in input().split()]
for j in range(n):
need += j
have += a[j]
if have < need:
ans = False
if ans:
print("YES")
else:
print("NO")
``` | output | 1 | 44,825 | 8 | 89,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,826 | 8 | 89,652 |
Tags: greedy, implementation
Correct Solution:
```
import sys
t = int(sys.stdin.readline())
for case in range(t):
n = int(input())
nums = [int(i) for i in sys.stdin.readline().split()]
can = True
for i in range(1,n):
nums[i] += (nums[i-1] - (i - 1))
if nums[i] <= i - 1:
can = False
break
if can:
sys.stdout.write("YES\n")
else:
sys.stdout.write("NO\n")
``` | output | 1 | 44,826 | 8 | 89,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,827 | 8 | 89,654 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
lis = list(map(int, input().split()))
carry = 1
flag = 1
for i in range(n):
carry = lis[i] - i + carry
if carry < 1:
flag = 2
break
print("NO" if flag == 2 else "YES")
``` | output | 1 | 44,827 | 8 | 89,655 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO. | instruction | 0 | 44,828 | 8 | 89,656 |
Tags: greedy, implementation
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
h = list(map(int, input().split()))
if n == 1:
print("YES")
continue
for i in range(1, n):
if sum(h[:i + 1]) < ((i + 1) * i) // 2:
print("NO")
break
else:
print("YES")
``` | output | 1 | 44,828 | 8 | 89,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
from itertools import permutations
#sys.setrecursionlimit(10**4)
#C:\Users\bittu\OneDrive\Documents\codeforces
I=sys.stdin.readline
#alpha="abcdefghijklmnopqrstuvwxyz"
"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
return int(I().strip())
def li():
return list(map(int,I().strip().split()))
def mi():
return map(int,I().strip().split())
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer // denom
def gcd(x, y):
while y:
x, y = y, x % y
return x
def isPrime(n):
if n<=1:
return False
elif n<=2:
return True
else:
for i in range(2,int(n**.5)+1):
if n%i==0:
return False
return True
def main():
ans=""
for _ in range(ii()):
n=ii()
arr=li()
tmp="YES"
for i in range(n-1):
if (arr[i]>=i):
extra=arr[i]-i
arr[i]-=extra
arr[i+1]+=extra
else:
tmp="NO"
if arr[n-1]<n-1:
tmp="NO"
ans+=tmp+"\n"
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 44,829 | 8 | 89,658 |
Yes | output | 1 | 44,829 | 8 | 89,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
#--------------------------x-IamRtSaurav-x--------------------------------#
t=int(input())
while(t>0):
t-=1
n=int(input())
lst=list(map(int,input().split()))
ex=0
cur=0
okay=True
for i in range(n):
if(lst[i]>=ex):
cur+=(lst[i]-ex)
elif(lst[i]<=ex):
cur+=lst[i]
if(cur>=ex):
cur=cur-ex
else:
okay=False
break
ex+=1
if(okay==True):
print("YES")
else:
print("NO")
``` | instruction | 0 | 44,830 | 8 | 89,660 |
Yes | output | 1 | 44,830 | 8 | 89,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
t = int(input())
for T in range(t):
n = int(input())
h = [int(x) for x in input().split()]
can_move = 0
if h[0] > 0:
can_move = h[0]
ans = 'YES'
for i in range(1, n):
## print(h[i] + can_move)
if h[i] + can_move < i:
ans = 'NO'
break
can_move += h[i] - i
print(ans)
``` | instruction | 0 | 44,831 | 8 | 89,662 |
Yes | output | 1 | 44,831 | 8 | 89,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
import sys
import math
input = sys.stdin.readline
t = int(input())
for test in range(t):
n = int(input())
#[a, b] = list(map(int, input().split(" ")))
h = list(map(int, input().split(" ")))
res = True
s=0
for i in range(1,n+1):
s+=h[i-1]
if s<(i-1)*i/2:
res=False
break
if res:
print('YES')
else:
print('NO')
``` | instruction | 0 | 44,832 | 8 | 89,664 |
Yes | output | 1 | 44,832 | 8 | 89,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
t = int(input())
while t:
n = int(input())
ls = list(map(int, input().split()))
if sum(ls)>=(n*(n-1)/2) and ls.count(0)<2:
print("YES")
else:
print("NO")
t-=1
``` | instruction | 0 | 44,833 | 8 | 89,666 |
No | output | 1 | 44,833 | 8 | 89,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
m = a[0]
for i in range(1, n):
m = max(m, a[i])
if m < i:
print("NO")
break
else:
print("YES")
``` | instruction | 0 | 44,834 | 8 | 89,668 |
No | output | 1 | 44,834 | 8 | 89,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
T=int(input())
for t in range(T):
n=int(input())
flag=False
a=list(map(int,input().split()))
sum=0
for i in range(n):
sum+=a[i]
if (sum<=i*(i-1)//2):
print("NO")
break
if(i==n-1):
flag=True
if(flag==True):
print("YES")
``` | instruction | 0 | 44,835 | 8 | 89,670 |
No | output | 1 | 44,835 | 8 | 89,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n stacks of blocks. The i-th stack contains h_i blocks and it's height is the number of blocks in it. In one move you can take a block from the i-th stack (if there is at least one block) and put it to the i + 1-th stack. Can you make the sequence of heights strictly increasing?
Note that the number of stacks always remains n: stacks don't disappear when they have 0 blocks.
Input
First line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
The first line of each test case contains a single integer n (1 ≤ n ≤ 100). The second line of each test case contains n integers h_i (0 ≤ h_i ≤ 10^9) — starting heights of the stacks.
It's guaranteed that the sum of all n does not exceed 10^4.
Output
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise.
You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
Example
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
Note
In the first test case there is no need to make any moves, the sequence of heights is already increasing.
In the second test case we need to move one block from the first stack to the second. Then the heights become 0 1.
In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights 3 4 5.
In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.
In the fifth test case we can only make one move (from the second to the third stack), which would make the heights 0 0 1. Both 0 1 0 and 0 0 1 are not increasing sequences, so the answer is NO.
Submitted Solution:
```
t=int(input())
for p in range(t):
n=int(input())
h=list(map(int,input().rstrip().split()))
sum=0
for i in range(n):
sum+=h[i]
if h.count(0)>=n-1 and sum<n-1:
print('no')
else:
print('yes')
``` | instruction | 0 | 44,836 | 8 | 89,672 |
No | output | 1 | 44,836 | 8 | 89,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
import sys
import math
import collections
from math import gcd
# from fractions import Fraction
# sys.setrecursionlimit(10**6)
# sys.setrecursionlimit(100000000)
inp =lambda: int(input())
strng =lambda: input().strip()
strl =lambda: list(input().strip()) #
mulf =lambda: map(float,input().strip().split()) #
seq =lambda: list(map(int,input().strip().split())) #
mod = (10**9)+7
input=sys.stdin.readline
# print("Hello, World!", flush=True)
# ord("A") chr(65)
t = inp()
for t1 in range(t):
n = inp()
s = strng()
d = {}
D = 0
K = 0
ans= []
for i in range(n):
if(s[i] == "D"):
D+=1
else:
K+= 1
if( K == 0):
temp = str(1)+" "+str(0)
d[temp] = d.get(temp,0)+1
ans.append(str(d[temp]))
elif(D == 0):
temp = str(0)+" "+str(1)
d[temp] = d.get(temp,0)+1
ans.append(str(d[temp]))
else:
g = gcd(D,K)
temp = str(D//g)+" "+str(K//g)
d[temp] = d.get(temp,0)+1
ans.append(str(d[temp]))
print(" ".join(ans), flush = True)
``` | instruction | 0 | 44,845 | 8 | 89,690 |
Yes | output | 1 | 44,845 | 8 | 89,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
def reducefract(n, d):
def gcd(n, d):
while d != 0:
t = d
d = n%d
n = t
return n
greatest=gcd(n,d)
n/=greatest
d/=greatest
return int(n), int(d)
for _ in range(int(input())):
dic = {}
n = int(input())
s = input()
cntd, cntk = 0, 0
for i in range(n):
if s[i] == "D":
cntd += 1
else:
cntk += 1
x, y = reducefract(cntd, cntk)
if (x, y) in dic:
dic[(x, y)] += 1
else:
dic[(x, y)] = 1
print(dic[(x, y)], end=" ")
print("\n")
``` | instruction | 0 | 44,846 | 8 | 89,692 |
Yes | output | 1 | 44,846 | 8 | 89,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
from sys import stdin
import math
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
s = stdin.readline()[:-1]
d, k = 0, 0
freq = {}
for i in s:
if i == 'D':
d += 1
else:
k += 1
x, y = d, k
g = math.gcd(x, y)
f = x//g, y//g
if f not in freq:
freq[f] = 0
freq[f] += 1
print(freq[f], end=" ")
print()
``` | instruction | 0 | 44,847 | 8 | 89,694 |
Yes | output | 1 | 44,847 | 8 | 89,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
from math import *
t=int(input())
for _ in range(t):
n=int(input())
s=input()
b={}
nD=0
nK=0
for i in range(len(s)):
if s[i]=="D":
nD+=1
elif s[i]=="K":
nK+=1
x=nD//gcd(nD,nK)
y=nK//gcd(nD,nK)
if (x,y) in b.keys():
b[(x,y)]+=1
else:
b[(x,y)]=1
print(b[(x,y)], end=" ")
print()
``` | instruction | 0 | 44,848 | 8 | 89,696 |
Yes | output | 1 | 44,848 | 8 | 89,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush,heappop,heapify
from itertools import permutations,combinations
from itertools import accumulate as ac
from random import randint as ri
mod = int(1e9)+7
ip = lambda : int(stdin.readline())
inp = lambda: map(int,stdin.readline().split())
ips = lambda: stdin.readline().rstrip()
out = lambda x : stdout.write(str(x)+"\n")
#ans = 'Case #{}: {}'.format(_+1,ans)
t = ip()
for _ in range(t):
n = ip()
s = ips()
p = Counter()
nn = n+1
ans = [0]*n
pref = [None]*n
for i in range(n):
p[s[i]] += 1
pref[i] = Counter(p)
for i in range(1,n+1):
a = pref[i-1]['D']
b = pref[i-1]['K']
for j in range(i,n+1,i):
c = pref[j-1]['D']
d = pref[j-1]['K']
if a*d == b*c:
times = j//i
ans[j-1] = max(ans[j-1],times)
else:
break
print(*ans)
``` | instruction | 0 | 44,849 | 8 | 89,698 |
No | output | 1 | 44,849 | 8 | 89,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
import sys
from math import gcd
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
def divisor(n): # nの約数全列挙
res = []
for i in range(1,int(n**.5)+1):
if n % i == 0:
res.append(i)
if i != n//i:
res.append(n//i)
return res
t = I()
for _ in range(t):
n = I()
T = S()
count_D = [0]*(n+1)
ANS = [set()]
for i in range(1,n+1):
t = T[i-1]
count_D[i] = count_D[i-1]
if t == 'D':
count_D[i] += 1
D = divisor(gcd(count_D[i],i-count_D[i]))
ans = set()
ans.add(1)
for d in D:
if d == 1:
continue
if count_D[i]-count_D[i-i//d] == count_D[i]//d:
if d-1 in ANS[i-i//d]:
ans.add(d)
ANS.append(ans)
ANS = [max(ANS[i]) for i in range(1,n+1)]
print(*ANS)
``` | instruction | 0 | 44,850 | 8 | 89,700 |
No | output | 1 | 44,850 | 8 | 89,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
import sys
import math
import heapq
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
input=stdin.readline
m=10**9+7
sys.setrecursionlimit(10**5)
T=int(input())
for _ in range(T):
n=int(input())
s=input().strip()
d=dd(list)
cd=dd(int)
ans=[]
for i in range(n):
cd[s[i]]+=1
d[i]=[cd['D'],cd['K']]
gc=math.gcd(cd['D'],cd['K'])
if gc==1 or cd['D']==0 or cd['K']==0:
ans.append(gc)
else:
inc=(cd['D']+cd['K'])//gc
rd,rk=cd['D']//gc,cd['K']//gc
pd,pk=0,0
f=1
for j in range(inc-1,i+1,inc):
#print(d[j])
ad,ak=d[j][0]-pd,d[j][1]-pk
if ad==rd and ak==rk:
pd,pk=d[j][0],d[j][1]
else:
f=0
break
if f:
ans.append(gc)
else:
ans.append(1)
print(*ans)
``` | instruction | 0 | 44,851 | 8 | 89,702 |
No | output | 1 | 44,851 | 8 | 89,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.
This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of n characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly 0) on this string, partitioning it into several contiguous pieces, each with length at least 1. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.
Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!
For a string we define a ratio as a:b where 'D' appears in it a times, and 'K' appears b times. Note that a or b can equal 0, but not both. Ratios a:b and c:d are considered equal if and only if a⋅ d = b⋅ c.
For example, for the string 'DDD' the ratio will be 3:0, for 'DKD' — 2:1, for 'DKK' — 1:2, and for 'KKKKDD' — 2:4. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.
The first line of each test case contains an integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of the wood.
The second line of each test case contains a string s of length n. Every character of s will be either 'D' or 'K'.
It is guaranteed that the sum of n over all test cases does not exceed 5 ⋅ 10^5.
Output
For each test case, output n space separated integers. The i-th of these numbers should equal the answer for the prefix s_{1},s_{2},...,s_{i}.
Example
Input
5
3
DDK
6
DDDDDD
4
DKDK
1
D
9
DKDKDDDDK
Output
1 2 1
1 2 3 4 5 6
1 1 1 2
1
1 1 1 2 1 2 1 1 3
Note
For the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.
For the second test case, you can split each prefix of length i into i blocks 'D'.
Submitted Solution:
```
ali=0;from collections import defaultdict, Counter;ali=0
ali=0;
ali=0;from math import sqrt, log10, log2, log, gcd, ceil, floor;ali=0
ali=0;
ali=0;from bisect import bisect_left, bisect_right;ali=0
ali=0;
ali=0;from itertools import permutations, combinations_with_replacement;ali=0
ali=0;
ali=0;import sys;ali=0
ali=0;
ali=0;import io;ali=0
ali=0;
ali=0;import os;ali=0
ali=0;
ali=0;input = sys.stdin.readline;ali=0
ali=0;
ali=0;# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline;ali=0
ali=0;
ali=0;# print=sys.stdout.write;ali=0
ali=0;
ali=0;sys.setrecursionlimit(10000);ali=0
ali=0;
ali=0;mod = int(pow(10, 7)+9);ali=0
ali=0;
ali=0;inf = float('inf');ali=0
ali=0;
def get_list():
ali=0;return [int(i) for i in input().split()];ali=0
ali=0;
def yn(a):
ali=0;print("YES" if a else "NO");ali=0
ali=0;
ali=0;t = 1;ali=0
ali=0;
for i in range(int(input())):
ali=0;n = int(input());ali=0
ali=0;
ali=0;s = input().strip();ali=0
ali=0;
ali=0;dcount = 0;ali=0
ali=0;
ali=0;kcount = 0;ali=0
ali=0;
for i in s:
ali=0;
if i == "D":
ali=0;dcount += 1;ali=0
ali=0;
else:
ali=0;kcount += 1;ali=0
ali=0;
ali=0;
if dcount == 0:
ali=0;answer = kcount;ali=0
ali=0;
elif kcount == 0:
ali=0;answer = dcount;ali=0
ali=0;
elif dcount >= kcount:
ali=0;
if dcount % kcount == 0:
ali=0;answer = kcount;ali=0
ali=0;
else:
ali=0;answer = 1;ali=0
ali=0;
else:
ali=0;
if kcount >= dcount:
ali=0;answer = dcount;ali=0
ali=0;
else:
ali=0;answer = 1;ali=0
ali=0;
ali=0;print(answer, end=" ");ali=0
ali=0;
ali=0;print();ali=0
ali=0;
``` | instruction | 0 | 44,852 | 8 | 89,704 |
No | output | 1 | 44,852 | 8 | 89,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,143 | 8 | 90,286 |
Tags: brute force, dp, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
s = list(map(int,input().split()))
c = list(map(int,input().split()))
d = {}
for i in range(n-1):
ans = 10**12
for j in range(i+1,n):
if s[i] < s[j]:
ans = min(ans,c[i]+c[j])
d[i] = ans
ans = 10**12
for i in range(n-2):
for j in range(i+1,n-1):
if s[i] < s[j]:
ans = min(ans,c[i]+d[j])
if ans == 10**12:
print(-1)
else:
print(ans)
``` | output | 1 | 45,143 | 8 | 90,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,144 | 8 | 90,288 |
Tags: brute force, dp, implementation
Correct Solution:
```
import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = float('inf')
for i in range(1, n-1):
bef = aft = float('inf')
for j in range(i):
if a[j] < a[i]:
bef = min(bef, b[j])
for j in range(i, n):
if a[i] < a[j]:
aft = min(aft, b[j])
ans = min(ans, b[i]+bef+aft)
print(-1 if ans > 10**9 else ans)
``` | output | 1 | 45,144 | 8 | 90,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,145 | 8 | 90,290 |
Tags: brute force, dp, implementation
Correct Solution:
```
n = int(input())
s = list(map(int, input().split()))
c = list(map(int, input().split()))
c_min = []
for i in range(n):
mini = int(10**18)
for j in range(i+1, n):
if s[i] < s[j]:
mini = min(mini, c[j])
c_min.append(mini)
res = int(10**18)
for i in range(n):
for j in range(i+1, n):
if s[i] < s[j]:
res = min(res, c[i]+c[j]+c_min[j])
print(-1 if res == int(10**18) else res)
``` | output | 1 | 45,145 | 8 | 90,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,146 | 8 | 90,292 |
Tags: brute force, dp, implementation
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sumi = []
for i in range(1,len(a)-1):
s = 10000000000
l = 10000000000
for j in range(i):
if(a[j]<a[i]):
k = b[i]+b[j]
if(s>k):
s = k
for j in range(i+1,len(a)):
if(a[j]>a[i]):
k = b[i]+b[j]
if(l>k):
l = k
sumi.append(s+l-b[i])
if(min(sumi)>=10000000000):
print(-1)
else:
print(min(sumi))
``` | output | 1 | 45,146 | 8 | 90,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,147 | 8 | 90,294 |
Tags: brute force, dp, implementation
Correct Solution:
```
# This code is contributed by Siddharth
# import sys
# input = sys.stdin.readline
# from sys import *
from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf=10**18
mod=10**9+7
# ==========================================> Code Starts Here <=====================================================================
n=int(input())
s=list(map(int,input().split()))
c=list(map(int,input().split()))
minn=inf
for j in range(1,n-1):
cost=c[j]
temp1=inf
temp2=inf
for i in range(j):
if s[i]<s[j]:
temp1=min(temp1,c[i])
for k in range(j+1,n):
if s[j]<s[k]:
temp2=min(temp2,c[k])
minn=min(temp1+temp2+cost,minn)
if minn<inf:
print(minn)
else:
print(-1)
``` | output | 1 | 45,147 | 8 | 90,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,148 | 8 | 90,296 |
Tags: brute force, dp, implementation
Correct Solution:
```
def f(n, S, C):
total = -1
for i in range(1, n-1):
l = (10 ** 8) + 100
for m in range(i-1, -1, -1):
if S[m] < S[i]:
l = min(l, C[m])
r = (10 ** 8) + 100
for o in range(i+1, n):
if S[o] > S[i]:
r = min(r, C[o])
if l == ((10**8)+100) or r == ((10 ** 8)+100): continue
elif total != -1: total = min(total, C[i]+r+l)
else: total = C[i]+r+l
return total
n = int(input())
S = [int(a) for a in input().split()]
C = [int(b) for b in input().split()]
print(f(n, S, C))
``` | output | 1 | 45,148 | 8 | 90,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,149 | 8 | 90,298 |
Tags: brute force, dp, implementation
Correct Solution:
```
R=lambda:list(map(int,input().split()))
I=3*10**8
n=int(input())
s,c=R(),R()
r=min(c[j]+min([I]+[c[i]for i in range(j)if
s[i]<s[j]])+min([I]+[c[i] for i in range(j+1,n)if
s[i]>s[j]])for j in range(1,n-1))
print((r,-1)[r>I])
``` | output | 1 | 45,149 | 8 | 90,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1. | instruction | 0 | 45,150 | 8 | 90,300 |
Tags: brute force, dp, implementation
Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
c=list(map(int,input().split()))
x=[0]
for i in range(1,n):
t=0
for j in range(i+1,n):
if s[j]>s[i]:
if t==0:
t=c[j]
else:
t=min(t,c[j])
x.append(t)
ans=-1
for i in range(n):
t=0
for j in range(i+1,n):
if s[j]>s[i] and x[j]!=0:
if ans==-1:
ans=c[j]+x[j]+c[i]
else:
ans=min(ans,c[j]+x[j]+c[i])
print(ans)
``` | output | 1 | 45,150 | 8 | 90,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1.
Submitted Solution:
```
from math import inf
n=int(input())
a=[int(i) for i in input().split()]
val=[int(i) for i in input().split()]
dp=[[inf for i in range(n)] for j in range(3)]
for i in range(n):
dp[0][i]=val[i]
for j in range(i):
if a[i]>a[j]:
dp[1][i]=min(dp[1][i],dp[0][j]+val[i])
dp[2][i]=min(dp[2][i],dp[1][j]+val[i])
m=inf
for i in range(n):
m=min(m,dp[2][i])
if m==inf:
print(-1)
else:
print(m)
``` | instruction | 0 | 45,151 | 8 | 90,302 |
Yes | output | 1 | 45,151 | 8 | 90,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1.
Submitted Solution:
```
n = int(input())
ss = list(map(int, input().strip().split()))
cs = list(map(int, input().strip().split()))
dp = [[float('inf')] * 4 for _ in range(n + 1)]
for i in range(1, n+1):
dp[i][1] = cs[i-1]
for i in range(2, n + 1):
for j in range(2, 4):
s, c = ss[i-1], cs[i-1]
for k in range(1, i):
if ss[k-1] < s:
dp[i][j] = min(dp[i][j], dp[k][j-1] + c)
#print(i, j, dp[i][j])
mmin = float('inf')
for i in range(1, 1+n):
mmin = min(mmin, dp[i][3])
if mmin == float('inf'):
print(-1)
else:
print(mmin)
``` | instruction | 0 | 45,152 | 8 | 90,304 |
Yes | output | 1 | 45,152 | 8 | 90,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1.
Submitted Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
m = 999999999
for i in range(1, n - 1):
m1 = 999999999
m2 = 999999999
ind1 = -1
ind2 = -1
for j in range(i):
if a[j] < a[i]:
if c[j] < m1:
m1 = c[j]
ind1 = j
for j in range(i + 1, n):
if a[i] < a[j]:
if c[j] < m2:
m2 = c[j]
ind2 = j
if ind1 != -1 and ind2 != -1:
m = min(m, c[ind1] + c[i] + c[ind2])
if m != 999999999: print(m)
else: print(-1)
``` | instruction | 0 | 45,153 | 8 | 90,306 |
Yes | output | 1 | 45,153 | 8 | 90,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1.
Submitted Solution:
```
def answer(n,A,B):
dp=[[float("inf") for i in range(n)] for j in range(3)]
dp[0][0]=B[0]
for i in range(3):
for j in range(1,n):
if i==0:
dp[i][j]=B[j]
else:
for k in range(j):
if A[j]>A[k]:
dp[i][j]=min(dp[i][j],dp[i-1][k]+B[j])
mini=min(dp[2])
if mini==float("inf"):
return -1
return mini
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
print(answer(n,A,B))
``` | instruction | 0 | 45,154 | 8 | 90,308 |
Yes | output | 1 | 45,154 | 8 | 90,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n displays placed along a road, and the i-th of them can display a text with font size s_i only. Maria Stepanovna wants to rent such three displays with indices i < j < k that the font size increases if you move along the road in a particular direction. Namely, the condition s_i < s_j < s_k should be held.
The rent cost is for the i-th display is c_i. Please determine the smallest cost Maria Stepanovna should pay.
Input
The first line contains a single integer n (3 ≤ n ≤ 3 000) — the number of displays.
The second line contains n integers s_1, s_2, …, s_n (1 ≤ s_i ≤ 10^9) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^8) — the rent costs for each display.
Output
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i < j < k such that s_i < s_j < s_k.
Examples
Input
5
2 4 5 4 10
40 30 20 10 40
Output
90
Input
3
100 101 100
2 4 5
Output
-1
Input
10
1 2 3 4 5 6 7 8 9 10
10 13 11 14 15 12 13 13 18 13
Output
33
Note
In the first example you can, for example, choose displays 1, 4 and 5, because s_1 < s_4 < s_5 (2 < 4 < 10), and the rent cost is 40 + 10 + 40 = 90.
In the second example you can't select a valid triple of indices, so the answer is -1.
Submitted Solution:
```
n = int(input())
s = list(map(int, input().split()))
c = list(map(int, input().split()))
cost = 999999999999999999999999999
if s == sorted(s):
c.sort()
print(sum(c[:3]))
else:
for i in range(n):
m = [999999999999999999999999999, -1]
for j in range(i):
if s[j] < s[i] and c[j] <= m[0]:
m[0] = c[j]
m[1] = j
m2 = [999999999999999999999999999, -1]
if m[1] != -1:
for j in range(i):
if s[j] < s[i] and c[j] <= m2[0] and ((j < m[1] and s[j] < s[m[1]]) or (j > m[1] and s[j] > s[m[1]])):
m2[0] = c[j]
m2[1] = j
if m[1] != -1 and m2[1] != -1:
cost = min(cost, c[i]+m[0]+m2[0])
if cost == 999999999999999999999999999:
print(-1)
else:
print(cost)
``` | instruction | 0 | 45,155 | 8 | 90,310 |
No | output | 1 | 45,155 | 8 | 90,311 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.