message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa.
instruction
0
99,141
14
198,282
Tags: dfs and similar, math Correct Solution: ``` def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) n = int(input()) c = [int(v)-1 for v in input().split(' ')] t = 1 for i in range(n): k = i for j in range(1, n+2): k = c[k] if k == i: break if j > n: print(-1) exit() t = lcm(t, j if j % 2 != 0 else j // 2) print(t) # Made By Mostafa_Khaled ```
output
1
99,141
14
198,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` import math n=int(input()) a=list(map(int,input().split())) if len(set(a))!=len(a): print(-1) else: ans,cycle=None,None visited=[False]*(n+1) for i in range(n): if visited[i+1]: continue count,v=0,[] index,value=i+1,-1 while value!=i+1: visited[index]=True v.append(index) value=a[index-1] index=value cycle=[len(v)//2,len(v)][len(v)%2] if i==0: ans=cycle else: ans=(ans*cycle)//math.gcd(ans,cycle) print(ans) ```
instruction
0
99,142
14
198,284
Yes
output
1
99,142
14
198,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` from fractions import gcd def dfs(node): if (vis[node] == idd[0]): return node cycleLen[0] += 1 vis[node] = idd[0] return dfs(crush[node]) n = int(input()) crush = list(map(int, input().split())) for i in range(n): crush[i] -= 1 vis = [0] * n ans = 10**100 idd = [0] V = [] for i in range(n): idd[0] += 1 cycleLen = [0] if (dfs(i) != i): ans = -1 V.append(cycleLen[0]) V.sort() def lcm(x, y): return x * y // gcd(x, y) if (ans == -1): print(ans) else: ans = 1 inc = 1 for item in V: mem = {} bad = False while (True): if (ans % item == 0): break if (item % 2 == 0 and ans % item == item // 2): break if (ans % item in mem): bad = True break mem[ans % item] = 1 ans += inc if (bad): ans = -1 break inc = lcm(inc, ans) print(ans) ```
instruction
0
99,143
14
198,286
Yes
output
1
99,143
14
198,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` from sys import stdin, stdout, setrecursionlimit input = stdin.readline # setrecursionlimit(int(1e6)) inf = float('inf') from collections import defaultdict as dd from collections import Counter, deque from heapq import * import math from math import floor, ceil, sqrt def geti(): return map(int, input().strip().split()) def getl(): return list(map(int, input().strip().split())) def getis(): return map(str, input().strip().split()) def getls(): return list(map(str, input().strip().split())) def gets(): return input().strip() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') def solve(): n = geta() a = getl() edges = dd(list) for i in range(n): edges[i].append(a[i]-1) dist = [[inf]*n for _ in range(n)] def dfs(root, par, temp = 0): vis[root] = True for node in edges[root]: dist[par][node] = temp + 1 if node not in vis: dfs(node, par, temp+1) ans = [] vis = dd(int) ok = dd(int) def dfs(root, par, dist = 0): if root == par and dist: ok[par] = True if dist&1: ans.append(dist) else: ans.append(dist//2) return if root in vis: return vis[root] = True for node in edges[root]: dfs(node, par, dist+1) need = [] for i in range(n): if i not in vis: need.append(i) dfs(i, i) # print(ans) for i in need: if i not in ok: print(-1) break else: ans = Counter(ans) ans = sorted(ans) # print(ans) vis = [False]*(len(ans)+1) ok = [] for i in range(len(ans)): if ans[i] == 1 or vis[i]: continue temp = [] for j in range(i, len(ans)): if ans[j] % ans[i] == 0: temp.append(ans[j]) vis[j] = True now = temp[0] g = temp[0] # print(temp) for k in range(1, len(temp)): now *= temp[k] g = math.gcd(g, temp[k]) now = now//g g = now if g!=now: ok.append(now//g) else: ok.append(now) # print(ok) now = 1 if ok: now = ok[0] g = ok[0] for k in range(1, len(ok)): now *= ok[k] g = math.gcd(g, ok[k]) now = now//g g = now print(now) if __name__=='__main__': solve() ```
instruction
0
99,144
14
198,288
Yes
output
1
99,144
14
198,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` #from collections import deque from functools import reduce n = int(input()) crush = [int(i) - 1 for i in input().split()] def parity_treat(n): if n%2 == 0: return n//2 else: return n def gcd(a,b): while b: a, b = b, a%b return a def lcm(a,b): return a * b // gcd(a,b) def lcmm(*args): return reduce(lcm, args) if len(set(crush)) < n: print(-1) else: component_size = [] visited = set() for i in range(n): if i not in visited: tmp = 1 start = i visited.add(start) j = crush[start] while j != start: visited.add(j) j = crush[j] tmp+=1 component_size.append(tmp) component_size = [parity_treat(i) for i in component_size] print(lcmm(*component_size)) ```
instruction
0
99,145
14
198,290
Yes
output
1
99,145
14
198,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` def gcd(a,b): while b > 0: a, b = b, a % b return a def lcm(a, b): return int(a * b / gcd(a, b)) def run(n, crush): visited = [False] * n cycle_size = 1 for i in range(0, n): if visited[i]: continue x = i c = 0 while (not visited[x]): visited[x] = True x = crush[x] - 1 c += 1 if x != i: return -1 cycle_size = lcm(cycle_size, c) if cycle_size % 2 == 0: cycle_size /= 2 return cycle_size n = int(input()) crush = [int(x) for x in input().split()] print(run(n,crush)) ```
instruction
0
99,146
14
198,292
No
output
1
99,146
14
198,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` ###### ### ####### ####### ## # ##### ### ##### # # # # # # # # # # # # # ### # # # # # # # # # # # # # ### ###### ######### # # # # # # ######### # ###### ######### # # # # # # ######### # # # # # # # # # # # #### # # # # # # # # # # ## # # # # # ###### # # ####### ####### # # ##### # # # # from __future__ import print_function # for PyPy2 # from itertools import permutations # from functools import cmp_to_key # for adding custom comparator # from fractions import Fraction from collections import * from sys import stdin # from bisect import * from heapq import * from math import * g = lambda : stdin.readline().strip() gl = lambda : g().split() gil = lambda : [int(var) for var in gl()] gfl = lambda : [float(var) for var in gl()] gcl = lambda : list(g()) gbs = lambda : [int(var) for var in g()] rr = lambda x : reversed(range(x)) mod = int(1e9)+7 inf = float("inf") n, = gil() nxt = [0] + gil() vis = [0]*(n+1) c = set() def cycle(p): tt = 0 start = p while vis[p] == 0: tt += 1 vis[p] = 1 p = nxt[p] if p != start: print(-1) exit() return tt for p in range(1, n+1): if vis[p] : continue tt = cycle(p) if tt&1 : c.add(tt) else: c.add(tt//2) if 1 in c:c.remove(1) c = list(c) if len(c) <= 1: print(c[0] if c else 1) exit() p = 1 gc = c[0] if c else 1 for ci in c: gc = gcd(gc, ci) p *= ci # print(p, gc) print(p//gc) ```
instruction
0
99,147
14
198,294
No
output
1
99,147
14
198,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` input() crush = [0] + [int(x) for x in input().split()] visited = set() circle_sizes = [] def solve(): for i in range(len(crush)): if i not in visited: start, cur, count = i, i, 0 while cur not in visited: visited.add(cur) count += 1 cur = crush[cur] if cur != start: return -1 circle_sizes.append(count if count % 2 else count // 2) ans = max(circle_sizes) for size in circle_sizes: if ans % size != 0: return -1 return ans print(solve()) ```
instruction
0
99,148
14
198,296
No
output
1
99,148
14
198,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i). Input The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush. Output If there is no t satisfying the condition, print -1. Otherwise print such smallest t. Examples Input 4 2 3 1 4 Output 3 Input 4 4 4 4 4 Output -1 Input 4 2 1 4 3 Output 1 Note In the first sample suppose t = 3. If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1. The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4. In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa. Submitted Solution: ``` def read_int(): return int(input()) def read_ints(): return map(int, input().split(' ')) def gcd(x, y): return x if y == 0 else gcd(y, x % y) n = read_int() a = list(read_ints()) vis = [False for i in range(n)] loop = 0 ok = True for i in range(n): if vis[i]: continue current = i length = 0 while not vis[current]: vis[current] = True current = a[current] - 1 length += 1 if current != i: ok = False print(-1) break if loop == 0: loop = length else: loop = loop * length // gcd(loop, length) if ok: print(loop if loop > 2 else 1) ```
instruction
0
99,149
14
198,298
No
output
1
99,149
14
198,299
Provide tags and a correct Python 3 solution for this coding contest problem. A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. <image> You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts. Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them. Note that the final necklace should remain as one circular part of the same length as the initial necklace. Input The only line of input contains a string s (3 ≤ |s| ≤ 100), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. Output Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO". You can print each letter in any case (upper or lower). Examples Input <span class="tex-font-style-tt">-o-o--</span> Output YES Input <span class="tex-font-style-tt">-o---</span> Output YES Input <span class="tex-font-style-tt">-o---o-</span> Output NO Input ooo Output YES
instruction
0
99,230
14
198,460
Tags: implementation, math Correct Solution: ``` s = input() count1 = count2 = 0 for i in s: if i =="-": count1+=1 else: count2+=1 if count2==0 or count1==0: print("YES") else: if count1%count2==0: print("YES") else: print("NO") ```
output
1
99,230
14
198,461
Provide a correct Python 3 solution for this coding contest problem. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2
instruction
0
99,325
14
198,650
"Correct Solution: ``` from math import gcd mod=998244353 N=int(input()) a=list(map(int,input().split())) a.sort() ans=1 for i in range(N): g=gcd(i,a[i]) ans=(ans*g)%mod print(ans) ```
output
1
99,325
14
198,651
Provide a correct Python 3 solution for this coding contest problem. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2
instruction
0
99,326
14
198,652
"Correct Solution: ``` import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from fractions import gcd from functools import reduce MOD = 998244353 N,*A = map(int,read().split()) A.sort() """ 安い鳥から追加していく。(サイクルの個数 -> 美しさ)が多項式倍で遷移する。 Gaussの補題より、最大個数かけるだけ """ answer = reduce(lambda x,y: x*y%MOD, (gcd(i,x) for i,x in enumerate(A))) print(answer) ```
output
1
99,326
14
198,653
Provide a correct Python 3 solution for this coding contest problem. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2
instruction
0
99,327
14
198,654
"Correct Solution: ``` N = int(input()) a = list(map(int,input().split())) Mod = 998244353 def gcd(a, b): while b: a, b = b, a % b return a a.sort() ans = 1 for i in range(N): ans *= gcd(a[i],i) ans %= Mod print(ans) ```
output
1
99,327
14
198,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2 Submitted Solution: ``` N=int(input()) L=list(map(int,input().split())) print(min(L)) ```
instruction
0
99,328
14
198,656
No
output
1
99,328
14
198,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2 Submitted Solution: ``` import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) ans = min(a) print(ans) ```
instruction
0
99,329
14
198,658
No
output
1
99,329
14
198,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2 Submitted Solution: ``` N=int(input()) a=list(map(int,input().split())) print(min(a)) ```
instruction
0
99,330
14
198,660
No
output
1
99,330
14
198,661
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Niwango-kun has \\(N\\) chickens as his pets. The chickens are identified by numbers \\(1\\) to \\(N\\), and the size of the \\(i\\)-th chicken is a positive integer \\(a_i\\). \\(N\\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \\(p\\) of \\(1, \ldots , N\\). Chicken \\(i\\) takes chicken \\(p_i\\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \\(i\\) as the set consisting of chickens \\(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\\). It can be proven that after each chicken takes some chicken's hand, the \\(N\\) chickens can be decomposed into cycles. The beauty \\(f(p)\\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \\(b_i \ (1 \leq i \leq N)\\) be the sum of \\(f(p)\\) among all possible permutations \\(p\\) for which \\(i\\) cycles are formed in the procedure above. Find the greatest common divisor of \\(b_1, b_2, \ldots, b_N\\) and print it \\({\rm mod} \ 998244353\\). Constraints * \\(1 \leq N \leq 10^5\\) * \\(1 \leq a_i \leq 10^9\\) * All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Examples Input 2 4 3 Output 3 Input 4 2 5 2 5 Output 2 Submitted Solution: ``` import numpy as np def main(): n = int(input()) a = list(map(int, input().split())) m = np.mean(a) r = a[np.argmin((a-m)**2)] print(r) main() ```
instruction
0
99,331
14
198,662
No
output
1
99,331
14
198,663
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,373
14
198,746
"Correct Solution: ``` N = int(input()) a = [int(i) for i in input().split()] w = [int(i) for i in input().split()] rightMin = 1001 leftMin = 1001 for i in range(N): if a[i] == 0: rightMin = min(rightMin, w[i]) else: leftMin = min(leftMin, w[i]) if rightMin == 1001 or leftMin == 1001: print(0) else: print(rightMin + leftMin) ```
output
1
99,373
14
198,747
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,374
14
198,748
"Correct Solution: ``` n = int(input()) a = list(map(int,input().split())) w = list(map(int,input().split())) INF = 10**9 x = [INF]*2 for i in range(n): x[a[i]] = min(x[a[i]], w[i]) ans = sum(x) if ans >= INF: ans = 0 print(ans) ```
output
1
99,374
14
198,749
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,375
14
198,750
"Correct Solution: ``` N = input() a = [int(x) for x in input().split()] w = [int(x) for x in input().split()] R = [w for a, w in zip(a, w) if a == 0] L = [w for a, w in zip(a, w) if a == 1] if R and L: print(min(R) + min(L)) else: print(0) ```
output
1
99,375
14
198,751
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,376
14
198,752
"Correct Solution: ``` n = int(input()) alst = list(map(int, input().split())) wlst = list(map(int, input().split())) right = [w for a, w in zip(alst, wlst) if a == 0] left = [w for a, w in zip(alst, wlst) if a == 1] if right and left: print(min(right) + min(left)) else: print(0) ```
output
1
99,376
14
198,753
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,377
14
198,754
"Correct Solution: ``` N = int(input()) *A, = map(int, input().split()) *W, = map(int, input().split()) INF = 10**9 l = r = INF for a, w in zip(A, W): if a: r = min(w, r) else: l = min(w, l) if l == INF or r == INF: print(0) else: print(l+r) ```
output
1
99,377
14
198,755
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,378
14
198,756
"Correct Solution: ``` n = int(input()) a = [int(_) for _ in input().split()] w = [int(_) for _ in input().split()] if sum(a) == n or sum(a) == 0: print(0) quit() lia = [] lib = [] for i in range(n): if a[i] == 0: lia.append(w[i]) else: lib.append(w[i]) print(min(lia)+min(lib)) ```
output
1
99,378
14
198,757
Provide a correct Python 3 solution for this coding contest problem. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all. * If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all. You wish you could minimize the total amount of frustration by clever sitting order arrangement. Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ $w_1$ $w_2$ $...$ $w_N$ The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears. Output Output the minimum total frustration the sages bear. Examples Input 5 1 0 0 1 0 2 3 5 1 2 Output 3 Input 3 0 0 0 1 2 3 Output 0
instruction
0
99,379
14
198,758
"Correct Solution: ``` n = int(input()) aw = [[0,0] for i in range(n)] for i, a in enumerate(map(int, input().split())): aw[i][0] = a for i, w in enumerate(map(int, input().split())): aw[i][1] = w migimin = 1001 hidarimin = 1001 for a,w in aw: if a: hidarimin = min(hidarimin, w) else: migimin = min(migimin, w) if hidarimin>1000 or migimin>1000: print(0) else: print(hidarimin+migimin) ```
output
1
99,379
14
198,759
Provide tags and a correct Python 3 solution for this coding contest problem. Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases. When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually). Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme. Input The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106. Output Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point. Examples Input X Output 0.000000 Input LXRR Output 50.000000 Note In the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.
instruction
0
99,567
14
199,134
Tags: binary search, dp, greedy Correct Solution: ``` def solve(): original = input() temp = [original[0]] for i in range(1, len(original)): if original[i] == original[i - 1] != 'X': temp.append('X') temp.append(original[i]) augmented = ''.join(temp) answer = 0 if augmented[0] == augmented[-1] != 'X': answer = max(rate(augmented + 'X'), rate('X' + augmented)) else: answer = rate(augmented) print('%d.%06d' % (answer / 1000000, answer % 1000000)) def rate(seq): correct, total, unknown, indicator = 0, 0, 0, 0 left_step = True for action in seq: if action == 'X': total += 1 left_step = not left_step else: if left_step and action == 'L' or not left_step and action == 'R': correct += 1 total += 1 indicator = 0 left_step = not left_step else: correct += 1 total += 2 unknown += indicator indicator = 1 - indicator if total % 2 == 1: total += 1 unknown += indicator if correct * 2 > total: correct -= unknown total -= unknown * 2 return correct * 100000000 // total solve() ```
output
1
99,567
14
199,135
Provide tags and a correct Python 3 solution for this coding contest problem. Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases. When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually). Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme. Input The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106. Output Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point. Examples Input X Output 0.000000 Input LXRR Output 50.000000 Note In the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.
instruction
0
99,568
14
199,136
Tags: binary search, dp, greedy Correct Solution: ``` __author__ = 'Darren' def solve(): original = input() temp = [original[0]] for i in range(1, len(original)): if original[i] == original[i-1] != 'X': temp.append('X') temp.append(original[i]) augmented = ''.join(temp) answer = 0 if augmented[0] == augmented[-1] != 'X': answer = max(rate(augmented+'X'), rate('X'+augmented)) else: answer = rate(augmented) print('%d.%06d' % (answer / 1000000, answer % 1000000)) def rate(seq): correct, total, unknown, indicator = 0, 0, 0, 0 left_step = True for action in seq: if action == 'X': total += 1 left_step = not left_step else: if left_step and action == 'L' or not left_step and action == 'R': correct += 1 total += 1 indicator = 0 left_step = not left_step else: correct += 1 total += 2 unknown += indicator indicator = 1 - indicator if total % 2 == 1: total += 1 unknown += indicator if correct * 2 > total: correct -= unknown total -= unknown * 2 return correct * 100000000 // total if __name__ == '__main__': solve() ```
output
1
99,568
14
199,137
Provide tags and a correct Python 3 solution for this coding contest problem. This is the easy version of the problem. The difference is constraints on the number of wise men and the time limit. You can make hacks only if all versions of this task are solved. n wise men live in a beautiful city. Some of them know each other. For each of the n! possible permutations p_1, p_2, …, p_n of the wise men, let's generate a binary string of length n-1: for each 1 ≤ i < n set s_i=1 if p_i and p_{i+1} know each other, and s_i=0 otherwise. For all possible 2^{n-1} binary strings, find the number of permutations that produce this binary string. Input The first line of input contains one integer n (2 ≤ n ≤ 14) — the number of wise men in the city. The next n lines contain a binary string of length n each, such that the j-th character of the i-th string is equal to '1' if wise man i knows wise man j, and equals '0' otherwise. It is guaranteed that if the i-th man knows the j-th man, then the j-th man knows i-th man and no man knows himself. Output Print 2^{n-1} space-separated integers. For each 0 ≤ x < 2^{n-1}: * Let's consider a string s of length n-1, such that s_i = ⌊ \frac{x}{2^{i-1}} ⌋ mod 2 for all 1 ≤ i ≤ n - 1. * The (x+1)-th number should be equal to the required answer for s. Examples Input 3 011 101 110 Output 0 0 0 6 Input 4 0101 1000 0001 1010 Output 2 2 6 2 2 6 2 2 Note In the first test, each wise man knows each other, so every permutation will produce the string 11. In the second test: * If p = \{1, 2, 3, 4\}, the produced string is 101, because wise men 1 and 2 know each other, 2 and 3 don't know each other, and 3 and 4 know each other; * If p = \{4, 1, 2, 3\}, the produced string is 110, because wise men 1 and 4 know each other, 1 and 2 know each other and 2, and 3 don't know each other; * If p = \{1, 3, 2, 4\}, the produced string is 000, because wise men 1 and 3 don't know each other, 3 and 2 don't know each other, and 2 and 4 don't know each other.
instruction
0
99,592
14
199,184
Tags: bitmasks, brute force, dp, meet-in-the-middle Correct Solution: ``` from sys import stdout n = int(input()) class Person: num = n - 1 def __init__(self, rel): self.relationship = int(rel, 2) def __getitem__(self, k): return (self.relationship >> Person.num - k) & 1 rel = [Person(input()) for _ in range(n)] dp = [[0] * n for _ in range(1 << n)] for people in range(1, 1 << n): ones = [i for i in range(n) if people & (1 << i)] # print(f'ones: {ones}') one_num = len(ones) if one_num == 1: dp[people][ones[0]] = [1] continue for i in ones: dp[people][i] = [0] * (1 << one_num - 1) pre_people = people ^ (1 << i) for j in ones: if j == i: continue for pre_s, times in enumerate(dp[pre_people][j]): s = pre_s | (rel[j][i] << one_num - 2) # print(f'dp[{people}][{i}][{s}]: {dp[people][i][s]}') dp[people][i][s] += times people = (1 << n) - 1 for s in range(1 << (n-1)): ans = 0 for i in range(n): ans += dp[people][i][s] print(ans, end=' ') ```
output
1
99,592
14
199,185
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,730
14
199,460
Tags: combinatorics, math Correct Solution: ``` x = input() n = len(x) mod = 10 ** 9 + 7 ans = 0 for i in range(n): if x[i] == '1': pref = pow(2, i, mod) suf = pow(2, n - i - 1, mod) ** 2 ans += (pref * suf) % mod print(ans % mod) ```
output
1
99,730
14
199,461
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,731
14
199,462
Tags: combinatorics, math Correct Solution: ``` #!/usr/local/bin/python3.3 -tt import sys if __name__ == '__main__': for l in sys.stdin: s = l.strip() break n = len(s) d = 2 ** (n - 1) print(d * int(s, 2) % 1000000007) ```
output
1
99,731
14
199,463
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,732
14
199,464
Tags: combinatorics, math Correct Solution: ``` s = input() s = s[::-1] ans = 0 for i in range(len(s)): if s[i] == '1': ans += ((2 ** i) ** 2) * (2**(len(s) - i - 1)) print(ans % (10**9+7)) ```
output
1
99,732
14
199,465
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,733
14
199,466
Tags: combinatorics, math Correct Solution: ``` p = 1000000007 s = input() print(int(s,2) * pow(2, len(s) - 1) % p) # Made By Mostafa_Khaled ```
output
1
99,733
14
199,467
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,734
14
199,468
Tags: combinatorics, math Correct Solution: ``` n = input().strip() s = len(n) k = int(n,2) start = 4 **( s-1) zib = 2**(s-1) step = 2**(s-1) print((start+(k-zib)*step)%(10**9+7)) ```
output
1
99,734
14
199,469
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,735
14
199,470
Tags: combinatorics, math Correct Solution: ``` MOD = int(1e9 + 7) x = input()[::-1] n = len(x) res = 0 for i, t in enumerate(x): if t == '1': res = (res + (1 << (n - 1 + i))) % MOD print(res) ```
output
1
99,735
14
199,471
Provide tags and a correct Python 3 solution for this coding contest problem. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1
instruction
0
99,736
14
199,472
Tags: combinatorics, math Correct Solution: ``` MOD = 1000000007 ans = 0 x = input().strip() n = len(x) for i, v in enumerate(x): if v == "1": ans += pow(2, i, MOD) * pow(2, (n - i - 1) * 2, MOD) % MOD ans %= MOD print(ans) ```
output
1
99,736
14
199,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1 Submitted Solution: ``` MOD = int(10e9 + 7) x = input()[::-1] n = len(x) res = 0 for i, t in enumerate(x): if t == '1': res = (res + (1 << (n - 1 + i))) % MOD print(res) ```
instruction
0
99,737
14
199,474
No
output
1
99,737
14
199,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1 Submitted Solution: ``` s = input() s = s[::-1] ans = 0 for i in range(len(s)): if s[i] == '1': ans += (2 ** i) ** 2 else: ans *= 2 print(ans % (10**9+7)) ```
instruction
0
99,738
14
199,476
No
output
1
99,738
14
199,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC. One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC. The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d. You are given a binary number of length n named x. We know that member i from MDC dances with member <image> from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7). Expression <image> denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor». Input The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros. Output Print the complexity of the given dance assignent modulo 1000000007 (109 + 7). Examples Input 11 Output 6 Input 01 Output 2 Input 1 Output 1 Submitted Solution: ``` s = input() s = s[::-1] ans = 0 for i in range(len(s)): if s[i] == '1': ans += 2 ** i else: ans *= 2 print(ans % (10**9+7)) ```
instruction
0
99,739
14
199,478
No
output
1
99,739
14
199,479
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>
instruction
0
99,829
14
199,658
Tags: combinatorics Correct Solution: ``` n=int(input()) ans=27**n-7**n mod=10**9+7 print(ans%mod) ```
output
1
99,829
14
199,659
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>
instruction
0
99,830
14
199,660
Tags: combinatorics Correct Solution: ``` n=int(input()) p=9**n*3**n print((p-7**n)%1000000007) ```
output
1
99,830
14
199,661
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>
instruction
0
99,831
14
199,662
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) ```
output
1
99,831
14
199,663
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>
instruction
0
99,832
14
199,664
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)) ```
output
1
99,832
14
199,665
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>
instruction
0
99,833
14
199,666
Tags: combinatorics Correct Solution: ``` n = int(input()) print((27 ** n - 7 ** n) % (10 ** 9 + 7)) ```
output
1
99,833
14
199,667
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>
instruction
0
99,834
14
199,668
Tags: combinatorics Correct Solution: ``` n = int(input()) mod = 10 ** 9 + 7 print((27 ** n - 7 ** n) % mod) ```
output
1
99,834
14
199,669
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>
instruction
0
99,835
14
199,670
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) ```
output
1
99,835
14
199,671
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>
instruction
0
99,836
14
199,672
Tags: combinatorics Correct Solution: ``` n = int(input()) ans = 27**n - 7**n const = 10**9 + 7 print(ans%const) ```
output
1
99,836
14
199,673
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) ```
instruction
0
99,837
14
199,674
Yes
output
1
99,837
14
199,675
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); ```
instruction
0
99,838
14
199,676
Yes
output
1
99,838
14
199,677
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) ```
instruction
0
99,839
14
199,678
Yes
output
1
99,839
14
199,679
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) ```
instruction
0
99,840
14
199,680
Yes
output
1
99,840
14
199,681
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)) ```
instruction
0
99,841
14
199,682
No
output
1
99,841
14
199,683