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. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses.
instruction
0
91,896
19
183,792
Tags: dfs and similar, dp, games Correct Solution: ``` def win(s, e): if e % 2: return s % 2 ^ 1 if s > e // 2: return s % 2 if s > e // 4: return 1 return win(s, e // 4) def lose(s, e): if s > e // 2: return 1 return win(s, e // 2) def game(n): res = [0, 1] for i in range(n): s, e = map(int, input().split()) res[0], res[1] = res[win(s, e)], res[lose(s, e)] return res n = int(input()) print(*game(n)) ```
output
1
91,896
19
183,793
Provide tags and a correct Python 3 solution for this coding contest problem. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses.
instruction
0
91,897
19
183,794
Tags: dfs and similar, dp, games Correct Solution: ``` import sys inpy = [int(x) for x in sys.stdin.read().split()] def win(s, e) : if e == s : return False if e == s+1 : return True if e % 2 == 1 : if s % 2 == 1 : return False return True q = e//4 if s <= q : return win(s, q) q = e//2 if(s > q) : return (e-s) % 2 == 1 return True def lose(s, e) : q = e//2 if(s > q) : return True else : return win(s, q) t = inpy[0] start = (True, False) inpo = 1 v = (True, True) for tc in range(t): if(inpo+1 >= len(inpy)) : print('wtf') s, e = inpy[inpo], inpy[inpo+1] inpo = inpo+2 v = ((win(s, e), lose(s, e))) if start[0] and start[1] : break if (not start[0]) and (not start[1]) : break if start[1] : v = (not v[0], not v[1]) start = (v[1], v[0]) if((start[0] != True and start[0] != False) or (start[1] != True and start[1] != False)) : print('wtf') sw = 2 if start[1] : sw = sw-1 print(1, end = ' ') else : sw = sw-1 print(0, end = ' ') if start[0] : print(1) sw = sw-1 else : print(0) sw = sw-1 if sw : print(wtf) ```
output
1
91,897
19
183,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses. Submitted Solution: ``` def win(s, e): if e % 2: return s % 2 ^ 1 if s > e // 2: return s % 2 if s > e // 4: return 1 return win(s, e // 4) def lose(s, e): if s > e // 2: return 1 return win(s, e // 2) def game(n): res = [0, 1] for i in range(n): s, e = map(int, input().split()) res[0], res[1] = res[win(s, e)], res[lose(s, e)] print(*res) return res n = int(input()) print(*game(n)) ```
instruction
0
91,898
19
183,796
No
output
1
91,898
19
183,797
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses. Submitted Solution: ``` def f(s,e): if e%2: return s%2==1 elif s*2>e: return s%2==0 else: return g(s,e//2) def g(s,e): if 2*s>e: return True else: return f(s,e//2) a=[tuple(map(int,input().split())) for i in range(int(input()))] b=1 for i in a: b=(b&g(*i))|(b^(f(*i)<<1)) if b==0: print('0 0') exit(0) elif b==3: print('1 1') exit(0) if b==2: print('1 0') else: print('0 1') ```
instruction
0
91,899
19
183,798
No
output
1
91,899
19
183,799
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses. Submitted Solution: ``` t = int(input()) A = [] B = [] for i in range(0, t): s, e= input().split(" ") s, e = int(s), int(e) B.append([s, e]) if s == e: A.append(2) else: if s + 1 > e and 2 * s > e: A.append(1) elif s + 1 <= e and 2 * s > e: A.append(1) elif s + 1 > e and 2 * s <= e: A.append(1) else: A.append(0) if t == 2 and B == [[1, 2], [2, 8]]: print(1, 0) else: if A[len(A)-1] == 0: x = 1 y = 0 prev0 = 1 prev1 = 0 elif A[len(A)-1] == 1: x = 1 y = 1 prev0 = 1 prev1 = 1 else: x = 0 y = 1 prev0 = 0 prev1 = 1 for i in range(len(A)-2, -1, -1): if A[i] == 0: x = 1 - prev0 y = 1 - prev1 prev0 = 1 - prev0 elif A[i] == 1: prev0 = 1 prev1 = 1 x = 1 print(x, y) ```
instruction
0
91,900
19
183,800
No
output
1
91,900
19
183,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"... The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 β‹… a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round. Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round. The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game. Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not. Input The first line contains the integer t (1 ≀ t ≀ 10^5) β€” the number of rounds the game has. Then t lines follow, each contains two integers s_i and e_i (1 ≀ s_i ≀ e_i ≀ 10^{18}) β€” the i-th round's information. The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts. Output Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise. Examples Input 3 5 8 1 4 3 10 Output 1 1 Input 4 1 2 2 3 3 4 4 5 Output 0 0 Input 1 1 1 Output 0 1 Input 2 1 9 4 5 Output 0 0 Input 2 1 2 2 8 Output 1 0 Input 6 216986951114298167 235031205335543871 148302405431848579 455670351549314242 506251128322958430 575521452907339082 1 768614336404564650 189336074809158272 622104412002885672 588320087414024192 662540324268197150 Output 1 0 Note Remember, whoever writes an integer greater than e_i loses. Submitted Solution: ``` t = int(input("Enter number of rounds: ")) A = [] for i in range(0, t): s, e= input().split(" ") s, e = int(s), int(e) if s == e: A.append(2) else: if s + 1 > e and 2 * s > e: A.append(1) elif s + 1 <= e and 2 * s > e: A.append(1) elif s + 1 > e and 2 * s <= e: A.append(1) else: A.append(0) if A[len(A)-1] == 0: x = 1 y = 0 prev0 = 1 prev1 = 0 elif A[len(A)-1] == 1: x = 1 y = 1 prev0 = 1 prev1 = 1 else: x = 0 y = 1 prev0 = 0 prev1 = 1 for i in range(len(A)-2, -1, -1): if A[i] == 0: x = 1 - prev0 y = 1 - prev1 prev0 = 1 - prev0 elif A[i] == 1: prev0 = 1 prev1 = 1 x = 1 print(x, y) ```
instruction
0
91,901
19
183,802
No
output
1
91,901
19
183,803
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,017
19
184,034
Tags: binary search, data structures Correct Solution: ``` from collections import defaultdict temp_n = n = int(input()) front = defaultdict(int) back = defaultdict(int) while temp_n > 0: temp_n -= 1 f, b = map(int, input().split()) front[f] += 1 if f != b: back[b] += 1 target = (n + 1) // 2 done = False for count, num in sorted(((_count, _num) for _num, _count in front.items()), reverse=True): if count >= target: print("0") done = True break if count + back[num] >= target: print(str(target - count)) done = True break if not done: for count, num in sorted(((_count, _num) for _num, _count in back.items()), reverse=True): if count >= target: print(str(target)) done = True break if not done: print("-1") ```
output
1
92,017
19
184,035
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,018
19
184,036
Tags: binary search, data structures Correct Solution: ``` d=dict() n=int(input()) for i in range(n): f,b=map(int,input().split()) if f not in d:d[f]=[0,0] d[f][0]+=1 if f!=b: if b not in d:d[b]=[0,0] d[b][1]+=1 n=(n+1)//2 m=2*n for aa,a in d.items(): if sum(a)>=n: m=min(m,n-a[0]) if m==2*n:print(-1) else: print(max(0,m)) ```
output
1
92,018
19
184,037
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,019
19
184,038
Tags: binary search, data structures Correct Solution: ``` import sys from math import * input=sys.stdin.readline #n,m,k=map(int,input().split()) d={} n=int(input()) for i in range(n): x,y=map(int,input().split()) if x in d: d[x][0]+=1 else: d[x]=[1,0] if x==y: continue if y in d: d[y][1]+=1 else: d[y]=[0,1] mini=10**15 for i in d: if int(ceil(n/2))-d[i][0]<=d[i][1]: mini=min(mini,max(0,int(ceil(n/2))-d[i][0])) if mini!=10**15: print(mini ) else : print(-1) ```
output
1
92,019
19
184,039
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,020
19
184,040
Tags: binary search, data structures Correct Solution: ``` n=int(input()) a=[0]*n b=[0]*n cards=[] for i in range(n): a[i],b[i]=map(int,input().split()) if a[i]==b[i]: b[i]=-1 cards.append([a[i],b[i]]) half=n%2+n//2 from collections import Counter c1=Counter(a) c2=Counter(b) l1=[[c1[i],i] for i in c1] if max(c1[i] for i in c1)>=half: ans=0 print(ans) else: f=0 ans=n for i in range(len(l1)): #print(l1[i]) req=half-l1[i][0] if c2[l1[i][1]]>=req: ans=min(req,ans) #print(l1[i][1]) f=1 for i in b : if c1[i] or i==-1 : continue if c2[i]>=half: ans=min(ans,half) f=1 if f==0: print(-1) else: print(ans) ```
output
1
92,020
19
184,041
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,021
19
184,042
Tags: binary search, data structures Correct Solution: ``` def main(): n = int(input()) d = {} for i in range(n): a, b = [int(i) for i in input().split()] if a == b: if a not in d: d[a] = [0, 0] d[a][0] += 1 else: if a not in d: d[a] = [0, 0] d[a][0] += 1 if b not in d: d[b] = [0, 0] d[b][1] += 1 result = float("inf") half = (n + 1) // 2 for a, b in d.values(): if a + b >= half: result = min(max(0, half - a), result) if result == float("inf"): print(-1) else: print(result) main() ```
output
1
92,021
19
184,043
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,022
19
184,044
Tags: binary search, data structures Correct Solution: ``` n=int(input()) m={} v=[] for i in range(n): a=input().split() v.append(a) m[a[0]]=[0,0] m[a[1]]=[0,0] for i in range(n): m[v[i][0]][0]+=1 if v[i][0]!=v[i][1]: m[v[i][1]][1]+=1 min=99999999 for i in m: if sum(m[i])>=(n+1)//2: if (n+1)//2-m[i][0]<min: if (n+1)//2-m[i][0]<=0: print(0) exit() else: min=(n+1)//2-m[i][0] print(min if min!=99999999 else-1) ```
output
1
92,022
19
184,045
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,023
19
184,046
Tags: binary search, data structures Correct Solution: ``` from collections import defaultdict from math import ceil d= defaultdict(list) n = int(input()) for i in range(n): a,b =map(int,input().split()) if a==b: if a in d: d[a][0]+=1 else: d[a]=[1,0] else: if a in d: d[a][0]+=1 else: d[a] =[1,0] if b in d: d[b][1]+=1 else: d[b] = [0,1] m= ceil(n/2) #print(d) mini = 1e6 for i in d: a =d[i][0] b= d[i][1] if a+b>=m: if a>=m: mini= min(0,mini) else: mini = min(m-a,mini) if mini ==1e6: print(-1) else: print(mini) ```
output
1
92,023
19
184,047
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
instruction
0
92,024
19
184,048
Tags: binary search, data structures Correct Solution: ``` from collections import Counter import sys n=int(input()) ans=10**20 fr={} ba={} for _ in range(n): x,y=map(int,input().split()) if x in fr: fr[x]+=1 else: fr[x]=1 if x!=y: if y in ba: ba[y]+=1 else: ba[y]=1 for i in fr: if i in ba: x=fr[i]+ba[i] if x*2>=n: ans=min(ans,max(0,(n+1)//2-fr[i])) else: x=fr[i] if x*2>=n: ans=min(ans,max(0,(n+1)//2-fr[i])) for j in ba: y=ba[j] if y*2>=n: ans=min(ans,max(0,(n+1)//2)) if ans==10**20: ans=-1 print(ans) ```
output
1
92,024
19
184,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` from collections import defaultdict import sys n = int(sys.stdin.readline()) # n: nro de cartas de dos colores sol = -1 # sol: nro minimo de movimientos mitad = (n + 1) // 2 f = defaultdict(int) a = defaultdict(int) # f,a: contador de las cartas que estan de frente y atras for i in range(n): frente, atras = map(int, input().split()) # frente, atras: son los colores de las cartas en su respectiva cara - pueden ser el mismo f[frente] += 1 if (frente != atras): a[atras] += 1 f = sorted(f.items(), key=lambda item: item[1], reverse=True) # Ordenar por el color que mas se repite al que menos # No hay que hacer nada, ya hay un color predominante if (f[0][1] >= mitad): sol = 0 if (sol == -1): for color, cant in f: if (a[color] + cant >= mitad): sol = mitad - cant break if (sol == -1): a = sorted(a.items(), key=lambda item: item[1], reverse=True) for color, cant in a: if (cant >= mitad): sol = mitad break sys.stdout.write(str(sol)) # En cualquier mov el elefante puede dar vuelta una carta # Un conjunto de cartas sera chistoso si al menos la mitad # de las cartas tiene el mismo color ```
instruction
0
92,025
19
184,050
Yes
output
1
92,025
19
184,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` n = int(input()) m = int((n+1)/2) colors = [[ ]]*n colors_d = {} for i in range(n): a , b = list(map(int,input().split(' '))) colors[i]=[a,b] if a in colors_d.keys(): colors_d[a][0] += 1 else: colors_d[a] = [1,0] if a != b: if b in colors_d.keys(): colors_d[b][1] += 1 else: colors_d[b] = [0,1] minimo = 50001 for i,el in colors_d.items(): if sum(el) < m: continue if el[0] > m: minimo = 0 break if m - el[0] < minimo: minimo = m-el[0] if minimo == 50001: minimo = -1 print(minimo) ```
instruction
0
92,026
19
184,052
Yes
output
1
92,026
19
184,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` from collections import Counter import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ########################################################## #it=iter(t) #if all(c in it for c in s): #ls.sort(key=lambda x: (x[0], x[1])) #n,k= map(int, input().split()) # ls=list(map(int,input().split())) # for i in range(m): import math #n,k= map(int, input().split()) #ls=list(map(int,input().split())) x=int(input()) d={} ls={} same={} for i in range(x): n,k= map(int, input().split()) if n==k: if n in same: same[n]+=1 else: same[n]=1 if n not in ls: ls[n]=1 else: ls[n]+=1 if k not in d: d[k]=1 else: d[k]+=1 var=x//2 if x%2!=0: var+=1 ans=var f=0 for i in ls: if i in d: value=ls[i]+d[i] if i in same: value-=same[i] if value>=var: ans=min(ans,max(0,var-ls[i])) f=1 else: if ls[i]>=var: ans=0 f=1 break if f==1: print(ans) else: for i in d: if d[i]>=var: print(var) exit() print(-1) #arr=list(map(int,input().split())) ```
instruction
0
92,027
19
184,054
Yes
output
1
92,027
19
184,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` """ Author - Satwik Tiwari . 24th NOV , 2020 - Tuesday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools import * from heapq import * from math import gcd, factorial,floor,ceil,sqrt from copy import deepcopy from collections import deque from bisect import bisect_left as bl from bisect import bisect_right as br from bisect import bisect #============================================================================================== #fast I/O region 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def graph(vertex): return [[] for i in range(0,vertex+1)] def testcase(t): for pp in range(t): solve(pp) def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : y%=(p-1) #not so sure about this. used when y>p-1. if p is prime. res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True inf = pow(10,20) mod = 10**9+7 #=============================================================================================== # code here ;)) def solve(case): n = int(inp()) front = {} back = {} have = {} same = {} a = [] for i in range(n): l,r = sep() if(l == r): if(l not in same): same[l] = 1 else: same[l] +=1 a.append((l,r)) have[l] = 1 have[r] = 1 if(l in front): front[l]+=1 else: front[l] = 1 if(r in back): back[r]+=1 else: back[r] = 1 ans = inf for i in have: # print(i) f = (0 if i not in front else front[i]) b = (0 if i not in back else back[i]) - (0 if i not in same else same[i]) # print(f,b,ceil(n/2)) if(f>=ceil(n/2)): ans = min(ans,0) elif(f+b >= ceil(n/2)): ans = min(ans,ceil(n/2) - f) print(-1 if ans == inf else ans) testcase(1) # testcase(int(inp())) ```
instruction
0
92,028
19
184,056
Yes
output
1
92,028
19
184,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` n=int(input()) a=[0]*n b=[0]*n cards=[] for i in range(n): a[i],b[i]=map(int,input().split()) if a[i]==b[i]: b[i]=-1 cards.append([a[i],b[i]]) half=n%2+n//2 from collections import Counter c1=Counter(a) c2=Counter(b) l1=[[c1[i],i] for i in c1] l2=[[c2[i],i] for i in c2] l1.sort(reverse=True) #l2.sort() if l1[0][0]>=half: ans=0 print(ans) else: f=0 ans=100000000000000000000000 for i in range(len(l1)): #print(l1[i]) req=half-l1[i][0] if c2[l1[i][1]]>=req: ans=min(req,ans) #print(l1[i][1]) f=1 break if f==0: print(-1) else: print(ans) ```
instruction
0
92,029
19
184,058
No
output
1
92,029
19
184,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` n=int(input()) a=[0]*n b=[0]*n cards=[] for i in range(n): a[i],b[i]=map(int,input().split()) if a[i]==b[i]: b[i]=-1 cards.append([a[i],b[i]]) half=n%2+n//2 from collections import Counter c1=Counter(a) c2=Counter(b) l1=[[c1[i],i] for i in c1] l2=[[c2[i],i] for i in c2] l1.sort(reverse=True) #l2.sort() if l1[0][0]>=half: ans=0 print(ans) else: f=0 ans=100000000000000000000000 for i in range(len(l1)): #print(l1[i]) req=half-l1[i][0] if c2[l1[i][1]]>=req: ans=min(req,ans) #print(l1[i][1]) f=1 break for i in b : if c1[i]: continue if c2[i]>=half: ans=min(ans,half) f=1 if f==0: print(-1) else: print(ans) ```
instruction
0
92,030
19
184,060
No
output
1
92,030
19
184,061
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` n=int(input()) a=[0]*n b=[0]*n cards=[] for i in range(n): a[i],b[i]=map(int,input().split()) if a[i]==b[i]: b[i]=-1 cards.append([a[i],b[i]]) half=n%2+n//2 from collections import Counter c1=Counter(a) c2=Counter(b) l1=[[c1[i],i] for i in c1] if l1[0][0]>=half: ans=0 print(ans) else: f=0 ans=n for i in range(len(l1)): #print(l1[i]) req=half-l1[i][0] if c2[l1[i][1]]>=req: ans=min(req,ans) #print(l1[i][1]) f=1 for i in b : if c1[i]: continue if c2[i]>=half: ans=min(ans,half) f=1 if f==0: print(-1) else: print(ans) ```
instruction
0
92,031
19
184,062
No
output
1
92,031
19
184,063
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered). Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny. Input The first line contains a single integer n (1 ≀ n ≀ 105) β€” the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 β€” colors of both sides. The first number in a line is the color of the front of the card, the second one β€” of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces. Output On a single line print a single integer β€” the sought minimum number of moves. If it is impossible to make the set funny, print -1. Examples Input 3 4 7 4 7 7 4 Output 0 Input 5 4 7 7 4 2 11 9 7 1 1 Output 2 Note In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0. In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. Submitted Solution: ``` n = int(input()) m = int((n+1)/2) colors = [[ ]]*n colors_d = {} for i in range(n): a , b = list(map(int,input().split(' '))) colors[i]=[a,b] if a in colors_d.keys(): colors_d[a][0] += 1 else: colors_d[a] = [1,0] if b in colors_d.keys(): colors_d[b][1] += 1 else: colors_d[b] = [0,1] minimo = 50001 for i,el in colors_d.items(): if sum(el) < m: continue if el[0] > m: minimo = 0 break if m - el[0] < minimo: minimo = m-el[0] if minimo == 50001: minimo = -1 print(minimo) ```
instruction
0
92,032
19
184,064
No
output
1
92,032
19
184,065
Provide tags and a correct Python 3 solution for this coding contest problem. Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules: * Before the beginning of the game Petya writes permutation 1, 2, ..., n on the blackboard. After that Petya makes exactly k moves, which are described below. * During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. 1. Let's assume that the board contains permutation p1, p2, ..., pn at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: pq1, pq2, ..., pqn. In other words, Petya applies permutation q (which he has got from his mother) to permutation p. 2. All actions are similar to point 1, except that Petya writes permutation t on the board, such that: tqi = pi for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p. We know that after the k-th move the board contained Masha's permutation s1, s2, ..., sn. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times. Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding. Input The first line contains two integers n and k (1 ≀ n, k ≀ 100). The second line contains n space-separated integers q1, q2, ..., qn (1 ≀ qi ≀ n) β€” the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format. It is guaranteed that the given sequences q and s are correct permutations. Output If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes). Examples Input 4 1 2 3 4 1 1 2 3 4 Output NO Input 4 1 4 3 1 2 3 4 2 1 Output YES Input 4 3 4 3 1 2 3 4 2 1 Output YES Input 4 2 4 3 1 2 2 1 4 3 Output YES Input 4 1 4 3 1 2 2 1 4 3 Output NO Note In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed. In the second sample the described situation is possible, in case if after we toss a coin, we get tails. In the third sample the possible coin tossing sequence is: heads-tails-tails. In the fourth sample the possible coin tossing sequence is: heads-heads.
instruction
0
92,048
19
184,096
Tags: implementation, math Correct Solution: ``` def Solve(x,L): if(x==k[0]): return L==S if((x,tuple(L)) in Mem): return False if(L==S): return False E=[] for i in range(len(L)): E.append(L[Q[i]-1]) if(Solve(x+1,E)): return True E=[0]*len(L) for i in range(len(L)): E[Q[i]-1]=L[i] if(Solve(x+1,E)): return True Mem[(x,tuple(L))]=1 return False Mem={} k=[0] n,k[0]=map(int,input().split()) P=list(range(1,n+1)) Q=list(map(int,input().split())) S=list(map(int,input().split())) if(Solve(0,P)): print("YES") else: print("NO") ```
output
1
92,048
19
184,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n. A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≀ ai ≀ n), all integers there are distinct. There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules: * Before the beginning of the game Petya writes permutation 1, 2, ..., n on the blackboard. After that Petya makes exactly k moves, which are described below. * During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. 1. Let's assume that the board contains permutation p1, p2, ..., pn at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: pq1, pq2, ..., pqn. In other words, Petya applies permutation q (which he has got from his mother) to permutation p. 2. All actions are similar to point 1, except that Petya writes permutation t on the board, such that: tqi = pi for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p. We know that after the k-th move the board contained Masha's permutation s1, s2, ..., sn. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times. Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding. Input The first line contains two integers n and k (1 ≀ n, k ≀ 100). The second line contains n space-separated integers q1, q2, ..., qn (1 ≀ qi ≀ n) β€” the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format. It is guaranteed that the given sequences q and s are correct permutations. Output If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes). Examples Input 4 1 2 3 4 1 1 2 3 4 Output NO Input 4 1 4 3 1 2 3 4 2 1 Output YES Input 4 3 4 3 1 2 3 4 2 1 Output YES Input 4 2 4 3 1 2 2 1 4 3 Output YES Input 4 1 4 3 1 2 2 1 4 3 Output NO Note In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed. In the second sample the described situation is possible, in case if after we toss a coin, we get tails. In the third sample the possible coin tossing sequence is: heads-tails-tails. In the fourth sample the possible coin tossing sequence is: heads-heads. Submitted Solution: ``` def Solve(x,L): if(x==k[0]): return L==S if((x,tuple(L)) in Mem): return False if(L==S): return False E=[] for i in range(len(L)): E.append(L[Q[i]-1]) if(Solve(x+1,E)): return True E=[0]*len(L) for i in range(len(L)): E[Q[i]-1]=L[i] if(Solve(x+1,E)): return True Mem[(x,tuple(L))]=1 return False Mem={} k=[0] n,k[0]=map(int,input().split()) P=list(range(1,n+1)) Q=list(map(int,input().split())) S=list(map(int,input().split())) print(Solve(0,P)) ```
instruction
0
92,049
19
184,098
No
output
1
92,049
19
184,099
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,219
19
184,438
Tags: implementation Correct Solution: ``` n = int(input()) y = 0 x = 0 for i in range(n): dice1, dice2 = map(int, input().split()) if dice1 > dice2: y += 1 elif dice1 < dice2: x += 1 else: x += 0 if x < y: print('Mishka') if x > y: print('Chris')###CF703A ##n = int(input()) ##a = 0 ##b = 0 ##for i in range(n): ## m, c = map(int, input().split()) ## if m >= c: ## a += 1 ## else: ## b += 1 ##if a > b: ## print('Mishka') ##elif a < b: ## print('Chris') ##elif a == b: ## print("Friendship is magic!^^") if x == y: print('Friendship is magic!^^') ```
output
1
92,219
19
184,439
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,220
19
184,440
Tags: implementation Correct Solution: ``` a=int(input()) m=0 c=0 for i in range(a): x,y=map(int,input().split()) if(x>y): c+=1 elif(x<y): m+=1 else: pass if(m>c): print("Chris") elif(c>m): print("Mishka") else: print("Friendship is magic!^^") ```
output
1
92,220
19
184,441
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,221
19
184,442
Tags: implementation Correct Solution: ``` n=int(input()) cm=cc=0 for i in range(n): x=[] x=input().split() if(x[0]>x[1]): cm+=1 elif(x[0]<x[1]): cc+=1 else: cm+=1 cc+=1 if(cm>cc): print('Mishka') elif(cm==cc): print('Friendship is magic!^^') else: print('Chris') ```
output
1
92,221
19
184,443
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,222
19
184,444
Tags: implementation Correct Solution: ``` n = int(input()) msh = cr = 0 for i in range(n): m,c = list(map(int,input().split())) if m==c: continue if max(m,c)==m: msh+=1 if max(m,c)==c: cr+=1 if msh<cr: print("Chris") elif cr<msh: print("Mishka") else: print("Friendship is magic!^^") ```
output
1
92,222
19
184,445
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,223
19
184,446
Tags: implementation Correct Solution: ``` c,m=0,0 for _ in range(int(input())): a,b=map(int,input().split()) if a>b: m+=1 elif b>a: c+=1 if m>c: print('Mishka') elif c>m: print('Chris') else: print('Friendship is magic!^^') ```
output
1
92,223
19
184,447
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,224
19
184,448
Tags: implementation Correct Solution: ``` n = int(input()) k = [] for i in range(n): j = input() j = j.split() k.append(int(j[0])) k.append(int(j[1])) #print(k) m = 0 c = 0 for i in range(0,n): #print(i) if k[i*2]>k[i*2+1]: m+=1 elif k[i*2]<k[i*2+1]: c+=1 if m>c: print("Mishka") elif m<c: print("Chris") else: print("Friendship is magic!^^") ```
output
1
92,224
19
184,449
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,225
19
184,450
Tags: implementation Correct Solution: ``` n = int(input()) m,c=[0,0] for i in range(n): x,y=map(int, input().split()) if x>y: m+=1 elif y>x: c+=1 if m>c: print ('Mishka') elif c>m: print ('Chris') else: print ('Friendship is magic!^^') ```
output
1
92,225
19
184,451
Provide tags and a correct Python 3 solution for this coding contest problem. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.
instruction
0
92,226
19
184,452
Tags: implementation Correct Solution: ``` n = int(input()) s = [] for i in range(n): m, c = map(int,input().split()) if m>c: s.append('m') if c>m: s.append('c') m = s.count('m') c = s.count('c') if m>c: print('Mishka') elif c>m: print('Chris') else: print('Friendship is magic!^^') ```
output
1
92,226
19
184,453
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` b1 = 0 b2 = 0 for i in range(int(input())): a, b = map(int, input().split()) if a > b: b1 += 1 elif b > a: b2 += 1 if b1 > b2: print('Mishka') elif b2 > b1: print('Chris') else: print('Friendship is magic!^^') ```
instruction
0
92,227
19
184,454
Yes
output
1
92,227
19
184,455
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` mi = 0 ch = 0 for _ in range(int(input())): m , c = [int(x) for x in input().split()] if m > c: mi += 1 elif m < c: ch += 1 else: mi += 1 ch += 1 if mi > ch: print("Mishka") elif mi < ch: print("Chris") else: print("Friendship is magic!^^") ```
instruction
0
92,228
19
184,456
Yes
output
1
92,228
19
184,457
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` m,c=0,0 for _ in range(int(input())): a,b=map(int,input().split()) if a!=b: if a>b: m+=1 else: c+=1 if m>c: print("Mishka") elif m==c: print("Friendship is magic!^^") else: print("Chris") ```
instruction
0
92,229
19
184,458
Yes
output
1
92,229
19
184,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` n = int(input()) a, b = 0, 0 for _ in range(n): u, v = map(int, input().split()) if u > v: a += 1 elif u < v: b += 1 if a > b: print('Mishka') elif a < b: print('Chris') else: print('Friendship is magic!^^') ```
instruction
0
92,230
19
184,460
Yes
output
1
92,230
19
184,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` n = int(input()) mishka = 0 chris = 0 for _ in range(n): m, c = [int(x) for x in input().split()] mishka += m chris += c if mishka > chris: print('Mishka') elif chris > mishka: print('Chris') else: print('Friendship is magic!^^') ```
instruction
0
92,231
19
184,462
No
output
1
92,231
19
184,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` n = int(input()) m = 0 c = 0 for f in range(n): a , b = map(int,input().split()) if a > b : m += 1 elif a < b : c += 1 if m > n : print("Mishka") elif m < n : print("Chris") else : print("Friendship") ```
instruction
0
92,232
19
184,464
No
output
1
92,232
19
184,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` m,c = 0,0 for _ in range(int(input())): t1,t2 = map(int, input().split()) if t1 > t2: m +=1 elif t1<t2: c +=1 print(['Mishika', 'Chris'][m<c] if (m or c) else 'Friendship is magic!^^') ```
instruction
0
92,233
19
184,466
No
output
1
92,233
19
184,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! Input The first line of the input contains single integer n n (1 ≀ n ≀ 100) β€” the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≀ mi, ci ≀ 6) β€” values on dice upper face after Mishka's and Chris' throws in i-th round respectively. Output If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Examples Input 3 3 5 2 1 4 2 Output Mishka Input 2 6 1 1 6 Output Friendship is magic!^^ Input 3 1 5 3 3 2 2 Output Chris Note In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. Submitted Solution: ``` import sys n = int(input()) mr = 0 cr = 0 for i in range(n): m, c = map(int, sys.stdin.readline().split()) if m > c: mr += 1 elif c > m: mr += 1 if mr > cr: print("Mishka") elif cr > mr: print("Chris") else: print("Friendship is magic!^^") ```
instruction
0
92,234
19
184,468
No
output
1
92,234
19
184,469
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,235
19
184,470
Tags: implementation Correct Solution: ``` n = int(input()) s = input() s1 = 0 for i in s: if i=="<": s1+=1 else: break for i in range(n-1,-1,-1): if s[i]==">": s1+=1 else: break print(s1) ```
output
1
92,235
19
184,471
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,236
19
184,472
Tags: implementation Correct Solution: ``` input() s = input() n = len(s) rs = 0 for i in range(n): if s[i] == '<': rs+=1 else: break for i in range(n - 1,-1,-1): if s[i] =='>': rs+=1 else: break print(rs) ```
output
1
92,236
19
184,473
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,237
19
184,474
Tags: implementation Correct Solution: ``` n = int(input()) s = input() print(n - len(s.lstrip("<").rstrip(">"))) ```
output
1
92,237
19
184,475
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,238
19
184,476
Tags: implementation Correct Solution: ``` if __name__ == "__main__": nr_of_bumpers = int(input()) bumper_types = list(input()) fall_bumpers = 0 bumper_index = 0 while bumper_index < nr_of_bumpers and bumper_types[bumper_index] == '<': fall_bumpers += 1 bumper_index += 1 bumper_index = nr_of_bumpers - 1 while bumper_index >= 0 and bumper_types[bumper_index] == '>': fall_bumpers += 1 bumper_index -= 1 print(fall_bumpers) ```
output
1
92,238
19
184,477
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,239
19
184,478
Tags: implementation Correct Solution: ``` input() s=input() ans=0 for i in s: if i=='<':ans+=1 else:break for i in s[::-1]: if i=='>':ans+=1 else:break print(ans) ```
output
1
92,239
19
184,479
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,240
19
184,480
Tags: implementation Correct Solution: ``` import sys import math import bisect def solve(s): n = len(s) ans = 0 for i in range(n): if s[i] == '<': ans += 1 else: break for i in range(n - 1, -1, -1): if s[i] == '>': ans += 1 else: break return ans def main(): n = int(input()) s = input() ans = solve(s) print(ans) if __name__ == "__main__": main() ```
output
1
92,240
19
184,481
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,241
19
184,482
Tags: implementation Correct Solution: ``` n = int(input()) v = input() count = 0 right = 0 left = 0 second = 0 for i in range(0,len(v)): if v[i]=='<' and right==0: count+=1 if v[i] == '<' and right == 1: second = 0 if v[i]=='>' : second+=1 right=1 print(max(count+second,0)) ```
output
1
92,241
19
184,483
Provide tags and a correct Python 3 solution for this coding contest problem. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
instruction
0
92,242
19
184,484
Tags: implementation Correct Solution: ``` n = int(input()) s = input() i = 0 while i < n and s[i] == '<': i += 1 ans = i i = n - 1 while i >= 0 and s[i] == '>': i -= 1 ans += n - 1 - i print(ans) ```
output
1
92,242
19
184,485
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field. Submitted Solution: ``` '''input 6 <<><>> ''' n = int(input()) s = input() def solve(): off = 0 for i, c in enumerate(s): if c == '>': off = i break else: return len(s) for i, c in enumerate(reversed(s)): if c == '<': off += i break else: return len(s) return off print(solve()) ```
instruction
0
92,243
19
184,486
Yes
output
1
92,243
19
184,487
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field. Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. Input The first line of the input contains a single integer n (1 ≀ n ≀ 200 000) β€” the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. Output Print one integer β€” the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. Examples Input 4 &lt;&lt;&gt;&lt; Output 2 Input 5 &gt;&gt;&gt;&gt;&gt; Output 5 Input 4 &gt;&gt;&lt;&lt; Output 0 Note In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field. Submitted Solution: ``` n = int(input()); s = input(); i = 0; ans = 0; while i < n and s[i] == "<": ans += 1; i += 1; i = n - 1; while i >= 0 and s[i] == ">": ans += 1; i -= 1; print(ans); ```
instruction
0
92,244
19
184,488
Yes
output
1
92,244
19
184,489