message
stringlengths
2
67k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
463
109k
cluster
float64
19
19
__index_level_0__
int64
926
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second
instruction
0
95,592
19
191,184
Tags: games, greedy Correct Solution: ``` import io, os # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline ii=lambda:int(input()) kk=lambda:map(int,input().split()) ll=lambda:list(kk()) n,a1,a2=ii(),input(),input() locs = [0]*4 for i in range(2*n): locs[int(a1[i])+2*int(a2[i])]+=1 rm = min(locs[1],locs[2]) locs[1]-=rm locs[2]-=rm locs[3]=locs[3]&1 if locs[1]: print("First") else: if locs[3]: if locs[2]==0: print("First") elif locs[2]<3: print("Draw") else: print("Second") else: if locs[2]<2: print("Draw") else: print("Second") ```
output
1
95,592
19
191,185
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second
instruction
0
95,593
19
191,186
Tags: games, greedy Correct Solution: ``` import sys import math n = int(input()) st1 = input() st2 = input() k = 0 res = 0 for i in range(2 * n): if(st1[i] == '1' and st2[i] == '1'): k += 1 elif(st1[i] == '1'): res -= 1 elif(st2[i] == '1'): res += 1 res1 = int(k / 2) + k % 2 res2 = k - res1 v = 0 if(k % 2 == 0): v = -1 if(res < 0): b = math.fabs(res) res1 += int(b / 2) + res % 2 elif(res > 0): res += v res2 += int(res / 2) + res % 2 if(res1 > res2): print("First") elif(res1 < res2): print("Second") else: print("Draw") ```
output
1
95,593
19
191,187
Provide tags and a correct Python 3 solution for this coding contest problem. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second
instruction
0
95,594
19
191,188
Tags: games, greedy Correct Solution: ``` from sys import stdin from math import ceil, floor n = int(input()) s = stdin.readline() t = stdin.readline() first = 0 second = 0 draw = 0 for i in range(2*n): if( s[i] == '1' and t[i] == '1' ): draw += 1 elif( s[i] == '1' ): first += 1 elif( t[i] == '1' ): second += 1 #print( first, second, draw ) if( first > second ): if( draw%2 == 1 ): first -= ceil( (first-second)/2 ) else: first -= (first-second) - ceil( (first-second)/2 ) elif( second > first ): if( draw%2 == 1 ): second -= (second-first) - ceil( (second-first)/2 ) else: second -= ceil( (second-first)/2 ) #print( first, second, draw ) first += ceil(draw/2.0) second += (draw - ceil(draw/2.0)) #print( first, second, draw ) if( first > second ): print( "First" ) elif( second > first ): print( "Second" ) else: print("Draw") ```
output
1
95,594
19
191,189
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys import bisect try: fin = open('in') except: fin = sys.stdin input = lambda: fin.readline().strip() n=int(input()) a=list(map(int,input())) b=list(map(int,input())) r=[[0,0],[0,0]] for i in range(2*n): r[a[i]][b[i]] += 1 t=[0]*2 for i in range(2*n): j=i%2 if r[1][1]>0: r[1][1]-=1 t[j]+=[1,1][j] elif r[0][1]>0: r[0][1]-=1 t[j]+=[0,1][j] elif r[1][0]>0: r[1][0]-=1 t[j]+=[1,0][j] else: r[0][0]-=1 t[j]+=[0,0][j] x,y=t if x>y:print("First") elif x<y:print("Second") else:print("Draw") ```
instruction
0
95,595
19
191,190
Yes
output
1
95,595
19
191,191
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` n = input() s = input() t = input() fir = 0 sec = 0 same = 0 for (l, r) in zip(s, t): if l == '1': fir += 1 if r == '1': same += 1 sec += 1 elif r == '1': sec += 1 if same % 2 != 0: fir += 1 if fir > sec: #or (sec - fir <= 1 and same % 2 != 0): print("First") elif sec > fir + 1: # or (sec - fir <= 1 and same % 2 == 0): print("Second") else: print("Draw") ```
instruction
0
95,596
19
191,192
Yes
output
1
95,596
19
191,193
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys import math n = int(input()) st1 = input() st2 = input() k = 0 res = 0 for i in range(2 * n): if(st1[i] == '1' and st2[i] == '1'): k += 1 elif(st1[i] == '1'): res -= 1 elif(st2[i] == '1'): res += 1 res1 = int(k / 2) + k % 2 res2 = k - res1 if(res < 0): b = math.fabs(res) res1 += int(b / 2) + res % 2 elif(res > 0): res += (k % 2) - 1 res2 += int(res / 2) + res % 2 if(res1 > res2): print("First") elif(res1 < res2): print("Second") else: print("Draw") ```
instruction
0
95,597
19
191,194
Yes
output
1
95,597
19
191,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` n = int(input()) s=input() t=input() s_1 = 0 t_1 = 0 for i in range(2*n): if s[i]=='1': s_1+=1 if t[i]=='1': t_1+=1 first = 0 second = 0 r = 0 for i in range(2*n): if s[i]=='1' and t[i]=='0': first+=1 elif s[i]=='0' and t[i]=='1': second+=1 elif s[i]=='1' and t[i]=='1': r+=1 if r%2==1: first+=1 if s_1>t_1: print('First') elif first==second or first==second-1: print('Draw') elif first>second: print('First') elif first < second: print('Second') ```
instruction
0
95,598
19
191,196
Yes
output
1
95,598
19
191,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys import math n = int(input()) st1 = input() st2 = input() k = 0 res = 0 for i in range(2 * n): if(st1[i] == '1' and st2[i] == '1'): k += 1 elif(st1[i] == '1'): res -= 1 elif(st2[i] == '1'): res += 1 res1 = int(k / 2) + k % 2 res2 = int(k / 2) if(res < 0): b = math.fabs(res) res1 += int(b / 2) + b % 2 elif(res > 0): res2 += int(res / 2) + res % 2 if(res1 > res2): print("First") elif(res1 < res2): print("Second") else: print("Draw") ```
instruction
0
95,599
19
191,198
No
output
1
95,599
19
191,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys import math n = int(input()) st1 = input() st2 = input() res1 = 0 res2 = 0 k = 0 for i in range(2 * n): if(st1[i] == '1' and st2[i] == '1'): k += 1 elif(st1[i] == '1'): res1 += 1 elif(st2[i] == '1'): res2 += 1 if(k % 2 != 0): res1 += 1 if(res1 > res2): print("First") elif(res1 < res2): print("Second") else: print("Draw") ```
instruction
0
95,600
19
191,200
No
output
1
95,600
19
191,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys import math n = int(input()) st1 = input() st2 = input() k = 0 res = 0 for i in range(2 * n): if(st1[i] == '1' and st2[i] == '1'): k += 1 elif(st1[i] == '1'): res -= 1 elif(st2[i] == '1'): res += 1 res1 = int(k / 2) + k % 2 res2 = int(k / 2) if(res < 0): b = math.fabs(res) res1 += int(b / 2) elif(res > 0): res2 += int(res / 2) if(res1 > res2): print("First") elif(res1 < res2): print("Second") else: print("Draw") ```
instruction
0
95,601
19
191,202
No
output
1
95,601
19
191,203
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·n binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·n, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as s = s1s2... s2n. Similarly, let's represent Andrey's word as t = t1t2... t2n. Then, if Yaroslav choose number k during his move, then he is going to write out character sk on the piece of paper. Similarly, if Andrey choose number r during his move, then he is going to write out character tr on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings s and t. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. Input The first line contains integer n (1 ≤ n ≤ 106). The second line contains string s — Yaroslav's word. The third line contains string t — Andrey's word. It is guaranteed that both words consist of 2·n characters "0" and "1". Output Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Examples Input 2 0111 0001 Output First Input 3 110110 001001 Output First Input 3 111000 000111 Output Draw Input 4 01010110 00101101 Output First Input 4 01100000 10010011 Output Second Submitted Solution: ``` import sys n = input() x = input() y = input() k = 0 s = 0 for i in range(len(list(x))): if x[i] == "1": k += 1 for i in range(len(list(y))): if y[i] == "1": s += 1 if int(x)>int(y) and s != k: print("First") if int(x)<int(y) and s != k: print("Second") if s == k: print("Draw") ```
instruction
0
95,602
19
191,204
No
output
1
95,602
19
191,205
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. George is a cat, so he loves playing very much. Vitaly put n cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the right with integers from 1 to n. Then the i-th card from the left contains number pi (1 ≤ pi ≤ n). Vitaly wants the row to have exactly k cards left. He also wants the i-th card from left to have number bi written on it. Vitaly gave a task to George, to get the required sequence of cards using the remove operation n - k times. In one remove operation George can choose w (1 ≤ w; w is not greater than the current number of cards in the row) contiguous cards (contiguous subsegment of cards). Let's denote the numbers written on these card as x1, x2, ..., xw (from the left to the right). After that, George can remove the card xi, such that xi ≤ xj for each j (1 ≤ j ≤ w). After the described operation George gets w pieces of sausage. George wondered: what maximum number of pieces of sausage will he get in total if he reaches his goal and acts optimally well? Help George, find an answer to his question! Input The first line contains integers n and k (1 ≤ k ≤ n ≤ 106) — the initial and the final number of cards. The second line contains n distinct space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the initial row of cards. The third line contains k space-separated integers b1, b2, ..., bk — the row of cards that you need to get. It is guaranteed that it's possible to obtain the given row by using the remove operation for n - k times. Output Print a single integer — the maximum number of pieces of sausage that George can get if he acts optimally well. Examples Input 3 2 2 1 3 1 3 Output 1 Input 10 5 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 Output 30 Submitted Solution: ``` __author__ = 'allen' n, k = (int(x) for x in (input().split(" "))) p = [int(x) for x in (input().split(" "))] b = [int(x) for x in (input().split(" "))] r = list(set(p)-set(b)) r.sort() r.append(-1) ps = [(i, p[i]) for i in range(len(p))] def second(inp): return inp[1] ps.sort(key=second) position = [-1, n] def bin_find(pos, i, j, k): m = i+(j-i)//2 if i > j: return i if pos[m] == k or i == j: return m elif k < pos[m]: return bin_find(pos, i, m-1, k) elif k > pos[m]: return bin_find(pos, m+1, j, k) def find_pie(pos, i): m = bin_find(pos, 0, len(pos)-1, i) if i > pos[m]: pos.insert(m+1, i) return pos[m+2]-pos[m]-1 else: pos.insert(m, i) return pos[m+1]-pos[m-1]-1 it_b = 0 s = 0 for it_p in range(n): if r[it_b] == ps[it_p][1]: it_b += 1 s += find_pie(position, ps[it_p][0]) else: find_pie(position, ps[it_p][0]) print(s) ```
instruction
0
95,636
19
191,272
No
output
1
95,636
19
191,273
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,722
19
191,444
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` m = 1000000007 input() n, d = 2, 1 for q in map(int, input().split()): d, n = q & d, pow(n, q, m) n = n * pow(2, m - 2, m) % m k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m print(str(k) + '/' + str(n)) ```
output
1
95,722
19
191,445
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,723
19
191,446
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` k = int(input()) MOD = 10 ** 9 + 7 antithree = pow(3, MOD - 2, MOD) antitwo = pow(2, MOD - 2, MOD) power = 1 parity = False for t in map(int, input().split()): power *= t power %= MOD - 1 if t % 2 == 0: parity = True q = pow(2, power, MOD) * antitwo q %= MOD if parity: p = (q + 1) * antithree p %= MOD else: p = (q - 1) * antithree p %= MOD print(p, q, sep = '/') ```
output
1
95,723
19
191,447
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,724
19
191,448
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` #!/usr/bin/python3 class Matrix: def __init__(self, n, m, arr=None): self.n = n self.m = m self.arr = [[0] * m for i in range(n)] if arr is not None: for i in range(n): for j in range(m): self.arr[i][j] = arr[i][j] def __mul__(self, other): assert self.m == other.n ans = Matrix(self.n, other.m) for i in range(self.n): for j in range(other.m): for k in range(self.m): ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7) return ans def __imul__(self, other): self = self * other return self def __pow__(self, n): if n == 0: ans = Matrix(self.n, self.n) for i in range(self.n): ans.arr[i][i] = 1 return ans elif n & 1 == 1: return self * (self ** (n - 1)) else: t = self ** (n >> 1) return t * t def __ipow__(self, n): self = self ** n return self def __eq__(self, other): if self.n != other.n or self.m != other.m: return False for i in range(self.n): for j in range(self.m): if self.arr[i][j] != other.arr[i][j]: return False return True def fpow(a, n): if n == 0: return 1 elif n & 1 == 1: return (a * fpow(a, n - 1)) % (10 ** 9 + 7) else: t = fpow(a, n >> 1) return (t * t) % (10 ** 9 + 7) transform = Matrix(2, 2, [[1, 1], [0, 4]]) mtx = transform k = int(input()) a = list(map(int, input().split())) """ f = False for j in a: if j % 2 == 0: f = True break if f: print(a) tp = 1 for j in a: if f and j % 2 == 0: j //= 2 f = False print(j) mtx **= j ans = Matrix(2, 1, [[0], [1]]) ans = mtx * ans print(ans.arr) print("%d/%d" % (ans.arr[0][0], ans.arr[1][0])) """ x = 1 for j in a: x = (x * j) % (10 ** 9 + 6) x = (x - 1) % (10 ** 9 + 6) if x % 2 == 0: ans = (transform ** (x // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % (ans.arr[0][0], fpow(2, x))) else: y = (x - 1) % (10 ** 9 + 6) ans = (transform ** (y // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), (ans.arr[1][0] * 2) % (10 ** 9 + 7))) ```
output
1
95,724
19
191,449
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,725
19
191,450
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` MOD = 10 ** 9 + 7 MOD1 = 2 * (10 ** 9 + 6) pow2 = [0] * 32 #pow2[i] = 2 ** (2 ** i) % MOD pow2[0] = 2 for i in range(1, 32): pow2[i] = (pow2[i - 1] ** 2) % MOD def exp2mod(exp): ans = 1 the_pow = 1 the_log = 0 while the_pow <= exp: if exp & the_pow == the_pow: ans = (ans * pow2[the_log]) % MOD the_pow *= 2 the_log += 1 return ans def main(): n = 1 k = int(input()) a = input().split() x = 0 y = 0 for i in range(k): n = (n * int(a[i])) % MOD1 x = exp2mod(n) if n % 2 == 0: x = (x + 2) % MOD else: x = (x - 2) % MOD if x % 2 == 0: x = x // 2 else: x = (x + MOD) // 2 if x % 3 == 0: x = x // 3 elif x % 3 == 1: x = (x + MOD) // 3 else: x = (x + 2 * MOD) // 3 y = exp2mod(n) if y % 2 == 0: y = y // 2 else: y = (y + MOD) // 2 print(str(x) + "/" + str(y)) main() ```
output
1
95,725
19
191,451
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,726
19
191,452
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` from functools import reduce mod = 1000000007 n = input() numbers = list(map(int,input().split())) flag = 1 if len(list(filter(lambda x: x%2 == 0,numbers))) else -1 b = reduce(lambda x,y:pow(x,y,mod),numbers,2) b = b*pow(2,mod-2,mod)%mod # b = 2^n-1 a = (b+flag)*pow(3,mod-2,mod)%mod #a = (2^n-1 -/+ 1) / 3 print("%d/%d"%(a,b)) ```
output
1
95,726
19
191,453
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,727
19
191,454
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` k = int(input()) MOD = 10 ** 9 + 7 antithree = pow(3, MOD - 2, MOD) antitwo = pow(2, MOD - 2, MOD) power = 1 parity = False for t in map(int, input().split()): power *= t power %= MOD - 1 if t % 2 == 0: parity = True q = pow(2, power, MOD) * antitwo q %= MOD if parity: p = (q + 1) * antithree p %= MOD else: p = (q - 1) * antithree p %= MOD print(p, q, sep = '/') # Made By Mostafa_Khaled ```
output
1
95,727
19
191,455
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,728
19
191,456
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` k = int(input()) n = list(map(int, input().split())) for i in range(k): n[i] = bin(n[i]) n[i] = n[i][2:] magic = 1000000007 def par(s): if s[-1] == '0': return True else: return False def mod_pow(x, s, p): ans = 1 for i in range(len(s)): if s[i] == '1': ans = (((ans * ans) % p) * x) % p else: ans = (ans * ans) % p return ans def div_in_field(a, b, p): b_op = pow(b, p - 2, p) return (b_op * a) % p denominator = 2 n_par = False for i in range(len(n)): denominator = mod_pow(denominator, n[i], magic) if par(n[i]): n_par = True denominator = div_in_field(denominator, 2, magic) numerator = 0 if n_par: numerator = div_in_field(1 + denominator, 3, magic) else: numerator = div_in_field(-1 + denominator, 3, magic) ans = str(numerator) + '/' + str(denominator) print(ans) ```
output
1
95,728
19
191,457
Provide tags and a correct Python 3 solution for this coding contest problem. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1
instruction
0
95,729
19
191,458
Tags: combinatorics, dp, implementation, math, matrices Correct Solution: ``` n = int(input()) ls = [int(x) for x in input().split(' ')] t = 1 mod = 1000000007 def qpow(n: int, m: int): m %= mod - 1 ans = 1 while m: if m & 1: ans = ans * n % mod n = n * n % mod m >>= 1 return ans k = 0 r=mod*2-2 for x in ls: t = t * x % (mod * 2 - 2) if x % 2 == 0: k = 1 t = (t - 1 + r) % r fz = (qpow(4, t >> 1) - 1) * qpow(3, mod - 2) % mod if k == 1: fz = (fz * 2 + 1) % mod fm = qpow(2, t) print('{}/{}'.format(fz, fm)) ```
output
1
95,729
19
191,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` from functools import reduce MOD = 10 ** 9 + 7 n, a = int(input()), map(int, input().split()) n = reduce(lambda x,y:(x*y)%(MOD-1), a, 1) # 333333336 * 3 = 1 # 500000004 * 2 = 1 k = n % 2 q = (pow(2, n, MOD) * 500000004) % MOD if k == 0: p = ((q + 1) * 333333336) % MOD else: p = ((q - 1) * 333333336) % MOD print("%d/%d" % (p, q)) ```
instruction
0
95,730
19
191,460
Yes
output
1
95,730
19
191,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` class Matrix: def __init__(self, n, m, arr=None): self.n = n self.m = m self.arr = [[0] * m for i in range(n)] if arr is not None: for i in range(n): for j in range(m): self.arr[i][j] = arr[i][j] def __mul__(self, other): assert self.m == other.n ans = Matrix(self.n, other.m) for i in range(self.n): for j in range(other.m): for k in range(self.m): ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7) return ans def __imul__(self, other): self = self * other return self def __pow__(self, n): if n == 0: ans = Matrix(self.n, self.n) for i in range(self.n): ans.arr[i][i] = 1 return ans elif n & 1 == 1: return self * (self ** (n - 1)) else: t = self ** (n >> 1) return t * t def __ipow__(self, n): self = self ** n return self def __eq__(self, other): if self.n != other.n or self.m != other.m: return False for i in range(self.n): for j in range(self.m): if self.arr[i][j] != other.arr[i][j]: return False return True def fpow(a, n): if n == 0: return 1 elif n & 1 == 1: return (a * fpow(a, n - 1)) % (10 ** 9 + 7) else: t = fpow(a, n >> 1) return (t * t) % (10 ** 9 + 7) transform = Matrix(2, 2, [[1, 1], [0, 4]]) mtx = transform k = int(input()) a = list(map(int, input().split())) x = 1 for j in a: x = (x * j) % (10 ** 9 + 6) x = (x - 1) % (10 ** 9 + 6) if x % 2 == 0: ans = (transform ** (x // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % (ans.arr[0][0], fpow(2, x))) else: y = (x - 1) % (10 ** 9 + 6) ans = (transform ** (y // 2)) * Matrix(2, 1, [[0], [1]]) print("%d/%d" % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), (ans.arr[1][0] * 2) % (10 ** 9 + 7))) ```
instruction
0
95,731
19
191,462
Yes
output
1
95,731
19
191,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq,bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict threading.stack_size(10**8) mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase sys.setrecursionlimit(300000) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default=2**51, func=lambda a, b: a & b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ def multiply(a, b): mul = [[0 for x in range(2)]for y in range(2)] for i in range(2): for j in range(2): mul[i][j] = 0 for k in range(2): mul[i][j] += a[i][k] * b[k][j] mul[i][j]%=mod for i in range(2): for j in range(2): a[i][j] = mul[i][j] # Updating our matrix return a def power(M,n): if n==0: res=[[0 for i in range(2)]for j in range(2)] res[0][0]=1 res[1][1]=1 return res if n==1: return M else: res=[[1,0],[0,1]] if n%2==1: res=multiply(res,M) re=power(M,n//2) re=multiply(re,re) re=multiply(re,res) return re n=int(input()) l=list(map(int,input().split())) req=1 for i in l: req*=i req%=mod-1 if req==0: req=mod-1 if req==1: print("0/1") sys.exit(0) M=[[0 for i in range(2)]for j in range(2)] M[0][0]=1 M[0][1]=2 M[1][0]=1 M[1][1]=0 M=power(M,req-2) num=M[0][0]%mod de=pow(2,req-1,mod) print(str(num)+"/"+str(de)) ```
instruction
0
95,732
19
191,464
Yes
output
1
95,732
19
191,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` mod = int(1e9+7) k = int(input()) top = 1 yoink = 1 a = list(map(int, input().split())) for thing in a: top *= thing yoink *= thing yoink %= 2 top %= (mod-1) def extended_gcd(aa, bb): lastremainder, remainder = abs(aa), abs(bb) x, lastx, y, lasty = 0, 1, 1, 0 while remainder: lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder) x, lastx = lastx - quotient*x, x y, lasty = lasty - quotient*y, y return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1) def modinv(a, m): g, x, y = extended_gcd(a, m) if g != 1: raise ValueError return x % m if top == 0: bot = modinv(2, mod) else: bot = pow(2, top-1, mod) #print(bot) # odd case if yoink % 2 == 0: blah = modinv(3, mod) blah *= (bot+1) blah %= mod print(str(blah) + '/' + str(bot)) else: blah = modinv(3, mod) blah *= (bot+2) blah %= mod print(str(blah-1) + '/' + str(bot)) ```
instruction
0
95,733
19
191,466
Yes
output
1
95,733
19
191,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` mod = 1000000007 def binpow(a, k): res = 1 while k > 0: if k % 2 == 1: res = (res * a) % mod a = (a * a) % mod; k //= 2 return res def binmatpow(a, k): res = [[1, 0], [0, 1]] while k > 0: if k % 2 == 1: res = matmul(res, a) a = matmul(a, a) k //= 2 return res def matmul(a, b): c = [[0 for x in range(2)] for y in range(2)] c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0] % mod c[1][0] = (a[1][0] * b[0][0]% mod + a[1][1] * b[1][0] % mod) % mod c[0][1] = (a[0][0] * b[0][1]% mod + a[0][1] * b[1][1]% mod) % mod c[1][1] = (a[1][0] * b[0][1]%mod + a[1][1] * b[1][1] % mod) % mod return c def main(): rmat = [[1, 0],[0, 0]] test = [[0, 2],[1, 1]] n = int(input()) a = list(map(int, input().split())) t = [[0, 2],[1, 1]] md = 1; for i in range(n): t = binmatpow(t, a[i]) md *= a[i] md %= (mod - 1) p = matmul(rmat, t)[0][0] * binpow(2, mod - 2) % mod q = binpow(2, (md + mod - 2) % mod) print("{0}/{1}".format(p, q)) main() ```
instruction
0
95,734
19
191,468
No
output
1
95,734
19
191,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` mod = 1000000007 def binpow(a, k): if k == 0: return 1 elif k % 2 == 0: t = binpow(a, k // 2) return t * t % mod else: t = binpow(a, k - 1) return t * a % mod def binmatpow(a, k): if k == 0: return [[1, 0],[0, 1]] elif k % 2 == 0: t = binmatpow(a, k // 2) return matmul(t, t) else: t = binmatpow(a, k - 1) return matmul(t, a) def matmul(a, b): c = [[0 for x in range(2)] for y in range(2)] c[0][0] = (a[0][0] * b[0][0] + a[0][1] * b[1][0]) % mod c[1][0] = (a[1][0] * b[0][0] + a[1][1] * b[1][0]) % mod c[0][1] = (a[0][0] * b[0][1] + a[0][1] * b[1][1]) % mod c[1][1] = (a[1][0] * b[0][1] + a[1][1] * b[1][1]) % mod return c def main(): test = [[0, 2],[1, 1]] rmat = [[1, 0],[0, 0]] n = int(input()) a = list(map(int, input().split())) t = test.copy() md = 1; for i in range(n): t = binmatpow(t, a[i]) print(a[i]) print(t) md *= a[i] md %= (mod - 1) p = (matmul(rmat, t)[0][0] * binpow(2, mod - 2)) % mod q = (binpow(2, md) * binpow(2, mod - 2)) % mod print("{0}/{1}".format(p, q)) main() ```
instruction
0
95,735
19
191,470
No
output
1
95,735
19
191,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` mod = 1000000007 def binpow(a, k): res = 1 while k > 0: if k % 2 == 1: res *= a a = (a * a) % mod; k //= 2 return res; def binmatpow(a, k): res = [[1, 0], [0, 1]] while k > 0: if k % 2 == 1: res = matmul(res, a) a = matmul(a, a) k //= 2 return res def matmul(a, b): c = [[0 for x in range(2)] for y in range(2)] c[0][0] = (a[0][0] * b[0][0] + a[0][1] * b[1][0]) % mod c[1][0] = (a[1][0] * b[0][0] + a[1][1] * b[1][0]) % mod c[0][1] = (a[0][0] * b[0][1] + a[0][1] * b[1][1]) % mod c[1][1] = (a[1][0] * b[0][1] + a[1][1] * b[1][1]) % mod return c def main(): rmat = [[1, 0],[0, 0]] test = [[0, 2],[1, 1]] n = int(input()) a = list(map(int, input().split())) t = [[1, 0],[0, 0]] md = 1; for i in range(n): t = binmatpow(t, a[i]) md *= a[i] md %= (mod - 1) p = (matmul(rmat, t)[0][0] * binpow(2, mod - 2)) % mod q = (binpow(2, md) * binpow(2, mod - 2)) % mod print("{0}/{1}".format(p, q)) main() ```
instruction
0
95,736
19
191,472
No
output
1
95,736
19
191,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. <image> Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that <image> in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7. Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7. Input The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you. The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array. Output In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7. Examples Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 Submitted Solution: ``` k=int(input()) x=input().split(' ') sum=0 for i in x: sum = sum + int(i) if sum % 2 == 1: print("0/1") else : sum/=2 sum = 2**sum sum = sum % 1000000007 print("1/",end="") print(int(sum)) ```
instruction
0
95,737
19
191,474
No
output
1
95,737
19
191,475
Provide a correct Python 3 solution for this coding contest problem. Problem There are coins with front and back sides and dice with rolls from $ 1 $ to $ N $. Gacho decided to play the following games using these. The game starts with a score of $ 0 $ and proceeds as follows. 1. Roll the dice $ 1 $ and add the number of rolls to the score. 2. If the current score is $ K $ or more, the game is cleared and the game ends. 3. If the current score is less than $ K $, toss a coin and return to 1. if the front appears, and if the back appears, the game is over and the game ends. When a coin is thrown, it has a probability of $ A \% $ and a probability of $ (100-A) \% $. Also, when the dice are rolled, each eye appears with equal probability. At this time, find the probability that Gacho can clear the game in one game. When the probability to be calculated is expressed as $ \ frac {P} {Q} $ using relatively prime integers $ P and Q $, it becomes $ R \ times Q \ equiv P \ bmod 998244353 $ $ 0 $ or more and $ 998244352 $ or less. Output the integer $ R $ of. Under the constraints of this problem, such $ R $ always exists uniquely. Constraints The input satisfies the following conditions. * $ 1 \ leq N \ leq 10 ^ 5 $ * $ 1 \ leq K \ leq 10 ^ 5 $ * $ 1 \ leq A \ leq 99 $ * All inputs are integers Input The input is given in the following format. $ N $ $ K $ $ A $ $ N, K, A $ are given on one line separated by blanks. Output When the probability of clearing the game is expressed as $ \ frac {P} {Q} $ using relatively prime integers $ P and Q $, it becomes $ R \ times Q \ equiv P \ bmod 998244353 $. Output an integer $ R $ that is greater than or equal to $ 0 $ and less than or equal to $ 998244352 $. Examples Input 1 1 50 Output 1 Input 2 2 10 Output 648858830 Input 6 10 99 Output 650893870
instruction
0
96,059
19
192,118
"Correct Solution: ``` N, K, A = map(int, input().split()) dp = [0] * (K+1) + [1] * N # 残りが i 点のときの勝率 dp[0] = 1 c = 1 mod = 998244353 p_coin = A * pow(100, mod-2, mod) % mod p_dice = pow(N, mod-2, mod) for i in range(1, K+1): dp[i] = c * p_coin % mod c += (dp[i] - dp[i-N]) * p_dice % mod print(dp[K] * pow(p_coin, mod-2, mod) % mod) ```
output
1
96,059
19
192,119
Provide a correct Python 3 solution for this coding contest problem. Problem There are coins with front and back sides and dice with rolls from $ 1 $ to $ N $. Gacho decided to play the following games using these. The game starts with a score of $ 0 $ and proceeds as follows. 1. Roll the dice $ 1 $ and add the number of rolls to the score. 2. If the current score is $ K $ or more, the game is cleared and the game ends. 3. If the current score is less than $ K $, toss a coin and return to 1. if the front appears, and if the back appears, the game is over and the game ends. When a coin is thrown, it has a probability of $ A \% $ and a probability of $ (100-A) \% $. Also, when the dice are rolled, each eye appears with equal probability. At this time, find the probability that Gacho can clear the game in one game. When the probability to be calculated is expressed as $ \ frac {P} {Q} $ using relatively prime integers $ P and Q $, it becomes $ R \ times Q \ equiv P \ bmod 998244353 $ $ 0 $ or more and $ 998244352 $ or less. Output the integer $ R $ of. Under the constraints of this problem, such $ R $ always exists uniquely. Constraints The input satisfies the following conditions. * $ 1 \ leq N \ leq 10 ^ 5 $ * $ 1 \ leq K \ leq 10 ^ 5 $ * $ 1 \ leq A \ leq 99 $ * All inputs are integers Input The input is given in the following format. $ N $ $ K $ $ A $ $ N, K, A $ are given on one line separated by blanks. Output When the probability of clearing the game is expressed as $ \ frac {P} {Q} $ using relatively prime integers $ P and Q $, it becomes $ R \ times Q \ equiv P \ bmod 998244353 $. Output an integer $ R $ that is greater than or equal to $ 0 $ and less than or equal to $ 998244352 $. Examples Input 1 1 50 Output 1 Input 2 2 10 Output 648858830 Input 6 10 99 Output 650893870
instruction
0
96,060
19
192,120
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 998244353 def solve(): n,k,a = LI() lst = [0]*(k+1) lst[-2] = 1 A = a*pow(100*n,mod-2,mod) inv = pow(n,mod-2,mod) for i in range(k-1)[::-1]: if k > i + n: lst[i] = A*(lst[i+1] - lst[i+n+1]) + lst[i+1] lst[i] %= mod else: lst[i] = A*(lst[i+1] - lst[k]) + (n-(k-i)+1)*inv + lst[i+1] lst[i] %= mod print((lst[0] - lst[1])%mod) return if __name__ == "__main__": solve() ```
output
1
96,060
19
192,121
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,481
19
192,962
"Correct Solution: ``` n = input() falling_dir = input() n = int(n, 10) f = 0 start_pos = 0 fall_dir = "." i = 0 for dir in falling_dir: if dir == "R": fall_dir = dir start_pos = i elif dir == "L": k = i - start_pos if fall_dir == ".": f += k+1 else: if k%2 == 0: f += k else: f += k+1 fall_dir = "." i += 1 # print("i = ", i-1, " f = ", f) if fall_dir == "R": k = n - start_pos f += k print(n-f) ```
output
1
96,481
19
192,963
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,482
19
192,964
"Correct Solution: ``` n=int(input()) x=input() i=0 c=0 while i<n: if x[i]=="L" or x[i]=="R": if x[i]=="R": c+=i break i+=1 if i==n: for i in range(n): if x[i]=="R": break print(i+1) else: j=i+1 while j<n: if x[j]==".": j+=1 elif x[i]==".": i+=1 continue elif x[i]=="R" and x[j]=="L": if (j-i-1)%2==1: c+=1 i=j j+=1 elif x[i]=="L" and x[j]=="R": c+=j-i-1 i=j j+=1 if x[i]=="L" and x[-1]==".": c+=j-i-1 print(c) ```
output
1
96,482
19
192,965
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,483
19
192,966
"Correct Solution: ``` n = int(input()) s = input().split('L') ans = 0 if 'R' not in s[0]: if len(s) != 1: s = s[1:] if 'R' in s[-1]: s[-1] = s[-1][:s[-1].index('R')] for sub in s: if 'R' not in sub: ans += len(sub) else: idx = sub.index('R') ans += idx ans += (len(sub) - idx - 1) % 2 print(ans) ```
output
1
96,483
19
192,967
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,484
19
192,968
"Correct Solution: ``` n = int(input()) string = input() result = 0 if set(string) == {'.', }: print(n) else: i = 0 met_1 = False met_2 = False start = 0 end = n-1 on = True while i < n and not (met_1 and met_2): # print("came in while") # print(f"string[i] = {string[i]}") # print(f"the result was {result}") if string[i] != '.' and not met_1: if string[i] == 'R': result += i start = i met_1 = True if string[n-1-i] != '.' and not met_2: if string[n-1-i] == 'L': result += i end = n - i - 1 met_2 = True # print(f"the result changed to {result}") i += 1 if len(set(string)) == 2: print(result) else: # print("The control came in the else.") # print(f"start = {start} end = {end} result = {result}") prev = start i = start +1 while start < i <= end: # print(f"prev = {prev} i = {i} string[i] = {string[i]}") if string[prev] == "R" and string[i] == "L": if (i - prev -1)%2 == 1: result += 1 prev = i elif string[prev] == "L" and string[i] == "R": result += i - prev -1 prev = i # print(f"the result changed to {result}") i += 1 print(result) ```
output
1
96,484
19
192,969
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,485
19
192,970
"Correct Solution: ``` N = int(input()) S = input() A = [1 for i in range(N)] mode = -1 ans = 0 for i in range(N): c = S[i] if(c=="L"): if(mode==-1): for k in range(i+1): A[k]=0 else: if(i-mode+1)%2==1: ans+=1 for k in range(mode,i+1): A[k]=0 mode = -1 elif(c=="R"): mode = i if(mode!=-1): for k in range(mode,N): A[k]=0 for i in range(N): ans+=A[i] print(ans) ```
output
1
96,485
19
192,971
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,486
19
192,972
"Correct Solution: ``` import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline n = int(input()) s = input().strip() st = [] up = n for i in range(n): if s[i] == "L": if not st: up -= (i+1) else: length = i - st.pop() + 1 length -= length%2 up -= length elif s[i] == "R": st.append(i) if st: up -= (n - st.pop()) print(up) ```
output
1
96,486
19
192,973
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,487
19
192,974
"Correct Solution: ``` n = int(input()) s = input() s = list(s) v = 0 while(True): lExits = False rExits = False if ('L' in s): l = s.index('L') lExits = True if ('R' in s): r = s.index('R') rExits = True if (lExits == False and rExits == False): break if (lExits == True and rExits == False): for i in range(l+1): s[i] = 'F' break if (lExits == False and rExits == True): for i in range(r,n): s[i] = 'F' break if (lExits == True and rExits == True): if (l < r): for i in range(l+1): s[i] = 'F' else: for i in range(r,l+1): s[i] = 'F' if ((l - r) % 2 == 0): s[r] = '.' c = 0 for i in s: if (i == '.'): c += 1 print(c) ```
output
1
96,487
19
192,975
Provide a correct Python 3 solution for this coding contest problem. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction.
instruction
0
96,488
19
192,976
"Correct Solution: ``` n = int(input()) st = list(input()) ans = 0 i = 0 while st and i < len(st): if st[i] == 'L': n -= i + 1 st = st[i + 1:] i = -1 elif st[i] == 'R': n -= 1 j = i + 1 while j < len(st): if st[j] == 'L': n -= j - i if (j - i) % 2 == 0: n += 1 st = st[j + 1:] i = -1 break if st[j] == 'R': n -= j - i - 1 st = st[j:] i = -1 break j += 1 else: n -= j - i - 1 i += 1 print(n) ```
output
1
96,488
19
192,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` class Stack(): def __init__(self): self.stack = [] self.len = 0 def top(self): assert not self.empty() return self.stack[self.len - 1] def pop(self): assert not self.empty() self.len -= 1 return self.stack.pop() def push(self, x): self.len += 1 self.stack.append(x) def empty(self): return self.len == 0 def calc(n, pos): st = Stack() last_pos = -1 ans = 0 for i in range(n): if pos[i] == "R": if st.empty(): ans += i - last_pos - 1 st.push(i) elif pos[i] == "L": if st.empty(): last_pos = i else: left_R = st.pop(); ans += (i - left_R + 1) % 2 last_pos = i if st.empty(): ans += n - last_pos - 1 return ans n=int(input()) pos=str(input()) print(calc(n, pos)) ```
instruction
0
96,489
19
192,978
Yes
output
1
96,489
19
192,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` n = int(input()) s = input() c = n k = 0 l, r = 0, 0 for i in range(n): if s[i] == '.': continue if s[i] == 'L': k -= 1 l = i else: k += 1 r = i if k < 0: c -= i + 1 k = 0 elif k == 0: c -= (l - r + 1) - (l - r + 1) % 2 if k > 0: c -= n - r print(c) ```
instruction
0
96,490
19
192,980
Yes
output
1
96,490
19
192,981
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` n = int(input()) s = input() t, res, prev = 0, 0, -1 for i in range(n): if s[i] == 'R': res += i - prev - 1 prev = i t = 1 if s[i] == 'L': if (prev != -1): res += (i - prev - 1) % 2 prev = i t = 0 if t == 0: res += n - prev - 1 print(res) ```
instruction
0
96,491
19
192,982
Yes
output
1
96,491
19
192,983
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` import sys,math,heapq from collections import defaultdict,Counter def li(): return list(map(int,sys.stdin.readline().split())) def ls(): return list(map(int,list(input()))) def la(): return list(input()) def ii(): return int(input()) n= ii() a = la() ans = 0 s = [] count = 0 for i in range(n): # print(count , i,s,ans) if a[i] == ".": count += 1 elif a[i] == "L": if s and s[-1] == "R": ans += count%2 s = [] count = 0 elif a[i] == "R": s.append("R") ans += count count = 0 # print(count) if not s: ans += count print(ans) ```
instruction
0
96,492
19
192,984
Yes
output
1
96,492
19
192,985
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` n = int(input()) s = input() falls = [0] * n i = 0 ans = n while i < len(s) and s[i] == '.': i += 1 if i == len(s): print(n) else: rr = s.rfind('R') rl = s.rfind('L') ll = s.find('L') lr = s.find('R') if (rr != -1) and (rl != -1) and (rr > rl): ans -= (n - rr) if (ll != -1) and (lr != -1) and (ll < lr): ans -= (ll + 1) #print(ans) if (ll != -1) and (lr == -1): print(rl + 1) elif (ll == -1) and (lr != -1): print(lr) else: s = s[lr:rl + 1] ll = s.find('L') lr = s.find('R') #print(s, lr, ll, ans) while (ll != -1) and (lr != -1): ans -= (ll - lr) if (lr - ll) % 2 != 0: ans -= 1 s = s[ll + 1:] ll = s.find('L') lr = s.find('R') #print(s, ll, lr, ans) print(ans) ```
instruction
0
96,493
19
192,986
No
output
1
96,493
19
192,987
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` n=int(input()) l=input() s=[] t=[] checkvalue=0 sum=0 for i in range(len(l)): if l[i]=="L": s.append(0) elif l[i]=="R": s.append(1) if s==[]: sum=n else: if s[0] == 1: checkvalue = 1 for i in range(len(l)): if l[i] == "L" or l[i] == "R": t.append(i) if len(t)==1: if checkvalue==0: sum= n - 1 - t[0] else: sum=t[0] else: for i in range(len(t) - 1): if checkvalue == 0: if i % 2 == 0: sum += t[i + 1] - t[i] - 1 else: sum += (t[i + 1] - t[i]) % 2 else: if i % 2 == 1: sum += t[i + 1] - t[i] - 1 else: sum += (t[i + 1] - t[i]) % 2 if s[len(t) - 1] == 0: sum += n - 1 - t[-1] print(sum) ```
instruction
0
96,494
19
192,988
No
output
1
96,494
19
192,989
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` # -*- coding: utf-8 -*- n = int(input()) s = list(input()) count = 0 l, r = -1, 0 while True: if l == -1: if 'R' in s: r = s.index('R') if 'L' in s[:r]: l = s.index('L') count += r - l - 1 else: count += r - 1 l = r elif 'L' in s: count = n - s.index('L') - 1 break else: count = n break else: if s[l] == 'R': if 'L' in s[l:]: r += s[l:].index('L') if (r - l - 1) & 1: count += 1 l = r else: break else: if 'R' in s[l:]: r += s[l:].index('R') count += r - l - 1 l = r else: count += n - l -1 break print(count) ```
instruction
0
96,495
19
192,990
No
output
1
96,495
19
192,991
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show". Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction. After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process. <image> Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process! Input The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to * "L", if the i-th domino has been pushed to the left; * "R", if the i-th domino has been pushed to the right; * ".", if the i-th domino has not been pushed. It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L". Output Output a single integer, the number of the dominoes that remain vertical at the end of the process. Examples Input 14 .L.R...LR..L.. Output 4 Input 5 R.... Output 0 Input 1 . Output 1 Note The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange. In the second example case, all pieces fall down since the first piece topples all the other pieces. In the last example case, a single piece has not been pushed in either direction. Submitted Solution: ``` import sys index = 0; for line in sys.stdin: total = 0; start = False; rtrig = False; rcount = 0; if(index == 0): index += 1; continue; for i in range(len(line)): if(not start): if(line[i] == 'L'): total += i + 1; start = True; if(line[i] == 'R'): start = True; elif(line[i] == "R"): rcount = i; elif(line[i] == "L"): total += int((int((i - rcount + 1) / 2)) * 2); sys.stdout.write(str(len(line) - total)); ```
instruction
0
96,496
19
192,992
No
output
1
96,496
19
192,993
Provide tags and a correct Python 3 solution for this coding contest problem. After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all. Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner. Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one. More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots). Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string. Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each xi query must be answered: is there a bullet in the positions xi? Input The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Output For each query print "." if the slot should be empty and "X" if the slot should be charged. Examples Input 3 1 3 1 2 3 Output ..X Input 6 3 6 1 2 3 4 5 6 Output .X.X.X Input 5 2 5 1 2 3 4 5 Output ...XX Note The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.
instruction
0
96,969
19
193,938
Tags: constructive algorithms, greedy Correct Solution: ``` n, k, p = map(int, input().split()) for i in range(p): pos = int(input()) if n % 2: if pos == n: print('X' if k > 0 else '.', end='') else: if k * 2 > n + 1: print('X' if (pos & 1) == 0 or (n - pos) // 2 \ + n // 2 + 1<= k else '.', end='') else: print('X' if (pos & 1) == 0 and \ (n + 1 - pos) // 2 < k else '.', end='') else: if k * 2 > n: print('X' if (pos & 1) == 0 or (n - pos + 1) // 2 + \ n // 2 <= k else '.', end='') else: print('X' if (pos & 1) == 0 and (n - pos + 2) // 2 <= k \ else '.', end='') ```
output
1
96,969
19
193,939
Provide tags and a correct Python 3 solution for this coding contest problem. After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all. Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner. Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one. More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots). Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string. Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each xi query must be answered: is there a bullet in the positions xi? Input The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Output For each query print "." if the slot should be empty and "X" if the slot should be charged. Examples Input 3 1 3 1 2 3 Output ..X Input 6 3 6 1 2 3 4 5 6 Output .X.X.X Input 5 2 5 1 2 3 4 5 Output ...XX Note The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.
instruction
0
96,970
19
193,940
Tags: constructive algorithms, greedy Correct Solution: ``` n, k, p = map(int, input().split()) for i in range(p): pos = int(input()) if n % 2: if pos == n: print('X' if k > 0 else '.', end='') else: if k * 2 > n + 1: print('X' if (pos & 1) == 0 or (n - pos) // 2 \ + n // 2 + 1<= k else '.', end='') else: print('X' if (pos & 1) == 0 and \ (n + 1 - pos) // 2 < k else '.', end='') else: if k * 2 > n: print('X' if (pos & 1) == 0 or (n - pos + 1) // 2 + \ n // 2 <= k else '.', end='') else: print('X' if (pos & 1) == 0 and (n - pos + 2) // 2 <= k \ else '.', end='') # Made By Mostafa_Khaled ```
output
1
96,970
19
193,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all. Sasha selects any k out of n slots he wishes and puts bullets there. Roma spins the cylinder so that every of n possible cylinder's shifts is equiprobable. Then the game starts, the players take turns, Sasha starts: he puts the gun to his head and shoots. If there was no bullet in front of the trigger, the cylinder shifts by one position and the weapon is given to Roma for make the same move. The game continues until someone is shot, the survivor is the winner. Sasha does not want to lose, so he must choose slots for bullets in such a way as to minimize the probability of its own loss. Of all the possible variant he wants to select the lexicographically minimal one, where an empty slot is lexicographically less than a charged one. More formally, the cylinder of n bullet slots able to contain k bullets can be represented as a string of n characters. Exactly k of them are "X" (charged slots) and the others are "." (uncharged slots). Let us describe the process of a shot. Suppose that the trigger is in front of the first character of the string (the first slot). If a shot doesn't kill anyone and the cylinder shifts, then the string shifts left. So the first character becomes the last one, the second character becomes the first one, and so on. But the trigger doesn't move. It will be in front of the first character of the resulting string. Among all the strings that give the minimal probability of loss, Sasha choose the lexicographically minimal one. According to this very string, he charges the gun. You have to help Sasha to charge the gun. For that, each xi query must be answered: is there a bullet in the positions xi? Input The first line contains three integers n, k and p (1 ≤ n ≤ 1018, 0 ≤ k ≤ n, 1 ≤ p ≤ 1000) — the number of slots in the cylinder, the number of bullets and the number of queries. Then follow p lines; they are the queries. Each line contains one integer xi (1 ≤ xi ≤ n) the number of slot to describe. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Output For each query print "." if the slot should be empty and "X" if the slot should be charged. Examples Input 3 1 3 1 2 3 Output ..X Input 6 3 6 1 2 3 4 5 6 Output .X.X.X Input 5 2 5 1 2 3 4 5 Output ...XX Note The lexicographical comparison of is performed by the < operator in modern programming languages. The a string is lexicographically less that the b string, if there exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Submitted Solution: ``` n, k, p = map(int, input().split()) for i in range(p): pos = int(input()) if n % 2: print('.' if n - pos >= k else 'X', end='') else: if k * 2 > n: print('X' if (pos & 1) == 0 or (n - pos + 1) // 2 + \ n // 2 <= k else '.', end='') else: print('X' if (pos & 1) == 0 and (n - pos + 2) // 2 <= k \ else '.', end='') ```
instruction
0
96,971
19
193,942
No
output
1
96,971
19
193,943
Provide tags and a correct Python 3 solution for this coding contest problem. Vova is playing a computer game. There are in total n turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is k. During each turn Vova can choose what to do: * If the current charge of his laptop battery is strictly greater than a, Vova can just play, and then the charge of his laptop battery will decrease by a; * if the current charge of his laptop battery is strictly greater than b (b<a), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by b; * if the current charge of his laptop battery is less than or equal to a and b at the same time then Vova cannot do anything and loses the game. Regardless of Vova's turns the charge of the laptop battery is always decreases. Vova wants to complete the game (Vova can complete the game if after each of n turns the charge of the laptop battery is strictly greater than 0). Vova has to play exactly n turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all. Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game. You have to answer q independent queries. Input The first line of the input contains one integer q (1 ≤ q ≤ 10^5) — the number of queries. Each query is presented by a single line. The only line of the query contains four integers k, n, a and b (1 ≤ k, n ≤ 10^9, 1 ≤ b < a ≤ 10^9) — the initial charge of Vova's laptop battery, the number of turns in the game and values a and b, correspondingly. Output For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise. Example Input 6 15 5 3 2 15 5 4 3 15 5 2 1 15 5 5 1 16 7 5 2 20 5 7 3 Output 4 -1 5 2 0 1 Note In the first example query Vova can just play 4 turns and spend 12 units of charge and then one turn play and charge and spend 2 more units. So the remaining charge of the battery will be 1. In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be 0 after the last turn.
instruction
0
97,020
19
194,040
Tags: binary search, math Correct Solution: ``` for n in range(int(input())): lvl,tot,a,b=map(int,input().split()) if tot*b>=lvl: print(-1) continue hi=tot lo=0 res=0 while hi>=lo: justpl=(hi+lo)//2 u=justpl*a+(tot-justpl)*b if justpl*a+(tot-justpl)*b<lvl: lo=justpl+1 res=justpl else: hi=justpl-1 print(res) ```
output
1
97,020
19
194,041