text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
"Correct Solution:
```
MOD = 10**9+7
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
N,M,L,R = map(int,input().split())
P = [0 for i in range(R+1)]
Q = [0 for i in range(R+1)]
Z = [0 for i in range(R+1)]
for k in range(1,R+1):
u = (R-M*k)//k
for j in range(u+1):
P[k*j+M*k] += nCr(N-M,j)*(-1)**(j%2)
P[k*j+M*k] %= MOD
for k in range(R+1):
Q[k] += nCr(k+N,N)
Q[k] %= MOD
Z[k] += nCr(k+N,N)
Z[k] %= MOD
for k in range(R-M+1):
Q[k+M] -= nCr(k+N,N)
Q[k+M] %= MOD
def f(MAX):
ans = 0
for t in range(MAX+1):
ans += P[t]*Q[MAX-t]
ans %= MOD
return ans
def F(x):
return (Z[x]-nCr(N,M)*f(x))%MOD
print((F(R)-F(L-1))%MOD)
```
| 93,300 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
"Correct Solution:
```
MOD = 10**9+7
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
N,M,L,R = map(int,input().split())
P = [0 for i in range(R+1)]
for k in range(R+1):
u = (R-M*(k+1))//(k+1)
for j in range(u+1):
P[(k+1)*j+M*(k+1)] += nCr(N-M,j)*(-1)**(j%2)
P[(k+1)*j+M*(k+1)] %= MOD
for k in range(1,R+1):
u = (R-M*(k+1))//k
for j in range(u+1):
P[k*j+M*(k+1)] -= nCr(N-M,j)*(-1)**(j%2)
P[k*j+M*(k+1)] %= MOD
Q = [nCr(i+N,N) for i in range(R+1)]
def f(MAX):
ans = 0
for t in range(MAX+1):
ans += P[t]*Q[MAX-t]
ans %= MOD
return ans
def F(x):
return (Q[x]-nCr(N,M)*f(x))%MOD
print((F(R)-F(L-1))%MOD)
```
| 93,301 |
Provide a correct Python 3 solution for this coding contest problem.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
"Correct Solution:
```
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N,M,L,R = IL()
P = [0 for i in range(R+1)]
for k in range(R+1):
u = (R-M*(k+1))//(k+1)
for j in range(u+1):
P[(k+1)*j+M*(k+1)] += nCr(N-M,j)*(-1)**(j%2)
P[(k+1)*j+M*(k+1)] %= MOD
for k in range(1,R+1):
u = (R-M*(k+1))//k
for j in range(u+1):
P[k*j+M*(k+1)] -= nCr(N-M,j)*(-1)**(j%2)
P[k*j+M*(k+1)] %= MOD
"""
@lru_cache(maxsize=None)
def P(t):
ans = 0
for k in range(t+1):
u = t-M*(k+1)
if u>=0:
if u%(k+1) == 0:
ans += nCr(N-M,u//(k+1))*(-1)**((u//(k+1))%2)
ans %= MOD
for k in range(t+1):
u = t-M*(k+1)
if u>=0:
if k!=0:
if u%k == 0:
ans -= nCr(N-M,u//k)*(-1)**((u//k)%2)
ans %= MOD
return ans
"""
@lru_cache(maxsize=None)
def Q(t):
ans = nCr(t+N,N)
return ans
def f(MAX):
ans = 0
for t in range(MAX+1):
ans += P[t]*Q(MAX-t)
ans %= MOD
return ans
def F(x):
return (Q(x)-nCr(N,M)*f(x))%MOD
print((F(R)-F(L-1))%MOD)
```
| 93,302 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
Submitted Solution:
```
#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
for (int i = 0; i < (v.size()); i++) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
const long long MOD = TEN(9) + 7;
const int MX = TEN(6);
long long inv[MX], fact[MX], ifact[MX];
void init() {
inv[1] = 1;
for (int i = 2; i < MX; ++i) {
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
}
fact[0] = ifact[0] = 1;
for (int i = 1; i < MX; ++i) {
fact[i] = fact[i - 1] * i % MOD;
ifact[i] = ifact[i - 1] * inv[i] % MOD;
}
}
long long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}
long long solve_sub(int N, int M, int S, int r, int l) {
long long v = 0;
for (int i = 0; i <= N - M; ++i) {
long long rem = S - (long long)r * M - (long long)(l + 1) * i;
if (rem < 0) break;
long long t = comb(rem + N, N);
if (i % 2 == 1) {
t *= -1;
}
t = t * comb(N - M, i) % MOD;
if (t < 0) t += MOD;
v = (v + t) % MOD;
}
v = v * comb(N, M) % MOD;
return v;
}
long long solve(int N, int M, int S) {
long long all = comb(S + N, N);
long long ng = 0;
for (int x = 1; (long long)x * M <= S; ++x) {
long long a =
solve_sub(N, M, S, x, x - 1) - solve_sub(N, M, S, x + 1, x - 1);
ng = (ng + a) % MOD;
if (ng < 0) ng += MOD;
}
return (all - ng + MOD) % MOD;
}
int main() {
int N, M, L, R;
cin >> N >> M >> L >> R;
init();
long long ans = (solve(N, M, R) - solve(N, M, L - 1) + MOD) % MOD;
cout << ans << endl;
return 0;
}
```
No
| 93,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
Submitted Solution:
```
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N,M,L,R = IL()
@lru_cache(maxsize=None)
def P(t):
ans = 0
for k in range(t//M+1):
u = t-M*(k+1)
if u>=0:
if u%(k+1) == 0:
ans += nCr(N-M,u//(k+1))*(-1)**((u//(k+1))%2)
if k!=0:
if u%k == 0:
ans -= nCr(N-M,u//k)*(-1)**((u//k)%2)
ans %= MOD
return ans
@lru_cache(maxsize=None)
def Q(t):
ans = nCr(t+N,N)
return ans
def f(MAX):
ans = 0
for t in range(MAX+1):
ans += P(t)*Q(MAX-t)
ans %= MOD
return ans
def F(x):
return (Q(x)-nCr(N,M)*f(x))%MOD
print((F(R)-F(L-1))%MOD)
```
No
| 93,304 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
Submitted Solution:
```
import numpy as np
N,M,L,R = map(int,input().split())
MOD = 10 ** 9 + 7
U = 6*10**5 + 100
fact = [1] * (U+1)
for n in range(1,U+1):
fact[n] = fact[n-1]*n%MOD
fact_inv = [1] * (U+1)
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for n in range(U,0,-1):
fact_inv[n-1] = fact_inv[n] * n % MOD
fact = np.array(fact,dtype=np.int64)
fact_inv = np.array(fact_inv,dtype=np.int64)
U = N - M
comb = fact[U] * fact_inv[:U+1] % MOD * fact_inv[U::-1] % MOD
comb[1::2] *= (-1)
F = np.zeros(N+M+1,dtype=np.int64)
F[M:N+1] = comb
P = np.zeros(R+1,dtype=np.int64)
for i,x in enumerate(F[1:],1):
P[::i] += x
P[:M-1:-1] -= P[-M-1::-1]
P %= MOD
# (1-x)^{N+1}で割る
Q = fact[N:N+R+1] * fact_inv[:R+1] % MOD * fact_inv[N] % MOD
def f(R):
total = fact[R+N] * fact_inv[R] % MOD * fact_inv[N] % MOD
x = (Q[R::-1] * P[:R+1] % MOD).sum() % MOD
coef = fact[N] * fact_inv[M] % MOD * fact_inv[N-M] % MOD
return (total - x*coef)%MOD
answer = (f(R) - f(L-1))%MOD
print(answer)
```
No
| 93,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of sequences of N non-negative integers A_1, A_2, ..., A_N that satisfy the following conditions:
* L \leq A_1 + A_2 + ... + A_N \leq R
* When the N elements are sorted in non-increasing order, the M-th and (M+1)-th elements are equal.
Since the answer can be enormous, print it modulo 10^9+7.
Constraints
* All values in input are integers.
* 1 \leq M < N \leq 3 \times 10^5
* 1 \leq L \leq R \leq 3 \times 10^5
Input
Input is given from Standard Input in the following format:
N M L R
Output
Print the number of sequences of N non-negative integers, modulo 10^9+7.
Examples
Input
4 2 3 7
Output
105
Input
2 1 4 8
Output
3
Input
141592 6535 89793 238462
Output
933832916
Submitted Solution:
```
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N,M,L,R = IL()
M = max(M,N-M)
@lru_cache(maxsize=None)
def P(t):
ans = 0
for k in range(t//M+1):
u = t-M*(k+1)
if u>=0:
if u%(k+1) == 0:
ans += nCr(N-M,u//(k+1))*(-1)**((u//(k+1))%2)
if k!=0:
if u%k == 0:
ans -= nCr(N-M,u//k)*(-1)**((u//k)%2)
ans %= MOD
return ans
@lru_cache(maxsize=None)
def Q(t):
ans = nCr(t+N,N)
return ans
def f(MAX):
ans = 0
for t in range(MAX+1):
ans += P(t)*Q(MAX-t)
ans %= MOD
return ans
def F(x):
return (Q(x)-nCr(N,M)*f(x))%MOD
print((F(R)-F(L-1))%MOD)
```
No
| 93,306 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
n = int(input())
s = input()
k = int(input())
t = s[k-1]
s = [c if c == t else "*" for c in s]
print("".join(s))
```
| 93,307 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
n=int(input())
s=input()
k=int(input())
print(''.join([x if x==s[k-1] else '*' for x in s]))
```
| 93,308 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
N=int(input())
S=input()
t=S[int(input())-1]
ans = [i if i==t else "*" for i in S]
print("".join(ans))
```
| 93,309 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
n=int(input())
s=input()
k=int(input())
ans=""
for i in range(n):
ans+=((s[i],"*")[s[i]!=s[k-1]])
print(ans)
```
| 93,310 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
N = int(input())
S = input()
K = int(input())
Sk = S[K - 1]
print(''.join([s if s == Sk else '*' for s in S]))
```
| 93,311 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
n = int(input())
s = input()
k = int(input())
for r in s:
print(r if r == s[k-1] else "*",end="")
```
| 93,312 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
n=int(input())
l=list(input())
m=int(input())
for i in range(len(l)):
if l[i]!=l[m-1]:
l[i]="*"
print("".join(l))
```
| 93,313 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
"Correct Solution:
```
input()
s = input()
n = int(input())
print(*[i if i==s[n-1] else "*" for i in s], sep='')
```
| 93,314 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N = int(input())
S = input()
K = int(input())
sk = S[K-1]
print("".join([s if s == sk else "*" for s in S]))
```
Yes
| 93,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
import re
n = int(input())
s = input()
k = int(input())
target = s[k-1]
print(re.sub('[^' + s[k-1] + ']', '*', s))
```
Yes
| 93,316 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
import re
n = int(input())
s = input()
k = int(input())
ans = re.sub(rf'[^{s[k-1]}]', '*', s)
print(ans)
```
Yes
| 93,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N=int(input())
S= input()
K=int(input())
print(''.join(map(lambda s: '*' if s != S[K-1] else s, S)))
```
Yes
| 93,318 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
n = int(input())
str = input()
str =list(str)
str.append("a")
cs = int(input())
char = str[cs-1]
for i in range(n):
if str[i] != char:
str[i:i+1] = "*"
ans = str[0:n]
print(*ans)
```
No
| 93,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
N = int(input())
S = input()
K = int(input())
target = S[K - 1]
for i in range(N):
if S[i] != target:
S[i] = '*'
print(S)
```
No
| 93,320 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
k = int( input())
s = list(str(input()))
n = int( input())
for i in range(len(s)):
if s[i] != s[n-1]:
s[i] = "*"
print(s)
```
No
| 93,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Constraints
* 1 \leq K \leq N\leq 10
* S is a string of length N consisting of lowercase English letters.
* N and K are integers.
Input
Input is given from Standard Input in the following format:
N
S
K
Output
Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
Examples
Input
5
error
2
Output
*rr*r
Input
6
eleven
5
Output
e*e*e*
Input
9
education
7
Output
******i**
Submitted Solution:
```
S = int(input())
word = list(input())
K = int(input())
judge=word[K-1]
for i in range(S):
if word[i] == judge:
pass
else:
word[i] = '*'
print(" ".join(word))
```
No
| 93,322 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
S = input()
ans = min(abs(int(S[i:i+3]) - 753) for i in range(len(S) - 2))
print(ans)
```
| 93,323 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
s = input()
print(min(abs(int("".join(p)) - 753) for p in zip(s, s[1:], s[2:])))
```
| 93,324 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
n = input()
a = []
for i in range(len(n)-2):
a += [abs(int(n[i:i+3])-753)]
print(min(a))
```
| 93,325 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
a=input()
l=[]
for i in range(len(a)-2):
l.append(abs(753-int(a[i:i+3])))
print(min(l))
```
| 93,326 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
x=input();print(min(abs(int(x[i:i+3])-753)for i in range(len(x)-2)))
```
| 93,327 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
s=input()
ans=753
for i in range(len(s)-2):
ans=min(ans,abs(int(s[i:i+3])-753))
print(ans)
```
| 93,328 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
m=999
s=input()
for i in range(2,len(s)):
m=min(m,abs(753-int(s[i-2:i+1])))
print(m)
```
| 93,329 |
Provide a correct Python 3 solution for this coding contest problem.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
"Correct Solution:
```
S=input()
L=[abs(int(S[i:i+3]) - 753) for i in range(len(S)-2)]
print(min(L))
```
| 93,330 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
s=input();minn=1000
for i in range(len(s)-2):minn=min(abs(int(s[i:i+3])-753),minn)
print(minn)
```
Yes
| 93,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
data = input()
print(min([abs(int(data[i:(i+3)]) - 753) for i in range(len(data)-2)]))
```
Yes
| 93,332 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
S = input()
t = 1000
for s in range(len(S)-2):
t = min(abs(753 - int(S[s:s+3])),t)
print(t)
```
Yes
| 93,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
s=input()
ans=999
for i in range(len(s)-2):
ans=min(abs(753-int(s[i:i+3])),ans)
print(ans)
```
Yes
| 93,334 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
s=input()
import math
xlist=[math.abs(int(s[i:i+2])-753) for i in range(0,len(s)-3)]
print(min(xlist))
```
No
| 93,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
S=list(input())
X=753
ans=0
for i in range(0,8,1) :
for j in range(0,8,1) :
if int(S[i]) == j :
demo = int(S[i]+S[i+1]+S[i+2])
if demo >= ans :
ans = demo
print(abs(X-ans))
```
No
| 93,336 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
s = str(input())
ans = []
for i in range(len(s) - 2):
ans.append(abs(s[i:i+3]) - 753)
print(min(ans))
```
No
| 93,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a string S consisting of digits `1`, `2`, ..., `9`. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better. What is the minimum possible (absolute) difference between X and 753?
Constraints
* S is a string of length between 4 and 10 (inclusive).
* Each character in S is `1`, `2`, ..., or `9`.
Input
Input is given from Standard Input in the following format:
S
Output
Print the minimum possible difference between X and 753.
Examples
Input
1234567876
Output
34
Input
35753
Output
0
Input
1111111111
Output
642
Submitted Solution:
```
s=str(input())
ans=10**9
for i in range(len(s)-3):
ans=min(ans,abs(753-int(s[i:i+3])))
print(ans)
```
No
| 93,338 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
l = list(map(int,input().split()))
k = int(input())
print(sum(l)+max(l)*(2**k-1))
```
| 93,339 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
l=list(map(int,input().split()))
n=int(input())
print(sum(l)+max(l)*((2**n)-1))
```
| 93,340 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
A = [int(x) for x in input().split()]
K = int(input())
print(sum(A)+max(A)*(2**K-1))
```
| 93,341 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
num=list(map(int,input().split()))
print(sum(num)-max(num)+max(num)*2**int(input()))
```
| 93,342 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
a,b,c = sorted(map(int,input().split()))
k = int(input())
print(a + b + c*(2**k))
```
| 93,343 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
a,b,c = map(int,input().split())
k = int(input())
x = max(a,b,c)
print(a+b+c+x*2**k-x)
```
| 93,344 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
x=[int(i) for i in input().split()]
x.sort()
n=int(input())
print(x[2]*2**n+x[0]+x[1])
```
| 93,345 |
Provide a correct Python 3 solution for this coding contest problem.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
"Correct Solution:
```
A,B,C=map(int, input().split())
K=int(input())
a=max(A,B,C)
b=A+B+C-a
print(b+a*(2**K))
```
| 93,346 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
L=sorted(list(map(int,input().split())))
k=int(input())
L[-1]=L[-1]*(2**k)
print(sum(L))
```
Yes
| 93,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
L=list(map(int,input().split()))
K=int(input())
N=sorted(L)
print(N[0]+N[1]+N[2]*(2**K))
```
Yes
| 93,348 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
a, b, c, K = map(int, open(0).read().split())
m = max(a, b, c)
print(m*2**K+a+b+c-m)
```
Yes
| 93,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
a,b,c = map(int,input().split())
k = int(input())
print(max(a,b,c)*(2**k-1)+a+b+c)
```
Yes
| 93,350 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
a,b,c = map(int,input().split())
k = int(input())
m = a
count = 0
if b>m:
m=b
count=1
if c>m:
m=c
count=2
if count==0:
print(a**k+b+c)
if count==1:
print(a+b**k+c)
if count==2:
print(a+b+c**k)
```
No
| 93,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
n = list(map(int,input().split()))
k = int(input())
n.sort(reverse=True)
print(n[0]**k+n[1]+n[2])
```
No
| 93,352 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
A, B, C = map(int, input().split())
K = int(input())
print(max(A, B, C)*(2**K)+B+C)
```
No
| 93,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
* Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?
Constraints
* A, B and C are integers between 1 and 50 (inclusive).
* K is an integer between 1 and 10 (inclusive).
Input
Input is given from Standard Input in the following format:
A B C
K
Output
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
Examples
Input
5 3 11
1
Output
30
Input
3 3 4
2
Output
22
Submitted Solution:
```
a, b, c = map(int, input().split())
k = int(input())
m = max(a, b, c)
print(sum([a, b, c])-m+m*2*k)
```
No
| 93,354 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**6)
N = int(input())
*P, = map(int, input().split())
if N > 10:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
```
No
| 93,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 10:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
```
No
| 93,356 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 7:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 1
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
```
No
| 93,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a sequence p, which is a permutation of (0,1,2, ...,N-1). The i-th element (0-indexed) in p is p_i.
He can perform N-1 kinds of operations labeled 1,2,...,N-1 any number of times in any order. When the operation labeled k is executed, the procedure represented by the following code will be performed:
for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
He would like to sort p in increasing order using between 0 and 10^{5} operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.
Constraints
* 2 \leq N \leq 200
* 0 \leq p_i \leq N-1
* p is a permutation of (0,1,2,...,N-1).
Input
Input is given from Standard Input in the following format:
N
p_0 p_1 ... p_{N-1}
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the following m lines, print the label of the i-th executed operation. The solution will be accepted if m is at most 10^5 and p is in increasing order after the execution of the m operations.
Examples
Input
5
4 2 0 1 3
Output
4
2
3
1
2
Input
9
1 0 4 3 5 6 2 8 7
Output
11
3
6
1
3
5
2
4
7
8
6
3
Submitted Solution:
```
N = int(input())
*P, = map(int, input().split())
if N > 7:
exit(1)
memo = set()
*A, = range(N)
ans = []
def dfs(state):
key = tuple(state)
if key in memo:
return
if state == A:
return 1
memo.add(key)
for i in range(1, N):
n_state = state[:]
for j in range(i, N):
n_state[j], n_state[j-i] = n_state[j-i], n_state[j]
if dfs(n_state):
ans.append(i)
return 0
dfs(P)
print(len(ans))
for e in reversed(ans):
print(e)
```
No
| 93,358 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
import math
INF, MOD = float("inf"), 10 ** 9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]
def get_int():
return int(input())
def get_int_list():
return list(map(int, input().split()))
def mins(x, y):
x = min(x, y)
def maxs(x, y):
x = max(x, y)
def fact(n):
tmp = 1
for i in range(2, n + 1):
tmp = int(tmp * i % MOD)
return tmp
while(True):
try:
n, m = get_int_list()
if(n == m):
print(int(fact(n) ** 2 * 2 % MOD))
elif(abs(n - m) == 1):
print(int(fact(n) * fact(m) % MOD))
else:
print(0)
except EOFError:
exit()
```
| 93,359 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
import sys
import math
n, m = (int(i) for i in input().split())
l=abs(n-m)
div=int(10**9+7)
if l>1:
print(0)
sys.exit()
if l==1:
ans=(math.factorial(n)*math.factorial(m))%div
print(ans)
else:
ans=(math.factorial(n)*math.factorial(m)*2)%div
print(ans)
```
| 93,360 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
from math import factorial
N, M = map(int, input().split())
ans = factorial(N)*factorial(M)
if abs(N-M) == 1:
print(ans % (10**9+7))
elif N == M:
print((ans*2) % (10**9+7))
else:
print(0)
```
| 93,361 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
import math
f=math.factorial
n,m=map(int,input().split())
if abs(n-m)>1:
print("0")
elif abs(n-m)==1:
ans=f(n)*f(m)
ans%=1000000007
print(ans)
else:
ans=f(n)*f(m)
ans*=2;
ans%=1000000007
print(ans)
```
| 93,362 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
MOD = 10 ** 9 + 7
def kaijo(n):
k = 1
for i in range(1, n + 1):
k = k * i % MOD
return k
n, m = map(int, input().split())
if n == m:
print((kaijo(n) ** 2 * 2) % MOD)
elif abs(n - m) > 1:
print(0)
else:
print((kaijo(n) * kaijo(m)) % MOD)
```
| 93,363 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
n, m = map(int, input().split())
def fac(x):
ans = 1
for i in range(1, x + 1):
ans = (ans * i) % (10 ** 9 + 7)
return(ans)
if n < m:
n, m = m, n
if n - m >= 2:
print(0)
elif n - m == 1:
print((fac(m)) ** 2 * n % (10 ** 9 + 7) )
else:
print((fac(n)) ** 2 * 2 % (10 ** 9 + 7))
```
| 93,364 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
mod = 1000000007
N,M = map(int,input().split())
if abs(N-M)>1:
print(0)
else:
ans = 1
for i in range(1,N+1): ans = (ans*i)%mod
for j in range(1,M+1): ans = (ans*j)%mod
if N==M: ans = (ans*2)%mod
print(ans)
```
| 93,365 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
"Correct Solution:
```
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math
#n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]
#total=1
#if(n==m):
# total+=1
t = math.factorial(min(n,m))
#print(t)
#print(t**2)
if(abs(n-m)>1):
print(0)
elif(n==m):
print((2*(t**2))%1000000007)
else:
print(((t**2)*max(n,m))%1000000007)
```
| 93,366 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
from functools import reduce
n, m = map(int, input().split())
mod = 1000000007
def factorial(n):
return reduce(lambda x, y: x*y%mod, range(1, n+1))
if n==m:
print(2*factorial(n)*factorial(m)%mod)
elif abs(n-m)<=1:
print(factorial(n)*factorial(m)%mod)
else:
print(0)
```
Yes
| 93,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
import math
n, m = [int(i) for i in input().split()]
print(0 if abs(n-m) > 1 else (math.factorial(n) * math.factorial(m) * (2 if n == m else 1)) % int(1e9 + 7))
```
Yes
| 93,368 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
N,M = map(int,input().split())
p=10**9+7
def comb(a,p):
ini=1
for i in range(1,a+1):
ini = (ini*i)%p
return ini
if abs(N-M)>1:
ans=0
else:
if N!=M:
k=1
else:
k=2
dog=comb(N,p)
mon=comb(M,p)
tot=comb(N+M,p)
ans= (k*dog*mon)%p
print(ans)
```
Yes
| 93,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
from math import *
M,N=input().split(' ')
M=int(M)
N=int(N)
res=1
if M==N:
res=factorial(M)
res=res*res*2
elif M-N==1:
res=factorial(N)
res*=res*M
elif M-N==-1:
res=factorial(M)
res*=res*N
else:
res=0
print(res%(10**9+7))
```
Yes
| 93,370 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
import sys
sys.setrecursionlimit(100000)
d = 10**9 + 7
def factorial(n):
if (n > 1):
return (n % d) * factorial(n-1)
return 1
n, m = map(int, input().split())
ans = (factorial(n) % d) * (factorial(m) % d)
ans %= d
if n == m:
ans *= 2
print(ans)
```
No
| 93,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
n, m = map(int, input().split())
def fac(x):
ans = 1
for i in range(1, x + 1):
ans = ans * i
return(ans)
if n < m:
n, m = m, n
if n - m >= 2:
print(0)
elif n - m == 1:
print((fac(m)) ** 2 * n % (10 ** 9 + 7) )
else:
print((fac(n)) ** 2 * 2 % (10 ** 9 + 7))
```
No
| 93,372 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
M,N=input().split(' ')
M=int(M)
N=int(N)
res=1
if M==N:
for i in range(1, M+1):
res*=i
res=res*res*2
elif abs(M-N)==1:
for i in range(1, M+1):
res*=i
for i in range(1, N+1):
res*=i
else:
res=0
print(res%(10**9+7))
```
No
| 93,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
Constraints
* 1 ≤ N,M ≤ 10^5
Input
Input is given from Standard Input in the following format:
N M
Output
Print the number of possible arrangements, modulo 10^9+7.
Examples
Input
2 2
Output
8
Input
3 2
Output
12
Input
1 8
Output
0
Input
100000 100000
Output
530123477
Submitted Solution:
```
# -*- coding: utf-8 -*-
#ARC076C
import sys
import math
#n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]
total=1
if(n==m):
total+=1
if(abs(n-m)>1):
print(0)
else:
print(total*math.factorial(n)*math.factorial(m))
```
No
| 93,374 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
sx, sy, tx, ty = map(int, input().split(' '))
h = ty - sy
w = tx - sx
p = 'U'*h+'R'*w
r = 'D'*h+'L'*w
print(p+r+'LU'+p+'RDRD'+r+'LU')
```
| 93,375 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
sx, sy, tx, ty = map(int, input().split())
x = tx-sx
y = ty-sy
print("R"*(x) + "U"*(y) + "L"*(x) + "D"*(y+1) + "R"*(x+1) + "U"*(y+1) + "LU" + "L"*(x+1) + "D"*(y+1) + "R")
```
| 93,376 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
sx, sy, tx, ty = (int(i) for i in input().split())
w = tx-sx
h = ty-sy
res = "U"*h+"R"*w+"D"*h+"L"*(w+1)+"U"*(h+1)+"R"*(w+1)+"DR"+"D"*(h+1)+"L"*(w+1)+"U"
print(res)
```
| 93,377 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
a,b,c,d = map(int,input().split())
x=c-a
y=d-b
print('R'*x+'U'*(y+1)+'L'*(x+1)+'D'*(y+1)+'R'+'U'*y+'R'*(x+1)+'D'*(y+1)+'L'*(x+1)+'U')
```
| 93,378 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
sx,sy,tx,ty=[int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print("R"*dx+"U"*dy+"L"*dx+"D"*(dy+1)+"R"*(dx+1)+"U"*(dy+1)+"LU"+"L"*(dx+1)+"D"*(dy+1)+"R")
```
| 93,379 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
SX,SY,TX,TY=map(int,input().split())
x=TX-SX
y=TY-SY
print(''.join(['U'*y,'R'*x,'D'*y,'L'*x,'L','U'*(y+1),'R'*(x+1),'D','R','D'*(y+1),'L'*(x+1),'U']))
```
| 93,380 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
sx, sy, tx, ty = [int(x) for x in input().split()]
dx=tx-sx
dy=ty-sy
print('R'*dx+'U'*dy+'L'*dx+'D'*(dy+1)+'R'*(dx+1)+'U'*(dy+1)+'L'+'U'+'L'*(dx+1)+'D'*(dy+1)+'R')
```
| 93,381 |
Provide a correct Python 3 solution for this coding contest problem.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
"Correct Solution:
```
a,b,c,d = list(map(int,input().split()))
a = c-a
b = d-b
print('R'*a+'U'*b+'L'*a+'D'*(b+1)+'R'*(a+1)+'U'*(b+1)
+'L'+'U'+'L'*(a+1)+'D'*(b+1)+'R')
```
| 93,382 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty = map(int,input().split())
x,y = tx-sx,ty-sy
ans = "R"*x + "U"*y + "L"*x + "D"*y + "D" +"R"*(x+1) + "U"*(y+1) + "LU" + "L"*(x+1) + "D"*(y+1) + "R"
print(ans)
```
Yes
| 93,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
a,b,c,d = map(int,input().split())
dx = c-a
dy = d-b
print('U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U')
```
Yes
| 93,384 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3
m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)*"D"
print(m1+m2+"DR"+m1+"ULUL"+m2+"DR")
```
Yes
| 93,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
a,b,c,d=map(int,input().split())
X=c-a
Y=d-b
ans1='R'*X+'U'*Y
ans2='L'*X+'D'*Y
ans3='D'+'R'*(X+1)+'U'*(Y+1)+'L'
ans4='U'+'L'*(X+1)+'D'*(Y+1)+'R'
print(ans1+ans2+ans3+ans4)
```
Yes
| 93,386 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
X=list(map(int,input().split()))
#X軸に並行
if X[2]-X[0]==0:
if X[3]-X[1]>0:
q=X[3]-X[1]
U="U"
D="D"
else:
q=X[1]-X[3]
U="U"
D="D"
print(U*(q+1)+R*2+D*(q+2)+L*2+U+L+U*q+R*2+D*q+L)
#Y軸に並行
if X[3]-X[1]==0:
if X[2]-X[0]>0:
p=X[2]-X[0]
R="R"
L="L"
else:
p=X[0]-X[2]
R="L"
L="R"
print(R*(p+1)+U*2+L*(p+2)+D*2+R+D+R*p+U*2+L*p+D)
if (X[2]-X[0]!=0 and X[3]-X[1]!=0):
if X[2]-X[0]>0:
p=X[2]-X[0]
R="R"
L="L"
else:
p=X[0]-X[2]
R="L"
L="R"
if X[3]-X[1]>0:
q=X[3]-X[1]
U="U"
D="D"
else:
q=X[1]-X[3]
U="D"
D="U"
print(U*p+R*(q+1)+D*(p+1)+L*(q+1)+U+L+U*(p+1)+R*(q+1)+D*(p+1)+L*q)
```
No
| 93,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx,sy,tx,ty=map(int,input().split())
nx=tx-sx
ny=ty-sy
ans=""
R1="U"*ny + "R"*nx + "D"*ny + "L"*nx
R2="D" + "R"*(nx + 1) + "U"*(ny + 1) +"R" + "U" + "L"*(nx + 1) +"D"*(ny + 1) + "R"
print(R1+R2)
```
No
| 93,388 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
ret=''
for i in range(tx-sx):
ret=ret+'U'
for i in range(ty-sy):
ret=ret+'R'
for i in range(tx-sx):
ret=ret+'D'
import sys
inp=sys.stdin.readline()
sx,sy,tx,ty=map(lambda x: int(x), inp.split(' '))
for i in range(ty-sy+1):
ret=ret+'L'
for i in range(tx-sx+1):
ret=ret+'U'
for i in range(ty-sy+1):
ret=ret+'R'
ret=ret+'DR'
for i in range(tx-sx+1):
ret=ret+'D'
for i in range(ty-sy+1):
ret=ret+'L'
ret=ret+'U'
```
No
| 93,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
Here, both the x- and y-coordinates before and after each movement must be integers.
He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
Under this condition, find a shortest path for him.
Constraints
* -1000 ≤ sx < tx ≤ 1000
* -1000 ≤ sy < ty ≤ 1000
* sx,sy,tx and ty are integers.
Input
The input is given from Standard Input in the following format:
sx sy tx ty
Output
Print a string S that represents a shortest path for Dolphin.
The i-th character in S should correspond to his i-th movement.
The directions of the movements should be indicated by the following characters:
* `U`: Up
* `D`: Down
* `L`: Left
* `R`: Right
If there exist multiple shortest paths under the condition, print any of them.
Examples
Input
0 0 1 2
Output
UURDDLLUUURRDRDDDLLU
Input
-2 -2 1 1
Output
UURRURRDDDLLDLLULUUURRURRDDDLLDL
Submitted Solution:
```
sx, sy, tx, ty = map(int, input().split())
ans = 'R'*(tx-sx) + 'U'*(ty-sy) + 'L'*(tx-sx) + 'D'*(ty-sy)
ans += 'D'*1 + 'R'*(tx-sx+1) + 'U'*(ty-sy+1) + 'L' * 1 + 'U' * 1 + 'L' * (tx-sy+1) + 'D'*(ty-sy+1) + 'R'*1
print(ans)
```
No
| 93,390 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
import sys,heapq
from collections import defaultdict,deque
input = sys.stdin.readline
n,m = map(int,input().split())
#+路線*chg : その路線ホーム
chg = 10**6
edge=defaultdict(set)
used =defaultdict(bool)
for i in range(m):
p,q,c = map(int,input().split())
edge[p].add(p+c*chg)
edge[p+c*chg].add(p)
edge[p+c*chg].add(q+c*chg)
edge[q+c*chg].add(p+c*chg)
edge[q].add(q+c*chg)
edge[q+c*chg].add(q)
used[p] = False
used[q] = False
used[p+c*chg] = False
used[q+c*chg] = False
edgelist = deque()
edgelist.append((1,0))
res = float("inf")
while len(edgelist):
x,cost = edgelist.pop()
used[x] = True
if x == n:
res = cost
break
for e in edge[x]:
if used[e]:
continue
#ホーム→改札
if x <= 10**5 and chg <= e:
edgelist.appendleft((e,cost+1))
else:
edgelist.append((e,cost))
if res == float("inf"):
print(-1)
else:
print(res)
```
| 93,391 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import defaultdict
"""
(駅、会社)を頂点にグラフを持つ。頂点数O(M)。
そのまま辺を貼ると辺が多くなりすぎる。
(駅、会社) -> (駅、無属性) -> (駅、会社)
"""
L = 32
mask = (1 << L) - 1
N,M = map(int,input().split())
graph = defaultdict(list)
for _ in range(M):
p,q,c = map(int,input().split())
p <<= L
q <<= L
graph[p].append(p+c)
graph[p+c].append(p)
graph[q].append(q+c)
graph[q+c].append(q)
graph[p+c].append(q+c)
graph[q+c].append(p+c)
INF = 10 ** 9
dist = defaultdict(lambda: INF)
start = 1 << L
goal = N << L
q = [start] # 0 が会社に属していない状態
dist[start] = 0
d = 0
while q:
qq = []
while q:
x = q.pop()
if x & mask == 0:
for y in graph[x]:
if dist[y] <= d + 1:
continue
dist[y] = d + 1
qq.append(y)
else:
for y in graph[x]:
if dist[y] <= d:
continue
dist[y] = d
q.append(y)
d += 1
q = qq
answer = dist[goal]
if answer == INF:
answer = -1
print(answer)
```
| 93,392 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
from collections import deque
def solve():
dist = [inf] * len(to)
q = deque()
q.append((0, 0))
dist[0] = 0
while q:
d, i = q.popleft()
if d > dist[i]: continue
if i < n:
for j in to[i]:
if dist[j] <= d + 1: continue
dist[j] = d + 1
q.append((d + 1, j))
else:
for j in to[i]:
if j == n - 1:
print(dist[i])
exit()
if dist[j] <= d: continue
dist[j] = d
q.appendleft((d, j))
print(-1)
inf=10**9
n,m=MI()
to=[]
uctoi={}
for u in range(n):
to.append([])
uctoi[u,0]=u
for _ in range(m):
u,v,c=MI()
u,v=u-1,v-1
if (u,c) not in uctoi:
i=uctoi[u,c]=len(to)
to.append([])
to[i].append(u)
to[u].append(i)
else:i=uctoi[u,c]
if (v,c) not in uctoi:
j=uctoi[v,c]=len(to)
to.append([])
to[j].append(v)
to[v].append(j)
else:j=uctoi[v,c]
to[i].append(j)
to[j].append(i)
#print(to)
#print(fin)
solve()
```
| 93,393 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
def bfs01(g, s):
d = {}
for v in g.keys():
d[v] = sys.maxsize
d[s] = 0
if s not in d:
return d
q = deque()
q.append((d[s], s))
NM = 1 << 30
while q:
_, u = q.popleft()
for v in g[u]:
if v > NM:
c = 0
else:
c = 1
alt = c + d[u]
if d[v] > alt:
d[v] = alt
if c == 0:
q.appendleft((d[v], v))
else:
q.append((d[v], v))
return d
@mt
def slv(N, M):
g = defaultdict(list)
NM = 30
for _ in range(M):
p, q, c = input().split()
p = int(p)
q = int(q)
c = int(c)
cp = (c << NM) + p
cq = (c << NM) + q
g[cp].append(cq)
g[cq].append(cp)
g[cp].append(p)
g[cq].append(q)
g[p].append((cp))
g[q].append((cq))
d = bfs01(g, 1)
return -1 if N not in d or d[N] == sys.maxsize else d[N]
def main():
N, M = read_int_n()
print(slv(N, M))
if __name__ == '__main__':
main()
```
| 93,394 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
from collections import deque,defaultdict
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
mod =10**7
table=defaultdict(set)
visit=defaultdict(int)
for i in range(M):
a,b,c=map(int,input().split())
table[a].add(a+c*mod)
table[b].add(b+c*mod)
table[a+c*mod].add(a)
table[b+c*mod].add(b)
table[a+c*mod].add(b+c*mod)
table[b+c*mod].add(a+c*mod)
visit[a]=0
visit[b]=0
visit[b+c*mod]=0
visit[a+c*mod]=0
H=deque()
H.append((1,0))
visit[1]=1
ans=mod
while H:
#print(H)
x,cost=H.popleft()
visit[x] = 1
if x==N:
ans=min(ans,cost)
break
for y in table[x]:
if visit[y]==1:
continue
if x<=10**5 and mod<=y:
H.append((y,cost+1))
else:
H.appendleft((y,cost))
if ans==mod:
print(-1)
else:
print(ans)
```
| 93,395 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n,m = map(int, readline().split())
g = {}
for _ in range(m):
p,q,c = map(int, readline().split())
pc = ((p-1)<<20)+c
qc = ((q-1)<<20)+c
pp = (p-1)<<20
qq = (q-1)<<20
if pc not in g: g[pc] = []
if qc not in g: g[qc] = []
if pp not in g: g[pp] = []
if qq not in g: g[qq] = []
g[pc].append(qc)
g[pc].append(pp)
g[qc].append(pc)
g[qc].append(qq)
g[pp].append(pc)
g[qq].append(qc)
if 0 not in g: g[0] = []
from collections import deque
q = deque([(0,0)])
res = {0:0}
mask = (1<<20)-1
while q:
vl,dv = q.popleft()
if res[vl] < dv: continue
if (vl>>20) == n-1:
res[(n-1)<<20] = dv+1
break
for tl in g[vl]:
ndv = dv + (vl&mask==0 or tl&mask==0)
if tl not in res or res[tl] > ndv:
res[tl] = ndv
if vl&mask==0 or tl&mask==0:
q.append((tl,ndv))
else:
q.appendleft((tl,ndv))
if (n-1)<<20 in res:
print(res[(n-1)<<20]//2)
else:
print(-1)
```
| 93,396 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
import sys
from collections import deque, defaultdict
def bfs01(s, t, links):
q = deque([(0, s, -1)]) # cost, station, last-company
visited = set()
while q:
d, v, e = q.popleft()
if v == t:
return d
if (v, e) in visited:
continue
visited.add((v, e))
if e == 0:
lv = links[v]
for c in lv:
for u in lv[c]:
if (u, c) in visited:
continue
q.append((d + 1, u, c))
else:
for u in links[v][e]:
if (u, e) in visited:
continue
q.appendleft((d, u, e))
if (v, 0) not in visited:
q.appendleft((d, v, 0))
return -1
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
p -= 1
q -= 1
links[p][c].add(q)
links[q][c].add(p)
print(bfs01(0, n - 1, links))
```
| 93,397 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
"Correct Solution:
```
from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
print(-1)
exit()
G=defaultdict(set)
for i in range(M):
a,b,c=map(int,input().split())
G[a+(c<<30)].add(b+(c<<30))
G[b+(c<<30)].add(a+(c<<30))
G[a].add(a+(c<<30))
G[b].add(b+(c<<30))
G[a+(c<<30)].add(a)
G[b+(c<<30)].add(b)
def BFS(x):
d={}
for k in G.keys():
d[k]=float("inf")
stack=deque([(x,0)])
if x not in d:
return -1
while stack:
s,m=stack.popleft()
if s==N:
return m
if d[s]>m:
d[s]=m
if s>=(1<<30):
for i in G[s]:
if d[i]>10**30:
stack.appendleft((i,m))
else:
for i in G[s]:
if d[i]>10**30:
stack.append((i,m+1))
return -1
print(BFS(1))
```
| 93,398 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number.
The i-th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i.
You can change trains at a station where multiple lines are available.
The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.
Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare.
Constraints
* 2 \leq N \leq 10^5
* 0 \leq M \leq 2×10^5
* 1 \leq p_i \leq N (1 \leq i \leq M)
* 1 \leq q_i \leq N (1 \leq i \leq M)
* 1 \leq c_i \leq 10^6 (1 \leq i \leq M)
* p_i \neq q_i (1 \leq i \leq M)
Input
The input is given from Standard Input in the following format:
N M
p_1 q_1 c_1
:
p_M q_M c_M
Output
Print the minimum required fare. If it is impossible to get to station N by subway, print `-1` instead.
Examples
Input
3 3
1 2 1
2 3 1
3 1 2
Output
1
Input
8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
Output
2
Input
2 0
Output
-1
Submitted Solution:
```
def main():
N,M=map(int,input().split())
if M == 0:
print(-1)
exit()
INF = 10**6
pqc = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
to1d={v:{} for v in range(N)}
count=2
for p,q,c in pqc:
if not to1d[p].get(c):
to1d[p][c] = count
count += 1
if not to1d[q].get(c):
to1d[q][c] = count
count += 1
G = [{} for _ in range(N+count)]
for p,q,c in pqc:
v1,v2 = to1d[p][c],to1d[q][c]
G[v1][v2] = G[v2][v1] = 0
for i in range(N):
if len(to1d[i])<=1: continue
for c in to1d[i].keys():
v = to1d[i][c]
G[v][count] = 1
G[count][v] = 0
count += 1
def dijkstra(start = 0, goal = 1):
from heapq import heappop, heappush
NN = len(G)
d = [INF]*NN
d[start] = 0
que = []
heappush(que, start)
while que:
p = divmod(heappop(que),NN)
v = p[1]
if d[v] < p[0]: continue
for u in G[v].keys():
if d[u] > d[v] + G[v][u]:
d[u] = d[v] + G[v][u]
heappush(que, d[u]*NN+u)
if v == goal: return d[goal]
return d[goal]
for c in to1d[0].keys():
v = to1d[0][c]
G[0][v] = 1
for c in to1d[N-1].keys():
v = to1d[N-1][c]
G[v][1] = 0
ans = dijkstra(0,1)
print(ans if ans < INF else -1)
if __name__=="__main__":
main()
```
Yes
| 93,399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.