text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
from collections import deque
n = int(input())
grafs = dict()
xx = set();yy = set()
skautnes = []
for e in range(n):
x, y = map(int, input().split())
xx.add(str(x) + 'x');yy.add(str(y) + 'y')
skautnes.append( (str(x) + 'x',str(y) + 'y') )
for i in xx.union(yy):
grafs[i] = set()
for s in skautnes:
grafs[s[0]].add(s[1])
grafs[s[1]].add(s[0])
def bfs(grafs, root):
apmekletie = set(root)
rinda = deque([root])
while rinda:
tgd = rinda.popleft()
for neighbour in grafs[tgd]:
if neighbour not in apmekletie:
apmekletie.add(neighbour)
rinda.append(neighbour)
return(apmekletie)
dalas = []
apmekletasvirsotnes = set()
for e in grafs:
if e not in apmekletasvirsotnes:
dala = bfs(grafs, e)
dalas.append(dala)
apmekletasvirsotnes.update(dala)
print(len(dalas) - 1)
```
| 96,400 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
#start the code from here
n=int(input())
global parent
parent=[i for i in range(n)]
# n is total number of nodes
# finding parent of a node
def find(w):
global parent
if parent[w]==w:
return w
else:
return find(parent[w])
def union(a,b):
global parent
w=find(a)
y=find(b)
if w==y:
return
parent[y]=w
#start the code from here
l=[]
ans=0
for i in range(n):
a,b=map(int,input().split())
for u in range(len(l)):
if l[u][0]==a or l[u][1]==b:
union(u,i)
else:
ans+=1
l.append([a,b])
pset=set()
for i in range(len(l)):
pset.add(find(i))
print(len(pset)-1)
```
| 96,401 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
def dfs(node):
vis[node]=1
for i in range(n):
if (X[i]==X[node] or Y[i]==Y[node]) and vis[i]==0:
dfs(i)
r=[-1 for i in range(2005)]
n=int(input())
X,Y=[],[]
vis=[0]*101
for i in range(n):
x,y=map(int,input().split())
X.append(x)
Y.append(y)
ans=0
for i in range(n):
if (vis[i]==0):
dfs(i)
ans+=1
print(ans-1)
```
| 96,402 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
import collections
def breadth_first_search(graph, root):
visited = set()
visited.add(root)
queue = collections.deque([root])
while queue:
vertex = queue.popleft()
for neighbour in graph[vertex]:
if neighbour not in visited:
visited.add(neighbour)
queue.append(neighbour)
return visited
# The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts.
# Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
N = int(input())
drifts = []
xcoord = set()
ycoord = set()
for n in range(N):
xi, yi = map(int, input().split())
sxi = 'x' + str(xi)
xcoord.add(sxi)
syi = 'y' + str(yi)
ycoord.add(syi)
drifts.append( (sxi, syi) )
graph = dict()
for v in xcoord | ycoord:
graph[v] = set()
for e in drifts:
graph[e[0]].add(e[1])
graph[e[1]].add(e[0])
# print(graph)
parts = []
seen = set()
for v in graph:
if v not in seen:
area = breadth_first_search(graph, v)
parts.append(area)
seen.update(area)
print(len(parts) - 1)
```
| 96,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
def dfs_util(x, y):
if visit[x, y]:
return
visit[x, y] = 1
ix1, ix2 = bisect_left(xs[x], y), bisect_left(ys[y], x)
if ix1 < len(xs[x]) - 1:
dfs_util(x, xs[x][ix1 + 1])
if ix1 > 0:
dfs_util(x, xs[x][ix1 - 1])
if ix2 < len(ys[y]) - 1:
dfs_util(ys[y][ix2 + 1], y)
if ix2 > 0:
dfs_util(ys[y][ix2 - 1], y)
def dfs():
cnt = 0
for x, y in points:
if not visit[x, y]:
dfs_util(x, y)
cnt += 1
return cnt
from sys import *
from collections import *
from bisect import *
points, visit, xs, ys = [], defaultdict(int), defaultdict(list), defaultdict(list)
for i in range(int(input())):
x, y = arr_inp(1)
points.append([x, y])
insort_right(ys[y], x)
insort_right(xs[x], y)
print(dfs() - 1)
```
| 96,404 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
n=int(input())
ans=1
xl=[]
yl=[]
for i in range(n):
x,y=map(int,input().split())
xl.append({x})
yl.append({y})
for i in range(n-1):
for j in range(i+1,n):
if xl[i]&xl[j] or yl[i]&yl[j]:
xl[j]|=xl[i]
yl[j]|=yl[i]
ans+=1
break
print(n-ans)
# Made By Mostafa_Khaled
```
| 96,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
def iceskate():
n = int(input())
drifts = []
for i in range(n):
drifts.append(list(map(int,input().split())))
# print(drifts)
disconnected = []
app_index = 0
for j in drifts:
disconnected.append([app_index])
for k in drifts[drifts.index(j)+1:]:
if j[0] == k[0] or j[1] == k[1]:
disconnected[app_index].append(drifts.index(k))
app_index +=1
# print(disconnected)
disconnected = connectSets(disconnected,n)
# print(disconnected)
print(len(disconnected)-1)
def connectSets(disconnected,n):
freq = [-1]*n
i=0
while i < n:
delFlag = 0
for k in range(len(disconnected[i])):
if freq[disconnected[i][k]] >= i or freq[disconnected[i][k]] == -1:
freq[disconnected[i][k]] = i
else:
# print(disconnected[freq[i[k]]])
loc = freq[disconnected[i][k]]
delFlag = 1
break
if delFlag == 1:
# print('freq=', end =' ')
# print(freq)
# print(len(freq))
# print('disconnected=', end = ' ')
# print(disconnected)
# print(freq)
# print(loc)
# for k in range(len(disconnected[i])):
# freq[disconnected[i][k]] = min(loc, freq[disconnected[i][k]])
disconnected[loc] += disconnected[i]
del disconnected[i]
i = loc
n-=1
else:
i +=1
# print(freq)
return disconnected
iceskate()
```
| 96,406 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Tags: brute force, dfs and similar, dsu, graphs
Correct Solution:
```
n = int(input())
visited = set()
graph = {}
def dfs(node):
visited.add(node)
for neighbor in graph[node]:
if neighbor not in visited:
dfs(neighbor)
def is_connected(x, y):
return x[0] == y[0] or x[1] == y[1]
for i in range(n):
x, y = map(int, input().split())
neighbors = []
for node in graph:
if is_connected(node, (x, y)):
graph[node].append((x, y))
neighbors.append(node)
graph[(x, y)] = neighbors
components = 0
for node in graph:
if node not in visited:
components += 1
dfs(node)
print(components - 1)
```
| 96,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class UnionFind:
def __init__(self, size):
self.table = [-1 for _ in range(size)]
def find(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self.find(self.table[x])
return self.table[x]
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] <= self.table[s2]:
self.table[s1] += self.table[s2]
self.table[s2] = s1
else:
self.table[s2] += self.table[s1]
self.table[s1] = s2
return True
return False
def subsetall(self):
a = []
for i in range(len(self.table)):
if self.table[i] < 0:
a.append((i, -self.table[i]))
return a
def main():
n = I()
xy = [LI() for _ in range(n)]
uf = UnionFind(n)
for i in range(n):
x,y = xy[i]
for j in range(i+1,n):
a,b = xy[j]
if a == x or b == y:
uf.union(i,j)
r = 0
for i in range(n):
if uf.find(i) == i:
r += 1
return r - 1
print(main())
```
Yes
| 96,408 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
n=int(input())
store=[0]*(n+1)
l=[]
def dfs(node):
store[node]=1
for i in range(n):
if ((l[i][0]==l[node][0] or l[i][1]==l[node][1]) and store[i]==0):
dfs(i)
for i in range(n):
x,y=map(int,input().split())
l.append([x,y])
count=-1
for i in range(n):
if (not store[i]):
dfs(i)
count+=1
print(count)
```
Yes
| 96,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
def find(x):
if x == p[x]: return x
else:
p[x] = find(p[x])
return p[x]
def unite(a, b):
global count
a = find(a)
b = find(b)
if a != b:
p[a] = b;
count -= 1
n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]
count = len({graph[i][0] for i in range(n)})
p = [i for i in range(1001)]
for (a, b) in graph:
for (x, y) in graph:
if b == y: unite(a, x)
print(count - 1)
```
Yes
| 96,410 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
def main():
n = int(input())
nodes = []
connected = []
for _ in range(n):
nodes.append(list(map(int,input().split())))
for i in range(n-1):
for j in range(i+1,n):
if nodes[i][0] == nodes[j][0] or nodes[i][1] == nodes[j][1]:
set1 = -1
set2 = -1
for k in range(len(connected)):
if str(nodes[i]) in connected[k]:
set1 = k
if str(nodes[j]) in connected[k]:
set2 = k
if set1==set2 and set1>=0: continue
if set1 >= 0:
tmp = set1
set1 = connected[set1]
connected.remove(connected[tmp])
if set2 > tmp: set2 -= 1
else: set1 = {str(nodes[i])}
if set2 >= 0:
tmp = set2
set2 = connected[set2]
connected.remove(connected[tmp])
else: set2 = {str(nodes[j])}
connected.append(set1.union(set2))
else:
need_new_set_i = 1
need_new_set_j = 1
for k in range(len(connected)):
if str(nodes[i]) in connected[k]:
need_new_set_i = 0
if str(nodes[j]) in connected[k]:
need_new_set_j = 0
if need_new_set_i: connected.append({str(nodes[i])})
if need_new_set_j: connected.append({str(nodes[j])})
return len(connected) - 1 if len(connected) > 0 else 0
print(main())
```
Yes
| 96,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
def arr_inp(n):
if n == 1:
return [int(x) for x in stdin.readline().split()]
elif n == 2:
return [float(x) for x in stdin.readline().split()]
else:
return [str(x) for x in stdin.readline().split()]
from sys import *
from collections import *
mem, mem2 = defaultdict(int), defaultdict(int)
for i in range(int(input())):
x, y = arr_inp(1)
mem[x] += 1
mem2[y] = 1
print(len(mem2.values()) - max(mem.values()))
```
No
| 96,412 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
from collections import defaultdict
n=int(input())
x_,y_=[],[]
x1,y1=[],[]
for i in range(n):
x,y=map(int,input().split())
x_.append(x)
y_.append(y)
count=0
for i in range(n):
for j in range(i+1,n):
#print(x_[i],x_[j])
if x_[i]!=x_[j] and y_[i]!=y_[j] and x_[j] not in x1 and y_[j] not in y1:
count+=1
x1.append(x_[j])
y1.append(y_[j])
print(count)
```
No
| 96,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
def main():
n = int(input())
nodes = []
connected = []
for _ in range(n):
nodes.append(list(map(int,input().split())))
for i in range(n-1):
for j in range(i+1,n):
if nodes[i][0] == nodes[j][0] or nodes[i][1] == nodes[j][1]:
set1 = -1
set2 = -1
for k in range(len(connected)):
if str(nodes[i]) in connected[k]:
set1 = k
if str(nodes[j]) in connected[k]:
set2 = k
if set1==set2 and set1>=0: continue
if set1 >= 0:
tmp = set1
set1 = connected[set1]
connected.remove(connected[tmp])
if set2 > tmp: set2 -= 1
else: set1 = {str(nodes[i])}
if set2 >= 0:
tmp = set2
set2 = connected[set2]
connected.remove(connected[tmp])
else: set2 = {str(nodes[j])}
connected.append(set1.union(set2))
else:
need_new_set_i = 1
need_new_set_j = 1
for k in range(len(connected)):
if str(nodes[i]) in connected[k]:
need_new_set_i = 0
if str(nodes[j]) in connected[k]:
need_new_set_j = 0
if need_new_set_i: connected.append({str(nodes[i])})
if need_new_set_j: connected.append({str(nodes[j])})
return len(connected) - 1
print(main())
```
No
| 96,414 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.
Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.
Output
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Examples
Input
2
2 1
1 2
Output
1
Input
2
2 1
4 1
Output
0
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
aa = [LI() for _ in range(n)]
nn = len(aa[0])
r = inf
for i in range(n):
for j in range(nn-1):
t = abs(aa[i][j] - aa[i][j+1])
if r > t:
r = t
for j in range(n-1):
for i in range(nn):
t = abs(aa[j][i] - aa[j+1][i])
if r > t:
r = t
return r
print(main())
```
No
| 96,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Tags: constructive algorithms
Correct Solution:
```
n = 402
print (n)
print (0, 1000000)
for i in range(1, n-1):
print (i * 1000, n-i)
print (1000000, 1000000)
```
| 96,416 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Tags: constructive algorithms
Correct Solution:
```
print(302)
print("0 1000000")
coord, rad = 17321*2, 300
for i in range(300):
print(coord, rad)
coord, rad = coord+600, rad-1
print("1000000 1000000")
```
| 96,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Submitted Solution:
```
print(303)
print("0 1000000")
for i in range(1, 302):
print(i, i)
print("302 1000000")
```
No
| 96,418 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Submitted Solution:
```
print(302)
print("0 1000000")
coord, rad = 2000, 300
for i in range(300):
print(coord, rad)
coord, rad = coord+600, rad-1
print("1000000 1000000")
```
No
| 96,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Submitted Solution:
```
print(303)
print("0 1000000")
for i in range(1, 302):
print(i*(i+1)//2, i)
print("1000000 1000000")
```
No
| 96,420 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Martha — as a professional problemsetter — proposed a problem for a world-class contest. This is the problem statement:
Tomorrow is Nadia's birthday, and Bardia (her brother) is assigned to make the balloons ready!
There are n balloons (initially empty) that are tied to a straight line on certain positions x1, x2, ..., xn. Bardia inflates the balloons from left to right. As a result, i-th balloon gets bigger and bigger until its radius reaches the pressure endurance pi or it touches another previously-inflated balloon.
<image>
While Bardia was busy with the balloons, he wondered "What will be the sum of radius of balloons after all of the balloons are inflated?". Being a nerdy type of guy, he is now thinking about the problem instead of preparing his sister's birthday. Calculate the answer to Bardia's problem so that Nadia's birthday won't be balloon-less.
Artha — Martha's student — claimed his solution got accepted. Martha (being his teacher for a long time!) knew he couldn't have solved the problem for real and thus thinks there is something wrong with the testcases. Artha isn't anyhow logical, which means there is no way for Martha to explain the wrong point in his algorithm. So, the only way is to find a testcase to prove him wrong!
Artha's pseudo-code is shown below:
<image>
You should output a small testcase for the problem such that Artha's algorithm is incorrect. The algorithm's output is considered correct if it differs from the correct value by no more than 1.
Input
Please pay attention! No input will be given to your program for this problem. So you do not have to read from the input anything.
Output
You should output the generated small testcase (which Artha's solution doesn't get it right). It should be in the following format:
* First line must contain the only number n (1 ≤ n ≤ 500).
* The i-th of the next n lines should contain the description of the i-th balloon — two space-separated integers xi, pi (1 ≤ pi ≤ 106, 0 ≤ x1 < x2 < ... < xn ≤ 106).
Examples
Note
The testcase depicted in the figure above (just showing how output should be formatted):
4
0 9
6 3
12 7
17 1
Submitted Solution:
```
print(302)
print("0 1000000")
coord, rad = 17321, 300
for i in range(300):
print(coord, rad)
coord, rad = coord+600, rad-1
print("1000000 1000000")
```
No
| 96,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
import math
def countSteps(x, y):
# If y divides x, then simply
# return x/y.
if (x % y == 0):
return math.floor(x / y)
# Else recur. Note that this function
# works even if x is smaller than y
# because in that case first recursive
# call exchanges roles of x and y.
return math.floor((x / y) +
countSteps(y, x % y))
n = int(input())
c = []
for i in range(0,n):
x,y = map(int, input().rstrip().split())
count = countSteps(x,y)
c.append(count)
for i in range(0,len(c)):
print(c[i])
```
| 96,422 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
"""
A. Subtractions
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
"""
def subs(a,b):
if a > b:
a , b = b, a
if (b % a) == 0:
return b//a
else:
return b//a + subs(b % a, a)
count = int(input())
for _ in range(count):
a,b = input().split()
a = int(a)
b = int(b)
print(subs(a,b))
```
| 96,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
cases = int(input())
for i in range(cases):
a, b = map(int, input().split())
total = 0
while a > 0 and b > 0:
total += max(a, b) // min(a, b)
if a >= b:
a %= b
else:
b %= a
print(total)
```
| 96,424 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
operations = 0
a, b = max(a,b), min(a,b)
while b != 0:
operations += a//b
a -= a//b*b
a, b = max(a,b), min(a,b)
print(operations)
```
| 96,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
if a > b: a, b = b, a
s = 0
if a > 0:
s = b // a
a, b = b - s * a, a
while a > 0:
k = b // a
a, b = b - k * a, a
s += k
print(s)
```
| 96,426 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
T = int(input())
for t in range(T):
x, y = [int(n) for n in input().split()]
ops = 0
while x and y:
if x < y:
ops += int(y/x)
y = y % x
elif y < x:
ops += int(x/y)
x = x % y
else:
ops += 1
break
print(ops)
```
| 96,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
#!/usr/bin/env python3
N = int(input())
def ans(a, b):
if a == 0 or b == 0: return 0
return (a // b) + ans(b, a % b)
for _ in range(N):
a, b = input().split(' ')
a = int(a)
b = int(b)
print(ans(a, b))
```
| 96,428 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Tags: math, number theory
Correct Solution:
```
for i in range(int(input())):
a,b=map(int,input().split())
sm=0
while a and b:
sm+=a//b
t=b
b=a%b
a=t
print(sm)
```
| 96,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
cases = int(input())
while cases:
cases -= 1
a, b = map(int, input().split())
ans = 0
while a > 0 and b > 0:
if a < b:
a, b = b, a
ans += a//b
a = a % b
print(ans)
```
Yes
| 96,430 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
import sys
if __name__=='__main__':
# read input
numCases = int(sys.stdin.readline())
for i in range(numCases):
a, b = sys.stdin.readline().split()
a = int(a)
b = int(b)
total = 0
largerNum = max(a,b)
smallerNum = min(a,b)
while True:
div = int(largerNum/smallerNum)
total += div
rem = int(largerNum%(smallerNum*div))
if rem == 0:
break
else:
largerNum = smallerNum
smallerNum = rem
print(total)
```
Yes
| 96,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
def solve(a, b):
holder = [a, b]
times = 0
while holder[0] > 0 and holder[1] > 0:
smaller = 0 if holder[0] < holder[1] else 1
other = 1 - smaller
# how many times does smaller go into bigger?
times += holder[other] // holder[smaller]
# guaranteed to be smaller than `smaller` now
holder[other] = holder[other] % holder[smaller]
return times
def main():
cases = int(input())
for _ in range(cases):
a, b = map(int, input().split())
print(solve(a, b))
if __name__ == "__main__":
main()
```
Yes
| 96,432 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
for _ in range(int(input())):
a, b = map(int, input().split())
cn = 0
while ( a != 0 and b != 0):
cn+=b//a
a,b=b%a,a
print(cn)
```
Yes
| 96,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
def Main():
c = 0
n = int(input())
while n >= 1 :
x = input().split()
if (int(x[1]) - int(x[0])) > 1:
c += 1
n -= 1
print(c)
Main()
```
No
| 96,434 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
for i in range(int(input())):
a,b=list(map(int,input().split()))
c=0
while a>0 and b>0:
if max(a,b)%min(a,b)==0:
c+=max(a,b)/min(a,b)
break
else:
a=max(a,b)
b=min(a,b)
a-=b
c+=1
print(int(c))
```
No
| 96,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
for i in range(int(input())):
a = [int(i) for i in input().split()]
if(a[1]>a[0]):
ans = int(a[1]/a[0])+a[0]-(a[1]%a[0])+1
elif(a[1]<a[0]):
ans = int(a[0]/a[1])+a[1]-(a[0]%a[1])+1
else:
ans = 1
print(ans)
```
No
| 96,436 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
Input
2
4 17
7 987654321
Output
8
141093479
Submitted Solution:
```
from math import ceil
m=0
for _ in range(int(input())):
a,b=list(map(int,input().split()))
while a!=0 and b!=0:
if a>=b:
m+=a//b
a=a%b
else:
m+=b//a
b=b%a
print(m)
```
No
| 96,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
ssr = [0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51,1,2,1,14,1,2,2,14,1,6,1,4,2,2,1,52,2,5,1,5,1,15,2,13,2,2,1,13,1,2,4,267,1,4,1,5,1,4,1,50,1,2,3,4,1,6,1,52,15,2,1,15,1,2,1,12,1,10,1,4,2]
n = int(input())
print(ssr[n])
```
| 96,438 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
# oeis 000001
x = [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2]
print(x[int(input()) - 1])
```
| 96,439 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
pres = ["Washington",
"Adams",
"Jefferson",
"Madison",
"Monroe",
"Adams",
"Jackson",
"Van Buren",
"Harrison",
"Tyler",
"Polk",
"Taylor",
"Fillmore",
"Pierce",
"Buchanan",
"Lincoln",
"Johnson",
"Grant",
"Hayes",
"Garfield",
"Arthur",
"Cleveland",
"Harrison",
"Cleveland",
"McKinley",
"Roosevelt",
"Taft",
"Wilson",
"Harding",
"Coolidge",
"Hoover",
"Roosevelt",
"Truman",
"Eisenhower",
"Kennedy",
"Johnson",
"Nixon",
"Ford",
"Carter",
"Reagan",
"Bush",
"Clinton",
"Bush",
"Obama",
"Trump",
"Biden"]
print(pres[int(input())-1])
```
| 96,440 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
n=int(input())
if (n == 1) :
print ("Washington")
elif (n == 2):
print ("Adams")
elif (n == 3):
print ("Jefferson")
elif (n == 4):
print ("Madison")
elif (n == 5):
print ("Monroe")
elif (n == 6):
print ("Adams")
elif (n == 7):
print ("Jackson")
elif (n == 8):
print ("Van Buren")
elif (n == 9):
print("Harrison")
elif (n == 10):
print("Tyler")
elif (n == 11):
print("Polk")
elif (n == 12):
print("Taylor")
elif (n == 13):
print("Fillmore")
elif (n == 14):
print("Pierce")
elif (n == 15):
print("Buchanan")
elif (n == 16):
print ("Lincoln")
elif (n == 17):
print ("Johnson")
elif (n == 18):
print ("Grant")
elif (n == 19):
print ("Hayes")
elif (n == 20):
print ("Garfield")
elif (n == 21):
print ("Arthur")
elif (n == 22):
print ("Cleveland")
elif (n == 23):
print ("Harrison")
elif (n == 24):
print ("Cleveland")
elif (n == 25):
print ("McKinley")
elif (n == 26):
print ("Roosevelt")
elif (n == 27):
print ("Taft")
elif (n == 28):
print ("Wilson")
elif (n == 29):
print ('Harding')
elif (n == 30):
print ("Coolidge")
elif (n == 31):
print ("Hoover")
elif (n == 32):
print ("Roosevelt")
elif (n == 33):
print ("Truman")
elif (n == 34):
print ("Eisenhower")
elif (n == 35):
print ("Kennedy")
elif (n == 36):
print ("Johnson")
elif (n == 37):
print ("Nixon")
elif n == 38:
print ("Ford")
elif n == 39:
print ("Carter")
elif n == 40:
print ("Reagan")
```
| 96,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
a = ['Washington', 'Adams', 'Jefferson', 'Madison', 'Monroe', 'Adams', 'Jackson', 'Van Buren', 'Harrison', 'Tyler', 'Polk', 'Taylor', 'Fillmore', 'Pierce', 'Buchanan', 'Lincoln', 'Johnson', 'Grant', 'Hayes', 'Garfield', 'Arthur', 'Cleveland', 'Harrison', 'Cleveland', 'McKinley', 'Roosevelt', 'Taft', 'Wilson', 'Harding', 'Coolidge', 'Hoover', 'Roosevelt', 'Truman', 'Eisenhower', 'Kennedy', 'Johnson', 'Nixon', 'Ford', 'Carter', 'Reagan', 'Bush', '']
print(a[int(input()) - 1])
```
| 96,442 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
a=[0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51,1,2,1,14,1,2,2,14,1,6,1,4,2,2,1,52,2,5,1,5,1,15,2,13,2,2,1,13,1,2,4,267,1,4,1,5,1,4,1,50,1,2,3,4,1,6,1,52,15,2,1,15,1,2,1,12,1,10,1,4,2]
n=int(input())
print(a[n])
```
| 96,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
lis=[0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51,1,2,1,14,1,2,2,14,1,6,1,4,2,2,1,52,2,5,1,5,1,15,2,13,2,2,1,13,1,2,4,267,1,4,1,5,1,4,1,50,1,2,3,4,1,6,1,52,15,2,1,15,1,2,1,12,1,10,1,4,2]
print(lis[int(input())])
```
| 96,444 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Tags: *special, implementation
Correct Solution:
```
OeisA000001 = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2]
print(OeisA000001[int(input())])
```
| 96,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
"""
Codeforces April Fools Contest 2014 Problem F
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
res = inputs[:]
inputs[:] = []
while n > len(inputs):
inputs.extend(input().split(" "))
if n > 0:
res = inputs[:n]
inputs[:n] = []
return res
InputHandler = InputHandlerObject()
g = InputHandler.getInput
############################## SOLUTION ##############################
x = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267]
print(a[x-1])
```
Yes
| 96,446 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
print(["Washington","Adams","Jefferson","Madison","Monroe","Adams","Jackson","Van Buren","Harrison","Tyler","Polk","Taylor","Fillmore","Pierce","Buchanan","Lincoln","Johnson","Grant","Hayes","Garfield","Arthur","Cleveland","Harrison","Cleveland","McKinley","Roosevelt","Taft","Wilson","Harding","Coolidge","Hoover","Roosevelt","Truman","Eisenhower","Kennedy","Johnson","Nixon","Ford","Carter","Reagan","Bush"][int(input())-1])
```
Yes
| 96,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
a = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan"]
print(a[int(input())-1])
```
Yes
| 96,448 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267][int(input())-1])
```
Yes
| 96,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
a = round(int(input())**(1/2)//1)
if a == 8:
print(267)
else:
print(a)
```
No
| 96,450 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
from math import ceil,log2
n = int(input())
print(ceil(log2(n)))
```
No
| 96,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
from math import log2 as log
n=int(input())
if 2**int(log(n))==n:
print(int(log(n)))
else:
print(int(log(n))+1)
```
No
| 96,452 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Input
The input contains a single integer a (1 ≤ a ≤ 40).
Output
Output a single string.
Examples
Input
2
Output
Adams
Input
8
Output
Van Buren
Input
29
Output
Harding
Submitted Solution:
```
n = int(input())
if n%10 == n:
if n%2 == 0:
print(n//2)
else:
print(3*n +1)
elif (n%10) >= (n//10):
print((n%10)-(n//10))
else:
print((n%10)+(n//10))
```
No
| 96,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
s = input()
z = set()
us = 0
ans = 1
if s[0] == '?' or (s[0] >= 'A' and s[0] <= 'J'):
ans = 9
z.add(s[0])
if s[0] >= 'A' and s[0] <= 'J':
us += 1
i = -1
for x in s:
i += 1
if i == 0:
continue
if x == '?':
ans *= 10
if x >= 'A' and x <= 'J':
if x not in z:
ans *= (10 - us)
z.add(x)
us += 1
print(ans)
```
| 96,454 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
s = input()
ans = 1
l = list('ABCDEFGHIJ')
if s[0] == "?":
ans *= 9
elif s[0] in l:
ans *= 9
l.remove(s[0])
for i in s[1:]:
if i == "?":
ans *= 10
elif i in l:
ans *= len(l)
l.remove(i)
print(ans)
```
| 96,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
s = str(input())
result = 1
n = len(s)
rozne = set()
pytajniki = 0
mnoznik_z_pierwszego = 1
for i in range(0,n):
if ord(s[i]) >= ord('0') and ord(s[i]) <= ord('9'):
continue;
elif ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
rozne.add(ord(s[i]))
continue
else:
if i == 0:
mnoznik_z_pierwszego = 9
else:
pytajniki = pytajniki + 1
for i in range(0, len(rozne)):
result = result * (10 - i)
result = result * mnoznik_z_pierwszego
if ord(s[0]) >= ord('A') and ord(s[0]) <= ord('Z'):
result = result / 10 * 9
print(int(result), end="")
for i in range(pytajniki):
print("0", end="")
print()
```
| 96,456 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
import math
'''
r,c,n,k = map(int,input().split())
matrix = [['*' for row in range(c)] for column in range(r)]
for i in range(n):
x,y = map(int,input().split())
matrix[x-1][y-1] = '#'
ans = 0
for row1 in range(r):
for row2 in range(r):
if matrix[row1:row2+1].count('#') >= k:
ans+=1
for column1 in range(c):
for column2 in range(column1,c):
count = 0
for row in range(r):
count+=matrix[r][column1:column2+1].count('#')
if count >=k:
ans+=1
print(ans)
'''
s = input()
ques = s[1:].count('?')
d = {'A':0,'B':0,'C':0,'D':0,'E':0,'F':0,'G':0,'H':0,'I':0,'J':0}
digit = set([str(i) for i in range(0,10)])
digit.add('?')
ans = 1
ans*=pow(10,ques)
count =0
for i in range(1,len(s)):
if s[i] not in digit and d[s[i]] == 0:
count+=1
d[s[i]] = 1
start = 10
if s[0] in d and d[s[0]] == 1:
count-=1
ans*=9
start = 9
if s[0] in d and d[s[0]] == 0:
ans*=9
start = 9
while count!=0:
ans*=start
start-=1
count-=1
if s[0] == '?':
ans*=9
print(ans)
```
| 96,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
from sys import *
from math import *
s = stdin.readline().strip()
ans = 1
now = 10
was = {}
was['A'] = False
was['B'] = False
was['C'] = False
was['D'] = False
was['E'] = False
was['F'] = False
was['G'] = False
was['H'] = False
was['I'] = False
was['J'] = False
if s[0] == '?':
ans *= 9
if (ord(s[0]) >= ord('A')) and (ord(s[0]) <= ord('J')):
ans *= 9
was[s[0]] = True
now = 9
cnt = 0
for i in range(1, len(s)):
if s[i] == '?':
cnt += 1
if (ord(s[i]) >= ord('A')) and (ord(s[i]) <= ord('J')):
if was[s[i]] == False:
ans *= now
now -= 1
was[s[i]] = True
print(ans, end = "")
for i in range(cnt):
print('0', end = "")
print()
```
| 96,458 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
import math
import string
s = input()
p = 0
for x in string.ascii_uppercase[:10]:
if x in s:
p += 1
ans = 0
r = s.count('?')
if s[0] == '?':
ans = 9 * pow(10, r - 1) * math.factorial(10) // math.factorial(10 - p)
elif s[0] in string.ascii_uppercase:
ans = 9 * pow(10, r) * math.factorial(9) // math.factorial(9 - p + 1)
else:
ans = pow(10, r) * math.factorial(10) // math.factorial(10 - p)
print(ans)
```
| 96,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
s = input()
abc = [0] * 26
cnt1 = 0
cnt2 = 0
ans = 1
for i in range(len(s)):
if s[i] == '?':
if i == 0:
ans *= 9
else:
cnt2 += 1
elif (s[i] >= 'A') and (s[i] <= 'Z'):
if abc[(ord(s[i]) - ord('A'))] == 0:
if i == 0:
abc[(ord(s[i]) - ord('A'))] = 1
ans *= 9
cnt1 += 1
else:
abc[(ord(s[i]) - ord('A'))] = 1
ans *= (10 - cnt1)
cnt1 += 1
print(str(ans) + '0' * cnt2)
```
| 96,460 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Tags: greedy
Correct Solution:
```
I=input()
s=set()
r=I.count('?')
for x in I:
if ord(x)>64:s.add(x)
i=10
t=1
for _ in s:t*=i;i-=1
if r:t*=10;r-=1
if ord(I[0])>57:t=t//10*9
print(str(t)+'0'*r)
```
| 96,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import sys
s = input()
use = [0] * 30
diff = 0
for i in s:
c = ord(i) - ord('A')
if (0 <= c and c <= 25): use[c] = True
for i in range(0, 30):
if (use[i]): diff += 1
ans = 1
for i in range(10, 10 - diff, -1):
if (i == 10 and (ord('A') <= ord(s[0]) and ord(s[0]) <= ord('Z'))): ans *= 9
else: ans *= i
j = 0
for i in s:
if (i == '?'):
if (j == 0): ans *= 9
else: ans *= 10
j += 1
print(ans)
```
Yes
| 96,462 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import math
'''
r,c,n,k = map(int,input().split())
matrix = [['*' for row in range(c)] for column in range(r)]
for i in range(n):
x,y = map(int,input().split())
matrix[x-1][y-1] = '#'
ans = 0
for row1 in range(r):
for row2 in range(r):
if matrix[row1:row2+1].count('#') >= k:
ans+=1
for column1 in range(c):
for column2 in range(column1,c):
count = 0
for row in range(r):
count+=matrix[r][column1:column2+1].count('#')
if count >=k:
ans+=1
print(ans)
'''
s = input()
d = {'?':5,'1':5,'2':5,'3':5,'4':5,'5':5,'6':5,'7':5,'8':5,'9':5,'0':5,'A':0,\
'B':0,'C':0,'D':0,'E':0,'F':0,'G':0,'H':0,'I':0,'J':0}
digit = set([str(i) for i in range(0,10)])
digit.add('?')
ans = 1
count =0
for i in range(1,len(s)):
if d[s[i]] == 0:
count+=1
d[s[i]] = 1
elif s[i] == '?':
d[s[i]]+=1
ans*=pow(10,d['?']-5)
start = 10
if d[s[0]] == 1:
count-=1
ans*=9
start = 9
if d[s[0]] == 0:
ans*=9
start = 9
while count!=0:
ans*=start
start-=1
count-=1
if s[0] == '?':
ans*=9
print(ans)
```
Yes
| 96,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
def main():
hint = input()
hint_nodigits = [h for h in hint if not h.isdigit()]
letters = [h for h in hint_nodigits if h != '?']
combs_letters = 1
for i in range(10, 10 - len(set(letters)), -1):
combs_letters *= i
combs_jolly = 10 ** (len(hint_nodigits) - len(letters))
if hint[0] == '?':
combs_jolly = (combs_jolly // 10) * 9
elif hint[0].isalpha():
combs_letters = (combs_letters // 10) * 9
print(combs_letters * combs_jolly)
if __name__ == '__main__':
main()
```
Yes
| 96,464 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
#essi will come back as soon as possible
s = input()
si = len(s)
res = 1
seen = {}
Len = 0
if '0'<= s[0] <='9':
pass
else:
if s[0] == '?':
res *= 9
else:
res*= 9
seen[s[0]] = 1
Len+= 1
tmp = ""
for i in range(1, si):
if '0'<=s[i] <='9':
pass
else:
if s[i] != '?':
if seen.get(s[i], 0) == 0:
res*= (10 - Len)
seen[s[i]] = 1
Len+= 1
else:
pass
else:
tmp+= '0'
print(res, tmp, sep = "")
```
Yes
| 96,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
s = input()
l = []
n = '0123456789'
c = 1
z = True
for i in s:
if i == '?':
c*=10
elif i in n:
continue
else:
if i in l:
continue
else:
if z:
c *= 9
l.append(i)
else:
c *= (10 - len(l))
l.append(i)
z = False
print(c)
```
No
| 96,466 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
letras = [0 for i in range(10)]
s = input()
res = 1
for c in range(len(s)):
if s[c] == '?':
if c == 0:
res *= 9
else:
res*=10
if s[c].isalpha():
letras[ord(s[c])-65] += 1
cont = 10
for i in range(10):
if s[0].isalpha() and i == 0:
res *= 9
cont -=1
elif letras[i] != 0:
res *= cont
cont-=1
print(res)
```
No
| 96,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
s = input()
d = {}
for c in s:
if c == '?':
pass
elif not c.isdigit():
if c in d:
d[c] += 1
else:
d[c] = 1
if s[0] == '?':
print(9 * 10 ** (s.count('?') - 1) * math.factorial(10) // math.factorial(10 - len(d.keys())))
elif s[0].isalpha():
print(10 ** s.count('?') * 9 * math.factorial(9) // math.factorial(10 - len(d.keys())))
else:
print(10 ** s.count('?') * 10 ** len(d.keys()))
```
No
| 96,468 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.
The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.
And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:
* if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
* if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
* if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
* The length of the safe code coincides with the length of the hint.
For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".
After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.
At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...
Input
The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.
The input limits for scoring 30 points are (subproblem A1):
* 1 ≤ |s| ≤ 5.
The input limits for scoring 100 points are (subproblems A1+A2):
* 1 ≤ |s| ≤ 105.
Here |s| means the length of string s.
Output
Print the number of codes that match the given hint.
Examples
Input
AJ
Output
81
Input
1?AA
Output
100
Submitted Solution:
```
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
s = input()
d = {}
for c in s:
if c == '?':
pass
elif not c.isdigit():
if c in d:
d[c] += 1
else:
d[c] = 1
if s[0] == '?':
print(9 * 10 ** (s.count('?') - 1) * (11 - len(d.keys())) ** len(d.keys()))
elif s[0].isalpha():
print(10 ** s.count('?') * 9 * (11 - len(d.keys())) ** (len(d.keys()) - 1))
else:
print(10 ** s.count('?') * (11 - len(d.keys())) ** len(d.keys()))
```
No
| 96,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
n = int(input())
array = list(map(int, input().split()))
cnt = 0
s = [0 for i in range(n)]
s[n - 1] = 1 * (array[n - 1] == 0)
for i in range(n - 2, -1, -1):
s[i] = s[i + 1] + 1 * (array[i] == 0)
for i in range(n):
cnt += s[i] * (array[i] == 1)
print(cnt)
```
| 96,470 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
res = 0
b = 0
for i in reversed(range(n)):
if a[i]==1: res += b
else: b += 1
print(res)
```
| 96,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
from collections import *
from itertools import accumulate
def arr_sum(arr):
arr.appendleft(0)
return list(accumulate(arr, lambda x, y: x + y))
def solve():
ans1, ans0 = 0, 0
for i in range(n):
if a[i]:
ans1 += (n - (i + 1)) - (mem[-1] - mem[i + 1])
else:
ans0 += mem[i]
# print(ans0,ans1)
return min(ans0, ans1)
n, a = int(input()), deque(map(int, input().split()))
mem = arr_sum(a.copy())
print(solve())
```
| 96,472 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
zero_count = [0] * n
zero_count[n - 1] = int(arr[n - 1] == 0)
for i in reversed(range(n - 1)):
zero_count[i] = zero_count[i + 1] + int(arr[i] == 0)
res = 0
for i in range(n - 1):
if arr[i] == 1:
res += zero_count[i + 1]
print(res)
```
| 96,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
def cows(n, lst):
zeros, result = 0, 0
for i in range(n - 1, -1, -1):
if lst[i] == 0:
zeros += 1
else:
result += zeros
return result
m = int(input())
a = [int(j) for j in input().split()]
print(cows(m, a))
```
| 96,474 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
#in the name of god
#Mr_Rubick
n=int(input())
a=list(map(int,input().split()))
cnt,s=0,[0]*n
s[n-1]=1*(a[n-1]==0)
for i in range(n-2,-1,-1): s[i]=s[i+1]+1*(a[i]==0)
for i in range(n): cnt+=s[i]*(a[i]==1)
print(cnt)
```
| 96,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
from collections import *
from math import *
n = int(input())
a = list(map(int,input().split()))
ct0,res0 = 0,0
for i in range(n):
if(a[i] == 1): ct0 += 1
else: res0 += ct0
ct1,res1 = 0,0
for i in range(n-1,-1,-1):
if(a[i] == 0): ct1 += 1
else: res1 += ct1
print(min(res0,res1))
```
| 96,476 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Tags: data structures, greedy
Correct Solution:
```
n = int(input())
lis = list(map(int,input().split()))
ans=b=0
for i in range(n-1,-1,-1):
if lis[i]==1:
ans+=b
else:
b+=1
print(ans)
```
| 96,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Submitted Solution:
```
#in the name of god
#Mr_Rubick
'''n=int(input())
a=list(map(int,input().split()))
cnt,s=0,[0]*n
s[n-1]=1*(a[n-1]==0)
for i in range(n-2,-1,-1): s[i]=s[i+1]+1*(a[i]==0)
for i in range(n): cnt+=s[i]*(a[i]==1)
print(cnt)'''
n=int(input())
a=list(map(int,input().split()))
cnt1,cnt2=0,0
for i in range (n):
if a[i]==0:cnt1+=1
else:cnt2+=1
if abs(cnt1-cnt2)<=1:print(min(cnt1,cnt2))
else:print(min(cnt1,cnt2))
```
No
| 96,478 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Submitted Solution:
```
def cows(n, lst):
zeros, result = 0, 0
for i in range(n - 1, -1, 1):
if lst[i] == 0:
zeros += 1
else:
result += zeros
return result
m = int(input())
a = [int(j) for j in input().split()]
print(cows(m, a))
```
No
| 96,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
Input
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Output
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
Note
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
Submitted Solution:
```
#in the name of god
#Mr_Rubick
n=int(input())
a=list(map(int,input().split()))
cnt=0
s=[0]*n
if a[n-1]==0:
s[n-1]=1*a[n-1]
for i in range(n-2,-1,-1):
if a[i]==0:
s[i]=s[i+1]+1*a[i]
for i in range(n):
if a[i]==1:
cnt+=s[i]*a[i]
print(cnt)
```
No
| 96,480 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n = input()
falling_dir = input()
n = int(n, 10)
f = 0
start_pos = 0
fall_dir = "."
i = 0
for dir in falling_dir:
if dir == "R":
fall_dir = dir
start_pos = i
elif dir == "L":
k = i - start_pos
if fall_dir == ".":
f += k+1
else:
if k%2 == 0:
f += k
else:
f += k+1
fall_dir = "."
i += 1
# print("i = ", i-1, " f = ", f)
if fall_dir == "R":
k = n - start_pos
f += k
print(n-f)
```
| 96,481 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n=int(input())
x=input()
i=0
c=0
while i<n:
if x[i]=="L" or x[i]=="R":
if x[i]=="R":
c+=i
break
i+=1
if i==n:
for i in range(n):
if x[i]=="R":
break
print(i+1)
else:
j=i+1
while j<n:
if x[j]==".":
j+=1
elif x[i]==".":
i+=1
continue
elif x[i]=="R" and x[j]=="L":
if (j-i-1)%2==1:
c+=1
i=j
j+=1
elif x[i]=="L" and x[j]=="R":
c+=j-i-1
i=j
j+=1
if x[i]=="L" and x[-1]==".":
c+=j-i-1
print(c)
```
| 96,482 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n = int(input())
s = input().split('L')
ans = 0
if 'R' not in s[0]:
if len(s) != 1:
s = s[1:]
if 'R' in s[-1]:
s[-1] = s[-1][:s[-1].index('R')]
for sub in s:
if 'R' not in sub:
ans += len(sub)
else:
idx = sub.index('R')
ans += idx
ans += (len(sub) - idx - 1) % 2
print(ans)
```
| 96,483 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n = int(input())
string = input()
result = 0
if set(string) == {'.', }:
print(n)
else:
i = 0
met_1 = False
met_2 = False
start = 0
end = n-1
on = True
while i < n and not (met_1 and met_2):
# print("came in while")
# print(f"string[i] = {string[i]}")
# print(f"the result was {result}")
if string[i] != '.' and not met_1:
if string[i] == 'R':
result += i
start = i
met_1 = True
if string[n-1-i] != '.' and not met_2:
if string[n-1-i] == 'L':
result += i
end = n - i - 1
met_2 = True
# print(f"the result changed to {result}")
i += 1
if len(set(string)) == 2:
print(result)
else:
# print("The control came in the else.")
# print(f"start = {start} end = {end} result = {result}")
prev = start
i = start +1
while start < i <= end:
# print(f"prev = {prev} i = {i} string[i] = {string[i]}")
if string[prev] == "R" and string[i] == "L":
if (i - prev -1)%2 == 1:
result += 1
prev = i
elif string[prev] == "L" and string[i] == "R":
result += i - prev -1
prev = i
# print(f"the result changed to {result}")
i += 1
print(result)
```
| 96,484 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
N = int(input())
S = input()
A = [1 for i in range(N)]
mode = -1
ans = 0
for i in range(N):
c = S[i]
if(c=="L"):
if(mode==-1):
for k in range(i+1):
A[k]=0
else:
if(i-mode+1)%2==1:
ans+=1
for k in range(mode,i+1):
A[k]=0
mode = -1
elif(c=="R"):
mode = i
if(mode!=-1):
for k in range(mode,N):
A[k]=0
for i in range(N):
ans+=A[i]
print(ans)
```
| 96,485 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
n = int(input())
s = input().strip()
st = []
up = n
for i in range(n):
if s[i] == "L":
if not st:
up -= (i+1)
else:
length = i - st.pop() + 1
length -= length%2
up -= length
elif s[i] == "R":
st.append(i)
if st:
up -= (n - st.pop())
print(up)
```
| 96,486 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n = int(input())
s = input()
s = list(s)
v = 0
while(True):
lExits = False
rExits = False
if ('L' in s):
l = s.index('L')
lExits = True
if ('R' in s):
r = s.index('R')
rExits = True
if (lExits == False and rExits == False):
break
if (lExits == True and rExits == False):
for i in range(l+1):
s[i] = 'F'
break
if (lExits == False and rExits == True):
for i in range(r,n):
s[i] = 'F'
break
if (lExits == True and rExits == True):
if (l < r):
for i in range(l+1):
s[i] = 'F'
else:
for i in range(r,l+1):
s[i] = 'F'
if ((l - r) % 2 == 0):
s[r] = '.'
c = 0
for i in s:
if (i == '.'):
c += 1
print(c)
```
| 96,487 |
Provide a correct Python 3 solution for this coding contest problem.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
"Correct Solution:
```
n = int(input())
st = list(input())
ans = 0
i = 0
while st and i < len(st):
if st[i] == 'L':
n -= i + 1
st = st[i + 1:]
i = -1
elif st[i] == 'R':
n -= 1
j = i + 1
while j < len(st):
if st[j] == 'L':
n -= j - i
if (j - i) % 2 == 0:
n += 1
st = st[j + 1:]
i = -1
break
if st[j] == 'R':
n -= j - i - 1
st = st[j:]
i = -1
break
j += 1
else:
n -= j - i - 1
i += 1
print(n)
```
| 96,488 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
class Stack():
def __init__(self):
self.stack = []
self.len = 0
def top(self):
assert not self.empty()
return self.stack[self.len - 1]
def pop(self):
assert not self.empty()
self.len -= 1
return self.stack.pop()
def push(self, x):
self.len += 1
self.stack.append(x)
def empty(self):
return self.len == 0
def calc(n, pos):
st = Stack()
last_pos = -1
ans = 0
for i in range(n):
if pos[i] == "R":
if st.empty():
ans += i - last_pos - 1
st.push(i)
elif pos[i] == "L":
if st.empty():
last_pos = i
else:
left_R = st.pop();
ans += (i - left_R + 1) % 2
last_pos = i
if st.empty():
ans += n - last_pos - 1
return ans
n=int(input())
pos=str(input())
print(calc(n, pos))
```
Yes
| 96,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
n = int(input())
s = input()
c = n
k = 0
l, r = 0, 0
for i in range(n):
if s[i] == '.':
continue
if s[i] == 'L':
k -= 1
l = i
else:
k += 1
r = i
if k < 0:
c -= i + 1
k = 0
elif k == 0:
c -= (l - r + 1) - (l - r + 1) % 2
if k > 0:
c -= n - r
print(c)
```
Yes
| 96,490 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
n = int(input())
s = input()
t, res, prev = 0, 0, -1
for i in range(n):
if s[i] == 'R':
res += i - prev - 1
prev = i
t = 1
if s[i] == 'L':
if (prev != -1):
res += (i - prev - 1) % 2
prev = i
t = 0
if t == 0:
res += n - prev - 1
print(res)
```
Yes
| 96,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
import sys,math,heapq
from collections import defaultdict,Counter
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii(): return int(input())
n= ii()
a = la()
ans = 0
s = []
count = 0
for i in range(n):
# print(count , i,s,ans)
if a[i] == ".":
count += 1
elif a[i] == "L":
if s and s[-1] == "R":
ans += count%2
s = []
count = 0
elif a[i] == "R":
s.append("R")
ans += count
count = 0
# print(count)
if not s:
ans += count
print(ans)
```
Yes
| 96,492 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
n = int(input())
s = input()
falls = [0] * n
i = 0
ans = n
while i < len(s) and s[i] == '.':
i += 1
if i == len(s):
print(n)
else:
rr = s.rfind('R')
rl = s.rfind('L')
ll = s.find('L')
lr = s.find('R')
if (rr != -1) and (rl != -1) and (rr > rl):
ans -= (n - rr)
if (ll != -1) and (lr != -1) and (ll < lr):
ans -= (ll + 1)
#print(ans)
if (ll != -1) and (lr == -1):
print(rl + 1)
elif (ll == -1) and (lr != -1):
print(lr)
else:
s = s[lr:rl + 1]
ll = s.find('L')
lr = s.find('R')
#print(s, lr, ll, ans)
while (ll != -1) and (lr != -1):
ans -= (ll - lr)
if (lr - ll) % 2 != 0:
ans -= 1
s = s[ll + 1:]
ll = s.find('L')
lr = s.find('R')
#print(s, ll, lr, ans)
print(ans)
```
No
| 96,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
n=int(input())
l=input()
s=[]
t=[]
checkvalue=0
sum=0
for i in range(len(l)):
if l[i]=="L":
s.append(0)
elif l[i]=="R":
s.append(1)
if s==[]:
sum=n
else:
if s[0] == 1:
checkvalue = 1
for i in range(len(l)):
if l[i] == "L" or l[i] == "R":
t.append(i)
if len(t)==1:
if checkvalue==0:
sum= n - 1 - t[0]
else:
sum=t[0]
else:
for i in range(len(t) - 1):
if checkvalue == 0:
if i % 2 == 0:
sum += t[i + 1] - t[i] - 1
else:
sum += (t[i + 1] - t[i]) % 2
else:
if i % 2 == 1:
sum += t[i + 1] - t[i] - 1
else:
sum += (t[i + 1] - t[i]) % 2
if s[len(t) - 1] == 0:
sum += n - 1 - t[-1]
print(sum)
```
No
| 96,494 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())
count = 0
l, r = -1, 0
while True:
if l == -1:
if 'R' in s:
r = s.index('R')
if 'L' in s[:r]:
l = s.index('L')
count += r - l - 1
else:
count += r - 1
l = r
elif 'L' in s:
count = n - s.index('L') - 1
break
else:
count = n
break
else:
if s[l] == 'R':
if 'L' in s[l:]:
r += s[l:].index('L')
if (r - l - 1) & 1:
count += 1
l = r
else:
break
else:
if 'R' in s[l:]:
r += s[l:].index('R')
count += r - l - 1
l = r
else:
count += n - l -1
break
print(count)
```
No
| 96,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
<image>
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!
Input
The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
* "L", if the i-th domino has been pushed to the left;
* "R", if the i-th domino has been pushed to the right;
* ".", if the i-th domino has not been pushed.
It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".
Output
Output a single integer, the number of the dominoes that remain vertical at the end of the process.
Examples
Input
14
.L.R...LR..L..
Output
4
Input
5
R....
Output
0
Input
1
.
Output
1
Note
The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction.
Submitted Solution:
```
import sys
index = 0;
for line in sys.stdin:
total = 0;
start = False;
rtrig = False;
rcount = 0;
if(index == 0):
index += 1;
continue;
for i in range(len(line)):
if(not start):
if(line[i] == 'L'):
total += i + 1;
start = True;
if(line[i] == 'R'):
start = True;
elif(line[i] == "R"):
rcount = i;
elif(line[i] == "L"):
total += int((int((i - rcount + 1) / 2)) * 2);
sys.stdout.write(str(len(line) - total));
```
No
| 96,496 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
* choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);
* swap the elements on positions i and j; in other words, you are allowed to apply the following sequence of assignments: tmp = a[i], a[i] = a[j], a[j] = tmp (tmp is a temporary variable).
You do not need to minimize the number of used operations. However, you need to make sure that there are at most 5n operations.
Input
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).
Output
In the first line, print integer k (0 ≤ k ≤ 5n) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime).
If there are multiple answers, you can print any of them.
Examples
Input
3
3 2 1
Output
1
1 3
Input
2
1 2
Output
0
Input
4
4 2 3 1
Output
3
2 4
1 2
2 4
Tags: greedy, sortings
Correct Solution:
```
from sys import stdin,stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
N=10**5+5
primes=[1]*N
p=2
while p*p<=N:
if primes[p]:
for j in range(p*p,N,p):
primes[j]=0
p+=1
primes[0]=primes[1]=0
for i in range(2,N):
if primes[i]==0:
primes[i]=primes[i-1]
else:primes[i]=i
# print(primes[:20])
# def fn(ans):
# for p1,p2 in ans:
# aa[p1-1],aa[p2-1]=aa[p2-1],aa[p1-1]
# print(aa)
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
# aa=a.copy()
ind=[0]*(1+n)
for i in range(1,1+n):
ind[a[i-1]]=i
p=1
ans=[]
while p<=n:
pos=ind[p]
while pos>p:
near=primes[pos-p+1]
ans+=[[pos-near+1,pos]]
ind[a[pos-1]],ind[a[pos-near+1-1]]=ind[a[pos-near+1-1]],ind[a[pos-1]]
a[pos-1],a[pos-near+1-1]=a[pos-near+1-1],a[pos-1]
pos=pos-near+1
p+=1
print(len(ans))
for k,v in ans:
print(k,v)
# fn(ans)
```
| 96,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
* choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);
* swap the elements on positions i and j; in other words, you are allowed to apply the following sequence of assignments: tmp = a[i], a[i] = a[j], a[j] = tmp (tmp is a temporary variable).
You do not need to minimize the number of used operations. However, you need to make sure that there are at most 5n operations.
Input
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).
Output
In the first line, print integer k (0 ≤ k ≤ 5n) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime).
If there are multiple answers, you can print any of them.
Examples
Input
3
3 2 1
Output
1
1 3
Input
2
1 2
Output
0
Input
4
4 2 3 1
Output
3
2 4
1 2
2 4
Tags: greedy, sortings
Correct Solution:
```
def sieve(n):
prime = [-1]*(n+1)
for i in range(2,n+1):
if prime[i]==-1:
for j in range(i,n+1,i):
prime[j] = i
return prime
p = sieve(100010)
prime = []
for i in range(len(p)):
if p[i]==i:
prime.append(p[i])
# print (prime)
def find_prime(num):
low = 0
high = len(prime)-1
while low<high:
mid = (low+high)//2
if prime[mid]<num:
low = mid + 1
else:
high = mid - 1
if prime[low]<=num:
return prime[low]
else:
return prime[low-1]
def calc(ind):
ans = []
num = loc[arr[ind][0]]
while num-ind>0:
p = find_prime(num-ind+1)
# print (p, num, ind)
loc[a[num-p+1]], loc[a[num]] = loc[a[num]], loc[a[num-p+1]]
a[num], a[num-p+1] = a[num-p+1], a[num]
ans.append([num-p+2, num+1])
num -= p-1
return ans
n = int(input())
a = list(map(int,input().split()))
loc = {}
for i in range(n):
loc[a[i]] = i
arr = []
for i in range(n):
arr.append([a[i], i])
arr.sort()
i = 0
ans = []
while i<n:
if arr[i][0]==a[i]:
i += 1
continue
ans.extend(calc(i))
i += 1
# print (a)
# print (loc)
print (len(ans))
for i in ans:
print (*i)
```
| 96,498 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):
* choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);
* swap the elements on positions i and j; in other words, you are allowed to apply the following sequence of assignments: tmp = a[i], a[i] = a[j], a[j] = tmp (tmp is a temporary variable).
You do not need to minimize the number of used operations. However, you need to make sure that there are at most 5n operations.
Input
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).
Output
In the first line, print integer k (0 ≤ k ≤ 5n) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime).
If there are multiple answers, you can print any of them.
Examples
Input
3
3 2 1
Output
1
1 3
Input
2
1 2
Output
0
Input
4
4 2 3 1
Output
3
2 4
1 2
2 4
Tags: greedy, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,=I()
l=I()
an=[]
sv=[0]*(10**5+10)
for i in range(2,len(sv)):
if not sv[i]:
sv[i]=i
for j in range(2*i,len(sv),i):
sv[j]=1
sv[0]=sv[1]=1
for i in range(2,len(sv)):
if not sv[i]-1:
sv[i]=sv[i-1]
ix=[0]*(n+1)
for i in range(n):
ix[l[i]]=i
for i in range(n):
ct=0
while l[i]!=i+1 and ct<5:
cr=ix[i+1]
pr=sv[cr-i+1]
#print(i,cr,pr)
an.append(sorted([cr+1,cr-pr+2]))
l[cr],l[cr-pr+1]=l[cr-pr+1],l[cr]
ix[l[cr]],ix[l[cr-pr+1]]=ix[l[cr-pr+1]],ix[l[cr]]
ct+=1
print(len(an))
for i in an:
print(*i)
```
| 96,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.