text
stringlengths
198
433k
conversation_id
int64
0
109k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` def nd(n): v = 0 while n: n, v = n // 10, v + 1 return v def sd(n): v = 0 while n: n, v = n // 10, v + n % 10 return v def mina(s): d9 = s // 9 return (s % 9 + 1) * 10 ** d9 - 1 def maxan(s, n): v = 0 for i in range(n - 1, -1, -1): c = min(s, 9) s -= c v += c * 10 ** i return v def minan(s, n): d9 = (s - 1) // 9 return 10 ** d9 - 1 + 10 ** (n - 1) + (s - 1) % 9 * 10 ** d9 def f(s, m): a1 = mina(s) if a1 > m: return a1 n = nd(m) if m >= maxan(s, n): return minan(s, n + 1) for i in range(n): if m // 10 ** i % 10 == 9: continue x = m - m % 10 ** i + 10 ** i sx = sd(x) if sx > s: continue for j in range(i + 1): d = x // 10 ** j % 10 c = min(9 - d, s - sx) x += c * 10 ** j sx += c if sx == s: return x return minan(s, n + 1) v = 0 for i in range(int(input())): v = f(int(input()), v) print(v) ``` Yes
99,800
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` def cr_mn(sm): d = 1 res = 0 while sm > 0: res += min(9, sm) * d sm -= min(9, sm) d *= 10 return res def cr_ln(sm, ln): if sm == 0: return '0' * ln res = int('1' + '0' * (ln - 1)) d = 1 sm -= 1 while sm > 0: res += min(9, sm) * d sm -= min(9, sm) d *= 10 return str(res) def cr_min(sm, lst): r1 = cr_mn(sm) if r1 > int(lst): r1 = str(r1) return '0' * (len(lst) - len(r1)) + str(r1) ln = len(lst) lfs = int(lst[0]) if lfs >= sm: return '-1' if ln == 1: return sm r1 = cr_min(sm - lfs, lst[1:]) if r1 == '-1': if lfs == 9: return '-1' r1 = str(cr_mn(sm - lfs - 1)) return str(lfs + 1) + '0' * (ln - 1 - len(r1)) + r1 return lst[0] + r1 n = int(input()) a = [] for i in range(n): a += [int(input())] b = [-1 for i in range(n)] b[0] = str(cr_mn(a[0])) print(b[0]) for i in range(1, n): b[i] = cr_min(a[i], b[i - 1]) if b[i] == '-1': b[i] = cr_ln(a[i], len(b[i - 1]) + 1) print(b[i]) ``` Yes
99,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` #!/usr/bin/env python def add(c, v, p=0): assert(v < 10 and p < len(c)) for i in range(p, len(c)): c[i] += v if c[i] >= 10: c[i] %= 10 v = 1 else: return c.append(v) def find_min(xsum, l): csum = sum(l) if csum == xsum: return l if csum < xsum: for i, e in enumerate(l): delta = min(9 - e, xsum - csum) l[i] += delta csum += delta while csum != xsum: delta = min(9, xsum - csum) l.append(delta) csum += delta else: for i in range(0, len(l)): c = l[i] if c != 0: delta = 10 - c add(l, delta, i) csum = sum(l) if csum <= xsum: return find_min(xsum, l) n = int(input()) c = [0] for i in range(n): b = int(input()) find_min(b, c) print(''.join(map(str, c[::-1]))) add(c, 1) ``` Yes
99,802
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Mon Nov 30 12:04:02 2015 @author: Mary """ n = int(input()) prev_b = 0 r = [0] * 500 for _ in range(n): b = int(input()) if b > prev_b: delta = b - prev_b i = 0 while delta > 0: if r[i] < 9: delta_i = min(delta, 9 - r[i]) r[i] += delta_i delta -= delta_i i += 1 else: max_i = -1 s = 0 while s < prev_b: max_i += 1 s += r[max_i] max_i += 1 sum_ge_max_i = 0 i = max_i s = 0 while b > s + r[i-1]: s += r[i-1] i -= 1 if r[i] < 9: max_i = i sum_ge_max_i = s r[max_i] += 1 sum_ge_max_i += 1 delta = b - sum_ge_max_i for i in range(max_i): if delta > 0: delta_i = min(delta, 9) r[i] = delta_i delta -= delta_i else: r[i] = 0 res = ''.join(map(str, reversed(r))) print(res.lstrip('0')) prev_b = b ``` Yes
99,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` def sum(i): s = str(i) sum = 0 for i in s: x = int(i) sum+=x return sum N = int(input()) minv = -1 for i in range(N): x = int(input()) #output the min number > minv whose digits add to x m = x%9 if(minv==-1): minv = 0 while(m-minv<0): m+=9 minv += m-minv while(sum(minv)!=x): minv+=9 print(minv) # 1 2 3 4 5 6 7 8 9 1 # 2 3 4 5 6 7 8 9 10 2 # 3 4 5 6 7 8 9 10 11 3 ``` No
99,804
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` def gen_min(x): return int(str(x % 9) + '9' * (x // 9)) def gen_next(x): S = list(str(x)) f = True for i in range(1, len(S)): if S[i] != '0': f = False break if f and S[0] == '1': return x * 10 for i in range(len(S) - 1, -1, -1): if int(S[i]) > 0: S[i] = str(int(S[i]) - 1) if i > 0: S[i - 1] = str(int(S[i - 1]) + 1) else: S = S + ['1'] S[0], S[-1] = S[-1], S[0] break return int(''.join(S)) ''' x = -1 for i in range(100): n = int(input()) x = gen_min(n) if n != -1 else gen_next(x) print(x) exit(0) ''' n = int(input()) b = [int(input()) for i in range(n)] a = [0] * (n + 1) for i in range(1, n + 1): l = a[i - 1] cur = gen_min(b[i - 1]) while cur <= l: cur = gen_next(cur) a[i] = cur print(cur) ``` No
99,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` def give(r, s, n, k): # делает минимально возможное число с такой суммой цифр и кол-вом разрядов for i in range(n-1, n-k-1, -1): s = s - r[i] + 9 r[i] = 9 if (s < b) and (b-s < 10): r[n-k-1] += b-s s += b-s elif s > b: p = '1'+'0'*n while sum_c(p) != b: p = str(int(p)+1) r = list(map(int, list(p))) return r def sum_c(s): sum = 0 for i in s: sum += int(i) return sum t = int(input()) b = 0 b_prev = 0 # прошлое значение b a = [0] # будущий ответ for i in range(t): b = int(input()) n = b // 9 if b % 9 != 0: n += 1 # посчитали количество разрядов pr = len(str(a[i])) if n > pr: # можно свободно создавать число r = give([1]+[0]*(n-1), 1, n, b // 9) else: # придется увеличивать прошлое r = give(list(map(int, list(str(a[i])))), b_prev, pr, b // 9) new = '' for i in r: new += str(i) a.append(int(new)) # записали число в массив b_prev = b # обновили b_prev for i in range(t): print(a[i+1]) ``` No
99,806
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possible options he likes the one sequence with the minimum possible last number an. Help Vasya restore the initial sequence. It is guaranteed that such a sequence always exists. Input The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300. Output Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers without leading zeroes. Examples Input 3 1 2 3 Output 1 2 3 Input 3 3 2 1 Output 3 11 100 Submitted Solution: ``` n=int(input());a=[0]*n for i in range(n): b = int(input()) if sum(int(i) for i in list(str(a[max(0,i-1)]))) > b: k = 10**(len(a[max(0,i-1)])) else: k = a[max(0,i-1)] for j in range(k, k*10): if sum(int(i) for i in list(str(j))) == b: a[i]=j break print(*a,sep="\n") ``` No
99,807
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` from math import * n=int(input()) s=input() t=input() l=0 r=n-1 for i in range(n): if(s[i]==t[i]): l+=1 else: break for i in range(n-1,-1,-1): if(s[i]==t[i]): r-=1 else: break ans=0 if(s[l+1:r+1]==t[l:r]): ans+=1 if(s[l:r]==t[l+1:r+1]): ans+=1 print(ans) ```
99,808
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## import math import bisect mod = 998244353 # for _ in range(int(input())): from collections import Counter # sys.setrecursionlimit(10**6) # dp=[[-1 for i in range(n+5)]for j in range(cap+5)] # arr= list(map(int, input().split())) # n,l= map(int, input().split()) # arr= list(map(int, input().split())) # for _ in range(int(input())): # n=int(input()) # for _ in range(int(input())): import bisect from heapq import * from collections import defaultdict,deque def okay(x,y): if x<0 or x>=3 : return False if y<n and mat[x][y]!=".": return False if y+1<n and mat[x][y+1]!=".": return False if y+2<n and mat[x][y+2]!=".": return False return True '''for i in range(int(input())): n,m=map(int, input().split()) g=[[] for i in range(n+m)] for i in range(n): s=input() for j,x in enumerate(s): if x=="#": g[i].append(n+j) g[n+j].append(i) q=deque([0]) dis=[10**9]*(n+m) dis[0]=0 while q: node=q.popleft() for i in g[node]: if dis[i]>dis[node]+1: dis[i]=dis[node]+1 q.append(i) print(-1 if dis[n-1]==10**9 else dis[n-1])''' '''from collections import deque t = int(input()) for _ in range(t): q = deque([]) flag=False n,k = map(int, input().split()) mat = [input() for i in range(3)] vis=[[0 for i in range(105)]for j in range(3)] for i in range(3): if mat[i][0]=="s": q.append((i,0)) while q: x,y=q.popleft() if y+1>=n: flag=True break if vis[x][y]==1: continue vis[x][y]=1 if (y+1<n and mat[x][y+1]=='.' and okay(x-1,y+1)==True): q.append((x-1,y+3)) if (y+1<n and mat[x][y+1]=='.' and okay(x,y+1)==True): q.append((x,y+3)) if (y+1<n and mat[x][y+1]=='.' and okay(x+1,y+1)==True): q.append((x+1,y+3)) if flag: print("YES") else: print("NO") # ls=list(map(int, input().split())) # d=defaultdict(list)''' from collections import defaultdict #for _ in range(int(input())): n=int(input()) #n,k= map(int, input().split()) #arr=sorted([i,j for i,j in enumerate(input().split())]) s=input() t=input() n=len(s) f=0 l=0 i=0 while s[i]==t[i]: i+=1 j=n-1 while s[j]==t[j]: j-=1 print(int(s[i:j]==t[i+1:j+1])+int(s[i+1:j+1]==t[i:j])) ```
99,809
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` from sys import stdin read = stdin.readline n = int(read()) S = read() T = read() for i in range(n): if S[i] != T[i]: break a = b = 1 for j in range(i,n-1): if S[j] != T[j+1]: a = (S[j+1:] == T[j+1:]) break for j in range(i,n-1): if S[j+1] != T[j]: b = (S[j+1:] == T[j+1:]) break print(a+b) ```
99,810
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` n=int(input()) st1=input() st2=input() i=0 while st1[i] == st2[i]: i+=1 j=n-1 while st1[j] == st2[j]: j-=1 print(int(st1[i+1:j+1] == st2[i:j]) + int(st1[i:j] == st2[i+1:j+1])) ```
99,811
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` import sys #sys.stdin = open("in.txt") try: while True: n = int(input()) s1 = input() s2 = input() L = 0 R = n-1 while s1[L] == s2[L]: L += 1 while s1[R] == s2[R]: R -= 1 res = 0 i = L while i < R and s1[i] == s2[i+1]: i += 1 if i >= R: res += 1 s1, s2 = s2, s1 i = L while i < R and s1[i] == s2[i+1]: i += 1 if i >= R: res += 1 print(res) except EOFError: pass ```
99,812
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` def aux(s, t): n = len(s) lpr = 0 for i in range(n): if s[i] != t[i]: break lpr += 1 lsf = 0 for i in range(n-1, -1, -1): if s[i] != t[i]: break lsf += 1 if(lpr == n): return 2 return (s[lpr:n-lsf-1] == t[lpr+1:n-lsf]) + (t[lpr:n-lsf-1] == s[lpr+1:n-lsf]) input(); print(aux(input(), input())) ```
99,813
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` i, j = 0, int(input()) - 1 a, b = input(), input() while a[i] == b[i]: i += 1 while a[j] == b[j]: j -= 1 print((a[i + 1:j + 1] == b[i:j]) + (b[i + 1:j + 1] == a[i:j])) ```
99,814
Provide tags and a correct Python 3 solution for this coding contest problem. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Tags: constructive algorithms, dp, greedy, hashing, strings, two pointers Correct Solution: ``` n = int(input()) s, t = input(), input() i = 0 while s[i] == t[i]: i += 1 j = n - 1 while s[j] == t[j]: j -= 1 print(int(s[i + 1:j + 1] == t[i:j]) + int(s[i:j] == t[i + 1:j + 1])) ```
99,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` import math from collections import Counter, defaultdict from itertools import accumulate R = lambda: map(int, input().split()) n = int(input()) s1 = input() s2 = input() for i in range(n): if s1[i] != s2[i]: s1, s2 = s1[i:], s2[i:] break for i in range(len(s1) - 1, -1, -1): if s1[i] != s2[i]: s1, s2 = s1[:i + 1], s2[:i + 1] break if len(s1) == 1 or s1[1:] == s2[:-1] and s1[:-1] == s2[1:]: print(2) elif s1[1:] == s2[:-1] or s1[:-1] == s2[1:]: print(1) else: print(0) ``` Yes
99,816
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` def aux(s, t): n = len(s) lpr = 0 for i in range(n): if s[i] != t[i]: break lpr += 1 lsf = 0 for i in range(n-1, -1, -1): if s[i] != t[i]: break lsf += 1 if lpr == n: return 2 else: return (s[lpr:n-lsf-1] == t[lpr+1:n-lsf]) + (t[lpr:n-lsf-1] == s[lpr+1:n-lsf]) input(); print(aux(input(), input())) ``` Yes
99,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` def check(pt1,pt2): global count while pt1<n and pt2<n: if st1[pt1] ==st2[pt2]: pt1+=1 pt2+=1 else: if pt1+1 <n and st1[pt1+1] ==st2[pt2]: pt1+=1 count+=1 elif pt2+1<n and st1[pt1] ==st2[pt2+1]: pt2+=1 count+=1 elif pt2+1<n and pt1+1 <n and st1[pt1+1] ==st2[pt2+1]: pt1+=1 pt2+=1 count+=1 else: return 0 if count >2: return 0 return 1 n=int(input())+1 st1=input()+"z" st2=input()+"z" count=0 c=check(0,0) if c==1: print(count%2 +1) else: print(0) ``` No
99,818
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` from math import * n=int(input()) s=input() t=input() a=[] for i in range(n): if s[i]!=t[i]: a.append([s[i],t[i]]) if len(a)==0: print(26*(n+1)) elif len(a)==1: print(2) elif len(a)==2: if(a[0][0]==a[1][0] or a[0][0]==a[1][1] or a[0][1]==a[1][0] or a[0][1]==a[1][1]): print(1) else: print(0) else: print(0) ``` No
99,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## import math import bisect mod = 998244353 # for _ in range(int(input())): from collections import Counter # sys.setrecursionlimit(10**6) # dp=[[-1 for i in range(n+5)]for j in range(cap+5)] # arr= list(map(int, input().split())) # n,l= map(int, input().split()) # arr= list(map(int, input().split())) # for _ in range(int(input())): # n=int(input()) # for _ in range(int(input())): import bisect from heapq import * from collections import defaultdict,deque def okay(x,y): if x<0 or x>=3 : return False if y<n and mat[x][y]!=".": return False if y+1<n and mat[x][y+1]!=".": return False if y+2<n and mat[x][y+2]!=".": return False return True '''for i in range(int(input())): n,m=map(int, input().split()) g=[[] for i in range(n+m)] for i in range(n): s=input() for j,x in enumerate(s): if x=="#": g[i].append(n+j) g[n+j].append(i) q=deque([0]) dis=[10**9]*(n+m) dis[0]=0 while q: node=q.popleft() for i in g[node]: if dis[i]>dis[node]+1: dis[i]=dis[node]+1 q.append(i) print(-1 if dis[n-1]==10**9 else dis[n-1])''' '''from collections import deque t = int(input()) for _ in range(t): q = deque([]) flag=False n,k = map(int, input().split()) mat = [input() for i in range(3)] vis=[[0 for i in range(105)]for j in range(3)] for i in range(3): if mat[i][0]=="s": q.append((i,0)) while q: x,y=q.popleft() if y+1>=n: flag=True break if vis[x][y]==1: continue vis[x][y]=1 if (y+1<n and mat[x][y+1]=='.' and okay(x-1,y+1)==True): q.append((x-1,y+3)) if (y+1<n and mat[x][y+1]=='.' and okay(x,y+1)==True): q.append((x,y+3)) if (y+1<n and mat[x][y+1]=='.' and okay(x+1,y+1)==True): q.append((x+1,y+3)) if flag: print("YES") else: print("NO") # ls=list(map(int, input().split())) # d=defaultdict(list)''' from collections import defaultdict #for _ in range(int(input())): n=int(input()) #n,k= map(int, input().split()) #arr=sorted([i,j for i,j in enumerate(input().split())]) s=input() t=input() n=len(s) f=0 l=0 i=0 while s[i]==t[i]: i+=1 j=n-1 while s[j]==t[j]: j-=1 if (i==j) or ((s[i:j-1]==t[i+1:j]+s[i+1:j]==t[i:j-1])==2): print(2) elif s[i:j-1]==t[i+1:j] or s[i+1:j]==t[i:j-1]: print(1) else: print(0) #print(i, j) ``` No
99,820
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics. Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word. Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters. Input The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. Output Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. Examples Input 7 reading trading Output 1 Input 5 sweet sheep Output 0 Input 3 toy try Output 2 Note In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold). In the second sample test the two given words couldn't be obtained from the same word by removing one letter. In the third sample test the two given words could be obtained from either word "tory" or word "troy". Submitted Solution: ``` def check(pt1,pt2): global count while pt1<n and pt2<n: if st1[pt1] ==st2[pt2]: pt1+=1 pt2+=1 else: if pt1+1 <n and st1[pt1+1] ==st2[pt2]: pt1+=1 count+=1 elif pt2+1<n and st1[pt1] ==st2[pt2+1]: pt2+=1 count+=1 elif (pt1+1 and pt2+1) <n and st1[pt1+1] ==st2[pt2+1]: pt1+=1 pt2+=1 count+=1 else: return 0 if count >2: return 0 return 1 n=int(input()) st1=input() st2=input() count=0 c=check(0,0) if c==1: print(count%2 +1) else: print(0) ``` No
99,821
Provide tags and a correct Python 3 solution for this coding contest problem. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Tags: data structures, implementation, sortings Correct Solution: ``` import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) h, q = mints() a = [None]*(q*2+1) L = 1<<(h-1) R = (1<<h)-1 j = 0 for i in range(q): hh,l,r,ans = mints() l = (l<<(h-hh)) r = ((r+1)<<(h-hh))-1 if ans == 1: L = max(L, l) R = min(R, r) else: a[j] = (l,-1) a[j+1] = (r+1,1) j+=2 if L > R: print("Game cheated!") exit(0) a[j]=((1<<h),-1) a = a[:j+1] a.sort() #print(a) #print(L,R) cnt = 0 t = 1<<(h-1) ans = None for i in a: if i[0] != t: kk = min(R+1,i[0])-max(t,L) #print(i,t,cnt,kk) if cnt == 0 and kk >= 1: if ans != None or kk > 1: print("Data not sufficient!") exit(0) ans = max(t,L) #print(ans) t = i[0] cnt -= i[1] if ans == None: print("Game cheated!") else: print(ans) ```
99,822
Provide tags and a correct Python 3 solution for this coding contest problem. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Tags: data structures, implementation, sortings Correct Solution: ``` from collections import * h,q=map(int,input().split()) d=defaultdict(lambda:0) d[2**h]=0 d[2**(h-1)]=0 for _ in range(q): i,l,r,a=map(int,input().split()) l,r=l*2**(h-i),(r+1)*2**(h-i) if a:d[1]+=1;d[l]-=1;d[r]+=1 else:d[l]+=1;d[r]-=1 s=0 l=0 D=sorted(d.items()) for (a,x),(b,_) in zip(D,D[1:]): s+=x if s==0:q=a;l+=b-a print(("Game cheated!",q,"Data not sufficient!")[min(l,2)]) ```
99,823
Provide tags and a correct Python 3 solution for this coding contest problem. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Tags: data structures, implementation, sortings Correct Solution: ``` h,q=map(int,input().split()) d=[(2**h,0),(2**(h-1),0)] for _ in range(q): i,l,r,a=map(int,input().split()) l,r=l*2**(h-i),(r+1)*2**(h-i) d.extend([[(l,1),(r,-1)],[(0,1),(l,-1),(r,1)]][a]) s=0 l=0 d=sorted(d) for (a,x),(b,_) in zip(d,d[1:]): s+=x if a!=b and s==0:q=a;l+=b-a print(("Game cheated!",q,"Data not sufficient!")[min(l,2)]) ```
99,824
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Submitted Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- def ReadIn(): height, n = [int(x) for x in input().split()] queries = [tuple(int(x) for x in input().split()) for q in range(n)] return height, queries def MoveToLeaves(height, queries): leaves = [] for level, left, right, yn in queries: shift = height - level leaves.append(tuple([ left << shift, (right << shift) | ((1 << shift) - 1), yn])) return leaves def RangeIntersection(ranges): # print(ranges) ret = ranges[0][:2] for r in ranges: ret = (max(r[0], ret[0]), min(r[1], ret[1])) return ret def RangeUnion(ranges): if len(ranges) == 0: return [] ranges.sort(key=lambda r: r[0]) ret = [] now = ranges[0][:2] for r in ranges: if r[0] > now[1] + 1: ret.append(now) now = r else: now = (now[0], max(now[1], r[1])) ret.append(now) return ret def Solve(height, queries): # print(height, queries) queries = MoveToLeaves(height, queries) # print(queries) range_in = RangeIntersection( [(1 << (height - 1), (1 << height) - 1, 1)] + list(filter(lambda q: q[2] == 1, queries))) # print(range_in) ranges_out = RangeUnion( list(filter(lambda q: q[2] == 0, queries))) if height == 16: print(ranges_out) if range_in[0] > range_in[1]: print('Game cheated!') return for r in ranges_out: if r[0] <= range_in[0] and range_in[1] <= r[1]: print('Game cheated!') return if range_in[0] < r[0] and r[1] < range_in[1]: print('Data not sufficient!') return for r in ranges_out: if r[0] == range_in[0] + 1: print(range_in[0]) return if r[1] == range_in[1] - 1: print(range_in[1]) return for l, r in zip(ranges_out[:-1], ranges_out[1:]): if r[0] - l[1] == 2: continue pos = l[1] + 1 if range_in[0] <= pos <= range_in[1]: print(pos) return print('Data not sufficient!') if __name__ == '__main__': height, queries = ReadIn() Solve(height, queries) ``` No
99,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random """ created by shhuan at 2017/10/6 09:03 """ H, Q = map(int, input().split()) M1 = [] M2 = [] for i in range(Q): i, l, r, a = map(int, input().split()) left = l * 2 ** (H - i) right = (r + 1) * 2 ** (H - i) - 1 if a: M1.append((abs(left-right), left, right)) else: M2.append((abs(left-right), left, right)) # M1.sort() # M2.sort(reverse=True) L, R = 2**(H-1), 2**H-1 for d, left, right in M1: L = max(L, left) R = min(R, right) if L > R: print("Game cheated!") exit(0) LR = {(L, R)} for d, left, right in M2: # merge [L, R] and [1, left-1] # merge [L, R] and [right+1, 2**H-1] nextlr = set() for L, R in LR: if R < left or L > right: nextlr.add((L, R)) elif L <= left-1 <= R: nextlr.add((L, left-1)) elif L <= right+1 <= R: nextlr.add((right+1, R)) LR = nextlr LR = list(LR) if len(LR) == 0: print("Game cheated!") elif len(LR) == 1 and LR[0][0] == LR[0][1]: print(LR[0][0]) else: print("Data not sufficient!") ``` No
99,826
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Submitted Solution: ``` from collections import * h,q=map(int,input().split()) d=defaultdict(lambda:0) d[2**h]=0 for _ in range(q): i,l,r,a=map(int,input().split()) l,r=l*2**(h-i),(r+1)*2**(h-i) if a:d[1]+=1;d[l]-=1;d[r]+=1 else:d[l]+=1;d[r]-=1 s=0 l=0 D=sorted(d.items()) for (a,x),(b,_) in zip(D,D[1:]): s+=x if s==0:q=a;l+=b-a print(("Game cheated!",q,"Data not sufficient!")[min(l,2)]) ``` No
99,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such that * The root is number 1 * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1 The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out! In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!. Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory. Input The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively. The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No"). Output If the information provided by the game is contradictory output "Game cheated!" without the quotes. Else if you can uniquely identify the exit to the maze output its index. Otherwise output "Data not sufficient!" without the quotes. Examples Input 3 1 3 4 6 0 Output 7 Input 4 3 4 10 14 1 3 6 6 0 2 3 3 1 Output 14 Input 4 2 3 4 6 1 4 12 15 1 Output Data not sufficient! Input 4 2 3 4 5 1 2 3 3 1 Output Game cheated! Note Node u is an ancestor of node v if and only if * u is the same node as v, * u is the parent of node v, * or u is an ancestor of the parent of node v. In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7. In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand. <image> Submitted Solution: ``` #!/usr/bin/env python # -*- coding: utf-8 -*- def ReadIn(): height, n = [int(x) for x in input().split()] queries = [tuple(int(x) for x in input().split()) for q in range(n)] return height, queries def MoveToLeaves(height, queries): leaves = [] for level, left, right, yn in queries: shift = height - level leaves.append(tuple([ left << shift, (right << shift) | ((1 << shift) - 1), yn])) return leaves def RangeIntersection(ranges): # print(ranges) ret = ranges[0][:2] for r in ranges: ret = (max(r[0], ret[0]), min(r[1], ret[1])) return ret def RangeUnion(ranges): if len(ranges) == 0: return [] ranges.sort(key=lambda r: r[0]) ret = [] now = ranges[0][:2] for r in ranges: if r[0] > now[1] + 1: ret.append(now) now = r else: now = (now[0], max(now[1], r[1])) ret.append(now) return ret def Solve(height, queries): # print(height, queries) queries = MoveToLeaves(height, queries) # print(queries) range_in = RangeIntersection( [(1 << (height - 1), (1 << height) - 1, 1)] + list(filter(lambda q: q[2] == 1, queries))) # print(range_in) ranges_out = RangeUnion( list(filter(lambda q: q[2] == 0, queries))) if range_in[0] > range_in[1]: print('Game cheated!') return for r in ranges_out: if r[0] <= range_in[0] and range_in[1] <= r[1]: print('Game cheated!') return if range_in[0] < r[0] and r[1] < range_in[1]: print('Data not sufficient!') return for r in ranges_out: if r[0] == range_in[0] + 1: print(range_in[0]) return if r[1] == range_in[1] - 1: print(range_in[1]) return for l, r in zip(ranges_out[:-1], ranges_out[1:]): if r[0] - l[1] == 2: continue pos = l[1] + 1 if range_in[0] <= pos <= range_in[1]: print(pos) return print('Data not sufficient!') if __name__ == '__main__': height, queries = ReadIn() Solve(height, queries) ``` No
99,828
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n=int(input()) ans=27**n-7**n mod=10**9+7 print(ans%mod) ```
99,829
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n=int(input()) p=9**n*3**n print((p-7**n)%1000000007) ```
99,830
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n = input() a, b = 20, 7 for i in range(1, int(n)): a, b = a*27+b*20, b*7 a %= 1000000007 b %= 1000000007 print(a) ```
99,831
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` ''' 1 1 1 1 1 2 1 2 2 1 1 3 1 3 3 1 2 3 bad combo 3**(3*n)-badcombo ''' n=int(input()) x=pow(3,3*n)-pow(7,n) print(x%(10**9+7)) ```
99,832
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n = int(input()) print((27 ** n - 7 ** n) % (10 ** 9 + 7)) ```
99,833
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n = int(input()) mod = 10 ** 9 + 7 print((27 ** n - 7 ** n) % mod) ```
99,834
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n = int(input()) res = 1 res2 = 1 for i in range(3 * n): res = (3 * res) % 1000000007 for i in range(n): res2 = (7 * res2) % 1000000007 print((res - res2) % 1000000007) ```
99,835
Provide tags and a correct Python 3 solution for this coding contest problem. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Tags: combinatorics Correct Solution: ``` n = int(input()) ans = 27**n - 7**n const = 10**9 + 7 print(ans%const) ```
99,836
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` n = int(input()) r = 3**(n*3) - 7**n print(r%1000000007) ``` Yes
99,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` inta = int(input()); intb = 3**(3*inta) - 7**(inta); intb %= 1000000007; print(intb); ``` Yes
99,838
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` mod_by = 10**9 + 7 n = int(input()) print((3**(3*n)-7**n) % mod_by) ``` Yes
99,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` n = int(input()) M = int(1e9 + 7) print((pow(3, 3 * n, M) % M - pow(7, n, M) % M) % M) ``` Yes
99,840
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` n = int(input()) print(3**(3*n)-7**n % int(1e9+7)) ``` No
99,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` from math import factorial n = int(input()) if n==1: print(20) quit() print(int(factorial(3*3*n-1)/(factorial(3)*factorial(3*3*n-4)))) ``` No
99,842
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` n = int(input()) res = (3**(3*n) - 7**(n))%(10**9-7) print (res) ``` No
99,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways). Input A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three. Output Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7. Examples Input 1 Output 20 Input 2 Output 680 Note 20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image> Submitted Solution: ``` mod = 10000007 def modpow(a,b): if(b == 0): return(1) elif(b % 2 == 1): return((a * modpow(a,b-1) % mod)) else: tmp = modpow(a,b/2) return ((tmp*tmp) % mod) n = int(input()) a = modpow(27,n) b = modpow(7,n) print(a-b) ``` No
99,844
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x, y, x0, y0 = map(int, input().split()) moves = input() seen = [[False] * y for i in range(x)] currX, currY = x0 - 1, y0 - 1 total = 0 for i in range(len(moves)): #print(currX, currY) #print("Seen:", seen[currX][currY]) #print() if not seen[currX][currY]: print("1", end=" ") total += 1 else: print("0", end=" ") seen[currX][currY] = True if moves[i] == "L": currY = max(currY - 1, 0) elif moves[i] == "R": currY = min(currY + 1, y - 1) elif moves[i] == "U": currX = max(currX - 1, 0) else: currX = min(currX + 1, x - 1) print(x * y - total) ```
99,845
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x, y, x0, y0 = map(int, input().split()) s = input() z = set() k = (len(s)+1)*[0] k[0] = 1 u = 0 z.add((x0, y0)) for i in s: u += 1 if i == 'U' and x0 > 1: x0 -= 1 elif i == 'D' and x0 < x: x0 += 1 elif i == 'L' and y0 > 1: y0 -= 1 elif i == 'R' and y0 < y: y0 += 1 if not (x0, y0) in z: k[u]+=1 z.add((x0, y0)) k[len(s)] += (x*y)-sum(k) for i in k: print(i, end=' ') ```
99,846
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x,y,x0,y0=map(int,input().split()) s1=input() r=x*y res="1 " k=1 a = [[0] * y for i in range(x)] a[x0-1][y0-1]=1 for i in range(len(s1)-1): if s1[i]=="U": if x0-1>=1 and k<r: x0=x0-1 if a[x0-1][y0-1]==0: res=res+"1 " k=k+1 a[x0-1][y0-1]=1 else: res=res+"0 " else: res=res+"0 " if s1[i]=="D": if x0+1<=x and k<r: x0=x0+1 if a[x0-1][y0-1]==0: res=res+"1 " k=k+1 a[x0-1][y0-1]=1 else: res=res+"0 " else: res=res+"0 " if s1[i]=="L": if y0-1>=1 and k<r: y0=y0-1 if a[x0-1][y0-1]==0: res=res+"1 " k=k+1 a[x0-1][y0-1]=1 else: res=res+"0 " else: res=res+"0 " if s1[i]=="R": if y0+1<=y and k<r: y0=y0+1 if a[x0-1][y0-1]==0: res=res+"1 " k=k+1 a[x0-1][y0-1]=1 else: res=res+"0 " else: res=res+"0 " print(res+str(r-k)) ```
99,847
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x, y, x0, y0 = map(int, input().split()) a = [[0] * (y + 1) for i in range(x + 1)] s = input() count = x * y result = [0] * (len(s)) for i in range(len(s)): if a[x0][y0] == 0: a[x0][y0] = 1 result[i] = 1 count -= 1 if s[i] == 'U' and x0 > 1: x0 -=1 elif s[i] == 'D' and x0 < x: x0 +=1 elif s[i] == 'L' and y0 > 1: y0 -= 1 elif s[i] == 'R' and y0 < y: y0 += 1 print(" ".join(map(str,result)), count) ```
99,848
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# x,y,x0,y0=RI() s=input() total=0 dirs={'U':0, 'D':1, 'L':2, 'R':3} visited=[[0 for i in range(y)] for j in range(x)] for i in range(len(s)): if not visited[x0-1][y0-1]: print(1, end=" ") visited[x0-1][y0-1]=1 total+=1 else: print(0,end=" ") x0+= dX[dirs[s[i]]] y0+= dY[dirs[s[i]]] if x0<1: x0=1 elif x0>x: x0=x if y0<1: y0=1 elif y0>y: y0=y print(x*y - total) ```
99,849
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` DIR = {"L": (0, -1), "R": (0, 1), "U": (-1, 0), "D": (1, 0)} X, Y, x, y = map(int, input().split()) S = input() path = list() path.append((x, y)) for dx, dy in map(lambda x: DIR[x], S): xp, yp = x + dx, y + dy if xp < 1 or xp > X or yp < 1 or yp > Y: pass else: x, y = xp, yp path.append((x, y)) result = [] total = 0 vis = set() for i in range(len(S)): if path[i] in vis: result.append(0) else: result.append(1) total += 1 vis.add(path[i]) result.append(X * Y - total) print(" ".join(map(str, result))) ```
99,850
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x, y, x0, y0=list(map(int, input().split())) P={(x0, y0)} s=input() c=1 print(1, end=' ') for i in range(len(s)-1): if s[i] =='L': if y0>=2: y0-=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='U': if x0>=2: x0-=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='R': if y0<y: y0+=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='D': if x0<x: x0+=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) print(x*y-c) '''''' ```
99,851
Provide tags and a correct Python 3 solution for this coding contest problem. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Tags: implementation Correct Solution: ``` x, y, x0, y0 = [int(x) for x in input().split()] x0 -= 1 y0 -= 1 commands = input() xy = x * y l = len(commands) a = [0] * (l + 1) n = 0 field = [[-1]*y for i in range(x)] field[x0][y0] = 0 for i in range(l): command = commands[i]; if command == 'U': if x0 > 0: x0 -= 1 elif command == 'D': if x0 + 1 < x: x0 += 1 elif command == 'L': if y0 > 0: y0 -= 1 elif command == 'R': if y0 + 1 < y: y0 += 1 if field[x0][y0] < 0: field[x0][y0] = i + 1 for i in range(x): for j in range(y): a[field[i][j]] += 1 print(' '.join(str(x) for x in a)) ```
99,852
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` x, y, x0, y0=list(map(int, input().split())) P={(x0, y0)} s=input() c=1 print(1, end=' ') for i in range(len(s)-1): if s[i] =='L': if y0>=2: y0-=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='U': if x0>=2: x0-=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='R': if y0<y: y0+=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) if s[i] =='D': if x0<x: x0+=1 if (x0, y0) in P: print(0, end=' ') else: print(1, end=' '); c+=1; P.add((x0, y0)) print(x*y-c) ``` Yes
99,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` x, y, x0, y0 = map(int, input().split(' ')) g = [[0]* (y+1) for i in range(x + 1)] s = input() result = [0] * len(s) count = x*y for i in range(len(s)): if g[x0][y0] == 0: g[x0][y0] = 1 result[i] = 1 count -= 1 if s[i] == 'U' and x0 > 1: x0 -=1 if s[i] == 'D' and x0 < x: x0 += 1 if s[i] == 'L' and y0 > 1: y0 -= 1 if s[i] == 'R' and y0 < y: y0 += 1 print(' '.join(map(str, result)), count) # Made By Mostafa_Khaled ``` Yes
99,854
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time # = input() # = int(input()) #() = (i for i in input().split()) # = [i for i in input().split()] (a, b, x, y) = (int(i) for i in input().split()) s = input() ans = [0 for i in range(len(s) + 1) ] start = time.time() acc = 0 x -= 1 y -= 1 map = [[ 0 for i in range(b)] for j in range(a)] for i in range(len(s)): if map[x][y] == 0: ans[i] += 1 map[x][y] = 1 if s[i] == 'L' and y > 0: y -= 1 elif s[i] == 'R' and y < b-1: y += 1 elif s[i] == 'D' and x < a-1: x += 1 elif s[i] == 'U' and x > 0: x -= 1 ans[len(s)] = a*b - sum([sum(i) for i in map]) for i in ans: print(i, end= ' ') print() finish = time.time() #print(finish - start) ``` Yes
99,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` x, y, sx, sy = map(int, input().split()) sx, sy = sx - 1, sy - 1 direction = {'U' : (-1, 0), 'D' : (1, 0), 'L' : (0, -1), 'R' : (0, 1)} visited = [[False] * y for i in range(x)] prev = sx, sy s = input() sm = x * y - 1 print (1, end = ' ') visited[prev[0]][prev[1]] = True for c in s[:-1]: d = direction[c] cur = tuple(map(sum, zip(prev, d))) if not 0 <= cur[0] < x or not 0 <= cur[1] < y: cur = prev p = 1 - visited[cur[0]][cur[1]] print (p, end = ' ') sm -= p visited[cur[0]][cur[1]] = True prev = cur print (sm) ``` Yes
99,856
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` y, x, x_, y_ = list(map(int, input().split())) c = input() ans = [0 for i in range(len(c) + 1)] ans[0] = 1 p = 1 was_here = set() was_here.add((x_, y_)) for i in c: if i == 'U': y_ = max(1, y_ - 1) elif i == 'D': y_ = min(y, y_ + 1) elif i == 'L': x_ = max(1, x_ - 1) else: x_ = min(x, x_ + 1) if (x_, y_) in was_here: ans[p] = 0 elif p < len(c): ans[p] = 1 was_here.add((x_, y_)) else: ans[p] = x * y - len(was_here) p += 1 print(' '.join(list(map(str, ans)))) ``` No
99,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` field = [int(x) for x in input().split()] commands = input() X = field[0] Y = field[1] pos = [field[2], field[3]] lastPos = [X+1, Y+1] count = 0 flag = False for c in commands: if lastPos[0] == pos[0] and lastPos[1] == pos[1]: print(0, end = " ") flag = True else: print(1, end = " ") count += 1 lastPos = pos[:] if c == "U" and (pos[0] - 1) > 0: pos[0] -= 1 elif c == "D" and (pos[0] + 1) <= X: pos[0] += 1 elif c == "L" and (pos[1] - 1) > 0: pos[1] -= 1 elif c == "R" and (pos[1] + 1) <= Y: pos[1] += 1 print(1) if not flag else print(count) ``` No
99,858
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` x, y, x0, y0 = map(int, input().split()) S = input() s = [] for i in range(len(S)): s.append(S[i]) X = [[0 for i in range(y + 2)] for j in range(x + 2)] for i in range(y + 2): X[0][i] = -1 X[x + 1][i] = -1 for i in range(x + 2): X[i][0] = -1 X[i][y + 1] = -1 X[x0][y0] = 1 result = [1] nr_explore = 1 for move in s: dx = 0 dy = 0 if move == 'U': dx = -1 dy = 0 elif move == 'D': dx = 1 dy = 0 elif move == 'R': dx = 0 dy = 1 elif move == 'L': dx = 0 dy = -1 if X[x0 + dx][y0 + dy] != -1: x0 += dx y0 += dy if X[x0][y0] == 0: nr_explore += 1 X[x0][y0] = 1 result.append(1) else: result.append(0) else: result.append(0) result[-1] = x * y - nr_explore + 1 for r in result: print(r, end=" ") ``` No
99,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same. After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code. Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it. The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up. Input The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right. The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'. Output Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up. Examples Input 3 4 2 2 UURDRDRL Output 1 1 0 1 1 1 1 0 6 Input 2 2 2 2 ULD Output 1 1 1 1 Note In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <image>. Submitted Solution: ``` x, y, x0, y0 = tuple(map(int, input().split())) s = input() l = len(s) res = [0] * (l + 1) location = [x0, y0] movement = [location[:]] for let in s: #print(location) if let == 'L': if location[1] - 1 > 0: location[1] -= 1 if let == 'R': if location[1] + 1 <= y: location[1] += 1 if let == 'U': if location[0] - 1 > 0: location[0] -= 1 if let == 'D': if location[0] + 1 <= x: location[0] += 1 movement.append(location[:]) for i in range(l + 1): if i > 0: if movement[i] == movement[i - 1]: res[i] = 0 else: res[i] = 1 else: res[i] = 1 res[l] += x * y - sum(res) print(' '.join(list(map(str, res)))) ``` No
99,860
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` string=input() n=len(string) ans=0 for i in range(n-1): if int(string[i])%4==0: ans+=1 temp=string[i:i+2] if temp[0]=='0': temp=string[i+1] if(int(temp)%4==0): ans=ans+i+1 if(int(string[-1])%4==0): ans=ans+1 print(ans) ```
99,861
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` # Anuneet Anand s = input() n = len(s) D = set() for i in range(100): if i%4==0: x = str(i) if i<10: x = "0"+x D.add(x) c = 0 for i in range(n-1): if s[i]+s[i+1] in D: c = c+i+1 for i in range(n): if int(s[i])%4==0: c = c+1 print(c) ```
99,862
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s = [int(x) for x in input()] ans = 0 if s[0] % 4 == 0: ans += 1 for i in range(1, len(s)): if s[i] % 4 == 0: ans += 1 if (s[i] + 10 * s[i - 1]) % 4 == 0: ans += i print(ans) ```
99,863
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s=input() c=0 for i in s: if int(i)%4==0: c+=1 for i in range(len(s)-1): if int(s[i]+s[i+1])%4==0: c+=(i+1) print(c) ```
99,864
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s = input() c = 0 for i in s: if(int(i) % 4 == 0): c += 1 i, j = len(s) - 1, len(s) - 2 while(j >= 0): if(int(''.join(s[j : i + 1])) % 4 == 0): c += len(s) - (len(s) - j) + 1 # print(i, j) i -= 1 j -= 1 print(c) ```
99,865
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s=input() a=[0] count=0 ans=0 for i in range(1,len(s)): p=int(s[i-1]+s[i]) #print(p) if(p%4==0): a.append(1) else: a.append(0) #print(a) for i in range(len(a)): if(a[i]==1): count=count+i for i in s: if(int(i)%4==0): ans+=1 output=count+ans #print(count) #print(ans) print(output) ```
99,866
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s = input() count=0 if int(s[0])%4==0: count+=1 for i in range(1,len(s)): if int(s[i-1])%2==0 and (s[i] in '048'): count+=(i+1) elif int(s[i-1])%2==1 and s[i] in '26': count+=i elif int(s[i])%4==0: count+=1 print(count) ```
99,867
Provide tags and a correct Python 3 solution for this coding contest problem. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Tags: dp Correct Solution: ``` s = input() count = 0 for i in range(len(s)): if s[i] in ["0","4","8"]: count+=1 for i in range(len(s)-1): x = s[i:i+2] if int(x)%4 == 0: count+= i+1 print(count) ```
99,868
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` s = input() ans = 0 for i in range(1, len(s)): if int(s[i - 1: i + 1]) % 4 == 0: ans += i for x in s: if int(x) % 4 == 0: ans += 1 print(ans) ``` Yes
99,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` s = input("") dp = s.count("0")+s.count("4")+s.count("8") for i in range(len(s)-1): if int(s[i] + s[i+1])%4 == 0: dp += (i+1) print(dp) ``` Yes
99,870
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` S = input() result = 0 for i in range(len(S) ): if i == 0: if int(S[i]) % 4 == 0: result += 1 elif int(S[i]) % 4 == 0: if int(S[i-1:i+1]) % 4 == 0: result += i+1 else: result += 1 elif int(S[i-1:i+1]) % 4 == 0: result += i print(result) ``` Yes
99,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` s=input(); ans=0; s=[int(x)for x in s]; ans+=sum([x%4==0 for x in s]); for i in range(len(s)-1): if (s[i]*10+s[i+1])%4==0: ans+=i+1; print(ans); ``` Yes
99,872
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` s = "0" + input() dp = [int(0)]*len(s) res = 0 def pow(a, b) : if b == 0 : return 1 elif b == 1 : return a elif b % 2 == 0 : return pow(a*a, b/2) else : return b*pow(a, b-1) for i in range(1, len(s)) : dp[i] = dp[i-1]*10 + int(s[i]) if dp[i] % 4 == 0 : res += 1 for i in range(1, len(s) - 1) : for j in range(i+1, len(s)) : if int(s[j]) % 2 == 0 and (dp[j] - dp[i]*pow(10,j-i)) % 4 == 0 : res += 1 print(res) ``` No
99,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` n=input() s=str(n) c=0 for i in range(len(s)): temp="" for j in range(i,len(s)): temp+=s[j] print(temp) if(int(temp)%4==0): c+=1 print(c) ``` No
99,874
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` n=int(input()) s=str(n) c=0 for i in range(len(s)): temp="" for j in range(i,len(s)): temp+=s[j] if(int(temp)%4==0): c+=1 print(c) ``` No
99,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9. Output Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 124 Output 4 Input 04 Output 3 Input 5810438174 Output 9 Submitted Solution: ``` import sys def get_array(): return list(map(int, sys.stdin.readline().split())) def get_ints(): return map(int, sys.stdin.readline().split()) def input(): return sys.stdin.readline().strip('\n') s = input() n = len(s) ans = 0 ans += s.count('4') ans += s.count('8') for i in range(1,n): k = s[i-1] + s[i] if int(k)%4 == 0: ans += i if k == '04' or k == '08' or k in ['20','40','60','80']: ans += 1 elif k == '00': ans += 3 print(ans) ``` No
99,876
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` from sys import stdin def main(): n, k = map(int, stdin.readline().split()) ar = list(map(int, stdin.readline().split())) lk = {ar[i] - 1: i for i in range(n)} pair = [-1 for _ in range(n)] for _ in range(k): x, y = map(int, stdin.readline().split()) if lk[y - 1] > lk[x - 1]: pair[y - 1] = max(pair[y - 1], lk[x - 1]) else: pair[x - 1] = max(pair[x - 1], lk[y - 1]) start = 0 end = 0 ok = True ans = 0 while end < n: while end < n and ok: curr = ar[end] - 1 if start <= pair[curr]: ok = False else: end += 1 if end < n: while start <= pair[ar[end] - 1]: ans += end - start start += 1 else: ans += (end - start + 1) * (end - start) // 2 ok = True print(ans) if __name__ == '__main__': main() ```
99,877
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().splitlines(): x, y = map(int, s.split()) px, py = pos[x], pos[y] if px > py: if duo[x] < py: duo[x] = py else: if duo[y] < px: duo[y] = px res = mx = 0 for i, a in enumerate(aa): if mx < duo[a]: mx = duo[a] res += i - mx print(res) if __name__ == '__main__': main() ```
99,878
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` def f(): sizes = input().split(' ') n, m = int(sizes[0]), int(sizes[1]) permStr = input().split(' ') pairsStr = [input() for i in range(m)] indexes = [0 for i in range(n+1)] for i in range(n): indexes[int(permStr[i])] = i+1 lowerNums = [0 for i in range(n+1)] for i in range(m): pair = pairsStr[i].split(" ") a, b = indexes[int(pair[0])], indexes[int(pair[1])] if a < b: l = a h = b else: l = b h = a if l > lowerNums[h]: lowerNums[h] = l counter = 0 left = 0 for i in range(1,n+1): candidate = lowerNums[i] if candidate > left: r=i-1-left q=i-1-candidate counter += (r*(r-1) - q*(q-1))//2 left = candidate r=i-left counter += r*(r-1)//2 print(counter + n) f() ```
99,879
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` """ 652C - Враждебные пары http://codeforces.com/problemset/problem/652/C Предподсчитаем сначала для каждого числа x его позицию posx в перестановке. Это легко сделать за линейное время. Теперь рассмотрим некоторую враждебную пару (a, b) (можно считать, что posa < posb). Запомним для каждого числа a самую левую позицию posb такую, что (a, b) образуют враждебную пару. Обозначим эту величину za. Теперь будем идти по перестановке справа налево и поддерживать позицию rg наибольшего корректного интервала с левым концом в текущей позиции перестановки lf. Значение rg пересчитывается следующим образом: rg = min(rg, z[lf]). Соответсвенно к ответу на каждой итерации нужно прибавлять величину rg - lf + 1. """ def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().splitlines(): x, y = map(int, s.split()) px, py = pos[x], pos[y] if px > py: if duo[x] < py: duo[x] = py else: if duo[y] < px: duo[y] = px res = mx = 0 for i, a in enumerate(aa): if mx < duo[a]: mx = duo[a] res += i - mx print(res) if __name__ == '__main__': main() ```
99,880
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys # TLE without n, m = map(int, input().split()) pos = [None] * (n + 1) for i, a in enumerate(map(int, input().split())): pos[a] = i z = [300005] * (n + 1) for pr in sys.stdin.read().splitlines(): x, y = map(int, pr.split()) if pos[x] > pos[y]: x, y = y, x z[pos[x]] = min(z[pos[x]], pos[y]) lf, rg, ans = n - 1, n - 1, 0 while lf >= 0: rg = min(rg, z[lf] - 1) ans += rg - lf + 1 lf -= 1 print(ans) ```
99,881
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys # TLE without n, m = map(int, input().split()) pos = [None] * (n + 1) for i, a in enumerate(map(int, input().split())): pos[a] = i z = [300005] * (n + 1) for pr in sys.stdin.read().splitlines(): x, y = map(int, pr.split()) if pos[x] > pos[y]: x, y = y, x z[pos[x]] = min(z[pos[x]], pos[y]) ''' if z[pos[x]] is None: z[pos[x]] = pos[y] else: z[pos[x]] = min(z[pos[x]], pos[y]) ''' lf, rg = n - 1, n - 1 ans = 0 while lf >= 0: if z[lf] is not None: rg = min(rg, z[lf] - 1) ans += rg - lf + 1 lf -= 1 print(ans) ```
99,882
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` import sys n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) index = [0]*(n+1) ng = [-1]*n for i, x in enumerate(a): index[x] = i for x, y in ((map(int, line.decode('utf-8').split())) for line in sys.stdin.buffer): s, t = min(index[x], index[y]), max(index[x], index[y]) ng[t] = max(ng[t], s) left = -1 ans = 0 for i in range(n): left = max(left, ng[i]) ans += i - left print(ans) ```
99,883
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Tags: combinatorics, sortings, two pointers Correct Solution: ``` #!/usr/bin/env python3 from __future__ import division, print_function def solver(): import sys blob = sys.stdin.read().split() it = map(int, blob) n, m = next(it), next(it) revp = [0, ] * (n+1) for i in range(n): revp[next(it)] = i pairs = [-1] * (n+1) pairs[-1] = n-1 for _ in range(m): a, b = next(it), next(it) a, b = revp[a], revp[b] if b > a: a, b = b, a pairs[a] = max(pairs[a], b) res = 0 pos = 0 for right, left in enumerate(pairs): if left == -1: continue for i in range(pos, left+1): res = res + right - i pos = max(pos, left + 1) return res def main(): import sys res = solver() sys.stdout.write("{}\n".format(res)) return 0 if __name__ == '__main__': main() ```
99,884
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` #!/usr/bin/env python3 from __future__ import division, print_function import sys def solver(): import re blob =re.split('[ \n]', sys.stdin.read()) # ~ blob = sys.stdin.read().split() it = map(int, blob) n, m = next(it), next(it) revp = [0, ] * (n+1) for i in range(n): revp[next(it)] = i pairs = [-1] * (n+1) pairs[-1] = n-1 for _ in range(m): a, b = next(it), next(it) a, b = revp[a], revp[b] if b > a: a, b = b, a pairs[a] = max(pairs[a], b) res = 0 pos = 0 for right, left in enumerate(pairs): if left == -1: continue for i in range(pos, left+1): res = res + right - i pos = max(pos, left + 1) return res def main(): res = solver() sys.stdout.write("{}\n".format(res)) return 0 if __name__ == '__main__': main() ``` Yes
99,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` #!/usr/bin/env python3 from __future__ import division, print_function def solver(): import sys it = (int(x) for line in sys.stdin.read().splitlines() for x in line.split(' ')) n, m = next(it), next(it) revp = [0, ] * (n+1) for i in range(n): revp[next(it)] = i pairs = [-1] * (n+1) pairs[-1] = n-1 for _ in range(m): a, b = next(it), next(it) a, b = revp[a], revp[b] if b > a: a, b = b, a pairs[a] = max(pairs[a], b) res = 0 pos = 0 for right, left in enumerate(pairs): if left == -1: continue for i in range(pos, left+1): res = res + right - i pos = max(pos, left + 1) return res def main(): import sys res = solver() sys.stdout.write("{}\n".format(res)) return 0 if __name__ == '__main__': main() ``` Yes
99,886
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` def main(): from sys import stdin n, m = map(int, input().split()) n += 1 aa, pos, duo = [0] * n, [0] * n, [0] * n for i, a in enumerate(map(int, input().split()), 1): aa[i] = a pos[a] = i for s in stdin.read().splitlines(): x, y = map(int, s.split()) px, py = pos[x], pos[y] if px > py: if duo[x] < py: duo[x] = py else: if duo[y] < px: duo[y] = px res = mx = 0 for i, a in enumerate(aa): if mx < duo[a]: mx = duo[a] res += i - mx print(res) if __name__ == '__main__': main() # Made By Mostafa_Khaled ``` Yes
99,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` import sys def FoePairs(): n,m=sys.stdin.readline().split() n=int(n) m=int(m) s=n+1 p=[0]*s pos_p=[0]*s closest_pos=[0]*s i=1 #recive la permutacion p y guarda en un nuevo arreglo las posiciones #de esos valores en el arrreglo sin permutar line=sys.stdin.readline().split() while i<s: t=int(line[i-1]) p[i]=t pos_p[t]=i i+=1 #recive los m foe pairs y determina para cada intervalo (x,y) el mayor par posible que contenga a y # como extremo derecho for x in range(0,m): start,finish= sys.stdin.readline().split() start=int(start) finish=int(finish) p_finish=pos_p[finish] p_start=pos_p[start] if p_finish>p_start: closest_pos[finish]=max(closest_pos[finish],p_start) else: closest_pos[start]=max(closest_pos[start],p_finish) i=1 respuesta=0 current_closest_pos=0 while i<s: current_closest_pos=max(current_closest_pos,closest_pos[p[i]]) respuesta+=i-current_closest_pos i+=1 print(respuesta) FoePairs() ``` Yes
99,888
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` #! /usr/bin/env python3 ''' ' Title: ' Author: Cheng-Shih, Wong ' Date: ''' def numOfRange( num ): if num < 2: return 0 return num*(num-1)//2 n, m = map(int, input().split()) p = [int(i) for i in input().split()] q = [0]*(n+1) for i in range(n): q[p[i]] = i vis = set() for i in range(m): u, v = map(int, input().split()) u, v = q[u], q[v] if u > v: u, v = v, u vis.add((u,v)) ps = list(vis) ps.sort() cover = [False]*len(ps) for i in range(len(ps)): for j in range(i+1, len(ps)): if ps[i][1] <= ps[j][0]: break if ps[i][0]<=ps[j][0] and ps[j][1]<=ps[i][1]: cover[i] = True nps = [] for i in range(len(ps)): if not cover[i]: nps.append(ps[i]) ans = 0 for i in range(len(nps)-1): j = i+1 ans += numOfRange(nps[j][1]-nps[i][0]-1) ans += n+numOfRange(nps[0][1])+numOfRange(n-nps[-1][0]-1) print( ans ) ``` No
99,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` n = input() letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] #for i in range(len(n)): #n1.append(n[i]) l = len(n) n1 = [0] * l k = 0 t = 0 for i in range(l): t = 0 for j in range(i + 1, l): if n[j] != "?" and (n[j] in n[i:j]): t = 1 if j - i == 25 and t == 0: k = 1 break if k == 1: break else: print(-1) if k == 1: for s in range(l): if n[s] == "?": for k in range(26): if i <= s and s <= j and (n[i:j + 1].count(letters[k]) == 0): n1[s] = letters[k] if s < i or s > j: n1[s] = letters[0] else: n1[s] = n[s] print("".join(map(str, n1))) ``` No
99,890
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` #import sys #sys.stdin = open('in', 'r') #n = int(input()) n,m = map(int, input().split()) p = [int(x) for x in input().split()] ind = [0]*(n+1) l = [0]*n for i in range(n): ind[p[i]] = i for i in range(m): a,b = map(int, input().split()) x1 = min(ind[a], ind[b]) x2 = max(ind[a], ind[b]) d = x2 - x1 l[x2] = d if l[x2] == 0 else min(d, l[x2]) res = 0 i = 0 cnt = 0 while i < n: if l[i] == 0: cnt += 1 else: res += (1 + cnt)*cnt // 2 cnt = l[i] res -= cnt*(cnt-1)//2 i += 1 if cnt > 0: res += (1 + cnt)*cnt // 2 print(res) ``` No
99,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important). Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair. Input The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs. The second line contains n distinct integers pi (1 ≤ pi ≤ n) — the elements of the permutation p. Each of the next m lines contains two integers (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi) — the i-th foe pair. Note a foe pair can appear multiple times in the given list. Output Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Examples Input 4 2 1 3 2 4 3 2 2 4 Output 5 Input 9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7 Output 20 Note In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). Submitted Solution: ``` #### IMPORTANT LIBRARY #### ############################ ### DO NOT USE import random --> 250ms to load the library ############################ ### In case of extra libraries: https://github.com/cheran-senthil/PyRival ###################### ####### IMPORT ####### ###################### from functools import cmp_to_key from collections import deque, Counter from heapq import heappush, heappop from math import log, ceil ###################### #### STANDARD I/O #### ###################### import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def print(*args, **kwargs): sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input def ii(): return int(inp()) def si(): return str(inp()) def li(lag = 0): l = list(map(int, inp().split())) if lag != 0: for i in range(len(l)): l[i] += lag return l def mi(lag = 0): matrix = list() for i in range(n): matrix.append(li(lag)) return matrix def lsi(): #string list return list(map(str, inp().split())) def print_list(lista, space = " "): print(space.join(map(str, lista))) ###################### ### BISECT METHODS ### ###################### def bisect_left(a, x): """i tale che a[i] >= x e a[i-1] < x""" left = 0 right = len(a) while left < right: mid = (left+right)//2 if a[mid] < x: left = mid+1 else: right = mid return left def bisect_right(a, x): """i tale che a[i] > x e a[i-1] <= x""" left = 0 right = len(a) while left < right: mid = (left+right)//2 if a[mid] > x: right = mid else: left = mid+1 return left def bisect_elements(a, x): """elementi pari a x nell'árray sortato""" return bisect_right(a, x) - bisect_left(a, x) ###################### ### MOD OPERATION #### ###################### MOD = 10**9 + 7 maxN = 5 FACT = [0] * maxN INV_FACT = [0] * maxN def add(x, y): return (x+y) % MOD def multiply(x, y): return (x*y) % MOD def power(x, y): if y == 0: return 1 elif y % 2: return multiply(x, power(x, y-1)) else: a = power(x, y//2) return multiply(a, a) def inverse(x): return power(x, MOD-2) def divide(x, y): return multiply(x, inverse(y)) def allFactorials(): FACT[0] = 1 for i in range(1, maxN): FACT[i] = multiply(i, FACT[i-1]) def inverseFactorials(): n = len(INV_FACT) INV_FACT[n-1] = inverse(FACT[n-1]) for i in range(n-2, -1, -1): INV_FACT[i] = multiply(INV_FACT[i+1], i+1) def coeffBinom(n, k): if n < k: return 0 return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n-k])) ###################### #### GRAPH ALGOS ##### ###################### # ZERO BASED GRAPH def create_graph(n, m, undirected = 1, unweighted = 1): graph = [[] for i in range(n)] if unweighted: for i in range(m): [x, y] = li(lag = -1) graph[x].append(y) if undirected: graph[y].append(x) else: for i in range(m): [x, y, w] = li(lag = -1) w += 1 graph[x].append([y,w]) if undirected: graph[y].append([x,w]) return graph def create_tree(n, unweighted = 1): children = [[] for i in range(n)] if unweighted: for i in range(n-1): [x, y] = li(lag = -1) children[x].append(y) children[y].append(x) else: for i in range(n-1): [x, y, w] = li(lag = -1) w += 1 children[x].append([y, w]) children[y].append([x, w]) return children def dist(tree, n, A, B = -1): s = [[A, 0]] massimo, massimo_nodo = 0, 0 distanza = -1 v = [-1] * n while s: el, dis = s.pop() if dis > massimo: massimo = dis massimo_nodo = el if el == B: distanza = dis for child in tree[el]: if v[child] == -1: v[child] = 1 s.append([child, dis+1]) return massimo, massimo_nodo, distanza def diameter(tree): _, foglia, _ = dist(tree, n, 0) diam, _, _ = dist(tree, n, foglia) return diam def dfs(graph, n, A): v = [-1] * n s = [[A, 0]] v[A] = 0 while s: el, dis = s.pop() for child in graph[el]: if v[child] == -1: v[child] = dis + 1 s.append([child, dis + 1]) return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges def bfs(graph, n, A): v = [-1] * n s = deque() s.append([A, 0]) v[A] = 0 while s: el, dis = s.popleft() for child in graph[el]: if v[child] == -1: v[child] = dis + 1 s.append([child, dis + 1]) return v #visited: -1 if not visited, otherwise v[B] is the distance in terms of edges #FROM A GIVEN ROOT, RECOVER THE STRUCTURE def parents_children_root_unrooted_tree(tree, n, root = 0): q = deque() visited = [0] * n parent = [-1] * n children = [[] for i in range(n)] q.append(root) while q: all_done = 1 visited[q[0]] = 1 for child in tree[q[0]]: if not visited[child]: all_done = 0 q.appendleft(child) if all_done: for child in tree[q[0]]: if parent[child] == -1: parent[q[0]] = child children[child].append(q[0]) q.popleft() return parent, children # CALCULATING LONGEST PATH FOR ALL THE NODES def all_longest_path_passing_from_node(parent, children, n): q = deque() visited = [len(children[i]) for i in range(n)] downwards = [[0,0] for i in range(n)] upward = [1] * n longest_path = [1] * n for i in range(n): if not visited[i]: q.append(i) downwards[i] = [1,0] while q: node = q.popleft() if parent[node] != -1: visited[parent[node]] -= 1 if not visited[parent[node]]: q.append(parent[node]) else: root = node for child in children[node]: downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse = True)[0:2] s = [node] while s: node = s.pop() if parent[node] != -1: if downwards[parent[node]][0] == downwards[node][0] + 1: upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1]) else: upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0]) longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1 for child in children[node]: s.append(child) return longest_path ### TBD SUCCESSOR GRAPH 7.5 ### TBD TREE QUERIES 10.2 da 2 a 4 ### TBD ADVANCED TREE 10.3 ### TBD GRAPHS AND MATRICES 11.3.3 e 11.4.3 e 11.5.3 (ON GAMES) ###################### ## END OF LIBRARIES ## ###################### def bin(n): return n*(n-1) // 2 n,m = li() p = li(-1) c = [set() for i in range(n)] for el in range(m): x, y = li(-1) c[x].add(y) c[y].add(x) used = [0] * n i, f = 0, 0 co = n while f + 1 < n: used[p[i]] = 1 f += 1 flag = 1 for el in c[p[f]]: if used[el] == 1: flag = 0 if flag == 0: j = f-1 trovato = 0 while j >= i: if trovato: used[p[j]] = 0 else: if p[j] in c[p[f]]: used[p[j]] = 0 i = j + 1 trovato = 1 j -= 1 co += f - i else: used[p[f]] = 1 co += f - i print(co) ``` No
99,892
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` import sys import math def main(): str_list = sys.stdin.readline().strip("\n").split(" ") number_list = [int(str(i)) for i in str_list] t = number_list[0] x = number_list[1] res = math.ceil(t / x) if(t % x == 0): res += 1 res *= x print(res) return res main() ```
99,893
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` n, k = map(int, input().split()) print((int(n / k) + 1) * k) ```
99,894
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` import sys str_list = sys.stdin.readline().strip("\n").split(" ") number_list = [int(str(i)) for i in str_list] t = number_list[0] x = number_list[1] y = (t + x)%x res = t+x - y print(res) ```
99,895
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` from sys import stdin def parse(): line = stdin.readline().split() N, K = map( int, line) quo, rem = int(N/K), N%K ans = (quo+1)*K print( ans) parse() ```
99,896
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` n,k=map(int,input().split()) print(n+k-n%k) ```
99,897
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` n, k = map(int, input().split()) ans = (n // k + 1) * k print(ans) ```
99,898
Provide tags and a correct Python 3 solution for this coding contest problem. Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k. Input The only line contains two integers n and k (1 ≤ n, k ≤ 109). Output Print the smallest integer x > n, so it is divisible by the number k. Examples Input 5 3 Output 6 Input 25 13 Output 26 Input 26 13 Output 39 Tags: implementation, math Correct Solution: ``` #A cin=lambda:map(int,input().split()) n,k=cin() print((n//k)*k+k) ```
99,899