description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
field = [] def full_line(x, y, vx, vy): global field summ = 0 for k in range(0, 5): if ( x == len(field) or y == len(field[x]) or x == -1 or y == -1 or "O" == field[x][y] ): return False if "X" == field[x][y]: summ += 1 x += vx y += vy return summ > 3 for i in range(0, 10): field.append(list(input())) for i in range(0, 10): for j in range(0, 10): if "O" != field[i][j] and ( full_line(i, j, 0, 1) or full_line(i, j, 1, 0) or full_line(i, j, 1, 1) or full_line(i, j, 1, -1) ): print("YES") exit() print("NO")
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER STRING VAR VAR VAR RETURN NUMBER IF STRING VAR VAR VAR VAR NUMBER VAR VAR VAR VAR RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF STRING VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
r = [input() for _ in range(10)] c = [] for i in range(10): t = "" for j in range(10): t += r[j][i] c.append(t) for x in r: if any(s in x for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() else: for y in c: if any(s in y for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() else: for a in range(6): z1 = "" z2 = "" for b in range(10 - a): z1 += r[a + b][b] z2 += r[b][a + b] if any(s in z1 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() if any(s in z2 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() c = list(zip(*r[::-1])) for a in range(6): z1 = "" z2 = "" for b in range(10 - a): z1 += c[a + b][b] z2 += c[b][a + b] if any(s in z1 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() if any(s in z2 for s in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]): print("YES") quit() print("NO")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR LIST STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [ ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", ""], ] for i in range(10): a.append(list(" " + input() + " ")) a.append(["", "", "", "", "", "", "", "", "", "", "", "", "", ""]) a.append(["", "", "", "", "", "", "", "", "", "", "", "", "", ""]) for i in range(2, 12): for ii in range(2, 12): if a[i][ii] == ".": a[i][ii] = "X" toch = ii st = i kek = 0 while a[st][toch] == "X": toch += 1 kek += 1 toch = ii - 1 while a[st][toch] == "X": toch -= 1 kek += 1 if kek >= 5: print("YES") exit() toch = ii kek = 0 while a[st][toch] == "X": st += 1 kek += 1 st = i - 1 while a[st][toch] == "X": st -= 1 kek += 1 if kek >= 5: print("YES") exit() kek = 0 st = i while a[st][toch] == "X": toch += 1 st += 1 kek += 1 toch = ii - 1 st = i - 1 while a[st][toch] == "X": toch -= 1 st -= 1 kek += 1 if kek >= 5: print("YES") exit() kek = 0 toch = ii st = i while a[st][toch] == "X": toch += 1 st -= 1 kek += 1 toch = ii - 1 st = i + 1 while a[st][toch] == "X": toch -= 1 st += 1 kek += 1 if kek >= 5: print("YES") exit() a[i][ii] = "." else: print("NO")
ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys table = [line.strip() for line in sys.stdin] def check_position(table, row, column): if table[row][column] != ".": return False left_sum = 0 tmp = column - 1 while tmp >= 0 and table[row][tmp] == "X": left_sum += 1 tmp -= 1 right_sum = 0 tmp = column + 1 while tmp < 10 and table[row][tmp] == "X": right_sum += 1 tmp += 1 if left_sum + right_sum >= 4: return True up_sum = 0 tmp = row - 1 while tmp >= 0 and table[tmp][column] == "X": up_sum += 1 tmp -= 1 down_sum = 0 tmp = row + 1 while tmp < 10 and table[tmp][column] == "X": down_sum += 1 tmp += 1 if up_sum + down_sum >= 4: return True maindup_sum = 0 tmp_row = row - 1 tmp_col = column - 1 while tmp_row >= 0 and tmp_col >= 0 and table[tmp_row][tmp_col] == "X": tmp_row -= 1 tmp_col -= 1 maindup_sum += 1 maindup_down = 0 tmp_row = row + 1 tmp_col = column + 1 while tmp_row < 10 and tmp_col < 10 and table[tmp_row][tmp_col] == "X": tmp_row += 1 tmp_col += 1 maindup_down += 1 if maindup_sum + maindup_down >= 4: return True dup_sum = 0 tmp_row = row - 1 tmp_col = column + 1 while tmp_row >= 0 and tmp_col < 10 and table[tmp_row][tmp_col] == "X": tmp_row -= 1 tmp_col += 1 dup_sum += 1 dup_down = 0 tmp_row = row + 1 tmp_col = column - 1 while tmp_row < 10 and tmp_col >= 0 and table[tmp_row][tmp_col] == "X": tmp_row += 1 tmp_col -= 1 dup_down += 1 if dup_sum + dup_down >= 4: return True return False for row in range(10): for column in range(10): if check_position(table, row, column): print("YES") sys.exit(0) print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
from sys import stdin def myInput(): board = [[], [], [[] for _ in range(20)], [[] for _ in range(20)]] for line in stdin: board[0].append(list(line.rstrip())) board[1] = map(list, zip(*board[0])) for i in range(len(board[0])): for j in range(len(board[0])): board[2][i + j].append(board[0][i][j]) board[3][i - j + len(board[0])].append(board[0][i][j]) return board def solve(board): for b in board: for line in b: val_bef = 0 val_eft = 0 ok = False for dig in line: if dig == "O": ok = False val_bef = 0 val_eft = 0 else: if dig == "X": if ok: val_eft += 1 else: val_bef += 1 elif dig == ".": if ok: ok = True val_bef = val_eft val_eft = 0 else: ok = True if ok and val_eft + val_bef >= 4: return True return False board = myInput() if solve(board): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR LIST LIST LIST LIST VAR FUNC_CALL VAR NUMBER LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR FUNC_DEF FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR STRING IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [list(input()) for i in range(10)] flag = True for i in range(10): for j in range(10): l, r = j - 1, j + 1 cnt_lr = 0 while 0 <= l and a[i][l] == "X": l -= 1 cnt_lr += 1 while r < 10 and a[i][r] == "X": r += 1 cnt_lr += 1 d, u = i - 1, i + 1 cnt_du = 0 while 0 <= d and a[d][j] == "X": d -= 1 cnt_du += 1 while u < 10 and a[u][j] == "X": u += 1 cnt_du += 1 ld, ru = 1, 1 cnt_ld_ru = 0 while i - ld >= 0 and j - ld >= 0 and a[i - ld][j - ld] == "X": cnt_ld_ru += 1 ld += 1 while i + ru < 10 and j + ru < 10 and a[i + ru][j + ru] == "X": cnt_ld_ru += 1 ru += 1 lu, rd = 1, 1 cnt_lu_rd = 0 while i + lu < 10 and j - lu >= 0 and a[i + lu][j - lu] == "X": cnt_lu_rd += 1 lu += 1 while i - rd >= 0 and j + rd < 10 and a[i - rd][j + rd] == "X": cnt_lu_rd += 1 rd += 1 if (cnt_lr >= 4 or cnt_du >= 4 or cnt_ld_ru >= 4 or cnt_lu_rd >= 4) and a[i][ j ] == ".": print("YES") exit() print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matriz = [[letra for letra in input()] for i in range(10)] flag = False for i in range(10): for j in range(6): m = [ matriz[i][j], matriz[i][j + 1], matriz[i][j + 2], matriz[i][j + 3], matriz[i][j + 4], ] if m.count(".") == 1 and m.count("X") == 4: flag = True break for i in range(6): for j in range(10): m = [ matriz[i][j], matriz[i + 1][j], matriz[i + 2][j], matriz[i + 3][j], matriz[i + 4][j], ] if m.count(".") == 1 and m.count("X") == 4: flag = True break for i in range(6): for j in range(6): m = [ matriz[i][j], matriz[i + 1][j + 1], matriz[i + 2][j + 2], matriz[i + 3][j + 3], matriz[i + 4][j + 4], ] if m.count(".") == 1 and m.count("X") == 4: flag = True break for i in range(6): for j in range(9, 3, -1): m = [ matriz[i][j], matriz[i + 1][j - 1], matriz[i + 2][j - 2], matriz[i + 3][j - 3], matriz[i + 4][j - 4], ] if m.count(".") == 1 and m.count("X") == 4: flag = True break if flag: print("YES") else: print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
field = [] for _ in range(10): field.append(input()) rows = [row for row in field] columns = [] for i in range(10): s = "" for j in range(10): s += field[j][i] columns.append(s) maindiags = [] for k in range(-9, 10): s = "" if k >= 0: for i in range(10 - k): for j in range(k, 10): if i == j - k: s += field[i][j] else: for i in range(-k, 10): for j in range(10 + k): if i == j - k: s += field[i][j] maindiags.append(s) diags = [] for k in range(-9, 10): s = "" if k >= 0: for i in range(k, 10): for j in range(k, 10): if i == 9 - j + k: s += field[i][j] else: for i in range(10 + k): for j in range(10 + k): if i == 9 - j + k: s += field[i][j] diags.append(s) def answer(a): patterns = [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."] for elem in a: if len(elem) >= 5: for k in range(5): for i in range(len(elem) - 4): flag = True for j in range(5): if elem[i + j] != patterns[k][j]: flag = False if flag: return True return False a = rows + columns + maindiags + diags print("YES" if answer(a) else "NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(par): if ( par.find(".XXXX") != -1 or par.find("X.XXX") != -1 or par.find("XX.XX") != -1 or par.find("XXX.X") != -1 or par.find("XXXX.") != -1 ): print("YES") quit() arr = [] for i in range(10): arr.append(input()) for string in arr: check(string) rarr = [] for a in range(10): string = "" for b in range(10): string += arr[b][a] rarr.append(string) for string in rarr: check(string) aarr = [] for a in range(4, 10): b, c = 0, a string = "" while True: string += arr[b][c] if b == a and not c: break b += 1 c -= 1 aarr.append(string) for string in aarr: check(string) barr = [] a = 1 while True: b, c = a, 9 string = "" while True: string += arr[b][c] if b == 9 and c == a: break b += 1 c -= 1 barr.append(string) if a == 5: break a += 1 b -= 1 for string in barr: check(string) carr = [] for a in range(6): b, c = a, 0 string = "" while True: string += arr[b][c] if b == 9 and c == 9 - a: break b += 1 c += 1 carr.append(string) for string in carr: check(string) darr = [] for a in range(1, 7): b, c = a, 0 string = "" while True: string += arr[c][b] if b == 9 and c == 9 - a: break b += 1 c += 1 darr.append(string) for string in darr: check(string) print("NO")
FUNC_DEF IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING WHILE NUMBER VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING WHILE NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING WHILE NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING WHILE NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
s = [] h = 0 h1 = 0 z = 0 x = 0 f1 = 0 while h < 10: a = list(input()) s.append(a) a = [] h = h + 1 while h1 < 60: w = s[z][x] + s[z][x + 1] + s[z][x + 2] + s[z][x + 3] + s[z][x + 4] if w.count("X") == 4 and w.count(".") == 1: f1 = 1 break x = x + 1 if x == 6: z = z + 1 x = 0 h1 = h1 + 1 h1 = 0 z = 0 x = 0 if f1 == 0: while h1 < 60: w = s[z][x] + s[z + 1][x] + s[z + 2][x] + s[z + 3][x] + s[z + 4][x] if w.count("X") == 4 and w.count(".") == 1: f1 = 1 break z = z + 1 if z == 6: x = x + 1 z = 0 h1 = h1 + 1 h1 = 0 z = 0 x = 0 if f1 == 0: while h1 < 36: w = ( s[z][x] + s[z + 1][x + 1] + s[z + 2][x + 2] + s[z + 3][x + 3] + s[z + 4][x + 4] ) if w.count("X") == 4 and w.count(".") == 1: f1 = 1 break x = x + 1 if x == 6: z = z + 1 x = 0 h1 = h1 + 1 h1 = 0 z = 0 x = 0 s.reverse() if f1 == 0: while h1 < 36: w = ( s[z][x] + s[z + 1][x + 1] + s[z + 2][x + 2] + s[z + 3][x + 3] + s[z + 4][x + 4] ) if w.count("X") == 4 and w.count(".") == 1: f1 = 1 break x = x + 1 if x == 6: z = z + 1 x = 0 h1 = h1 + 1 if f1 == 0: print("NO") if f1 == 1: print("YES")
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [[x for x in input()] for i in range(10)] def f(): global a for i in range(10): for j in range(6): q = 0 for k in range(5): q += int(a[i][j + k] == "X") if q == 5: return 1 for j in range(10): for i in range(6): q = 0 for k in range(5): q += int(a[i + k][j] == "X") if q == 5: return 1 for i in range(6): for j in range(6): q = 0 for k in range(5): q += int(a[i + k][j + k] == "X") if q == 5: return 1 return 0 fl = 0 for i in range(10): for j in range(10): if a[i][j] == ".": a[i][j] = "X" if f(): fl = 1 a[i][j] = "." for i in range(10): a[i] = list(reversed(a[i])) for i in range(10): for j in range(10): if a[i][j] == ".": a[i][j] = "X" if f(): fl = 1 a[i][j] = "." if fl: print("YES") else: print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR STRING IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(r0, c0, dr, dc): cntx = 0 cnte = 0 for i in range(5): r = r0 + dr * i c = c0 + dc * i if r < 0 or 9 < r or c < 0 or 9 < c: break elif cells[r][c] == "X": cntx += 1 elif cells[r][c] == ".": cnte += 1 return cntx == 4 and cnte == 1 cells = [list(input()) for _ in range(10)] drc = [(1, 0), (0, 1), (1, 1), (1, -1)] ans = "NO" for r0 in range(10): for c0 in range(10): for dr, dc in drc: if check(r0, c0, dr, dc): ans = "YES" print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER RETURN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(i, j): i1 = i j1 = j i2 = i j2 = j while j1 + 1 <= m - 1 and mat[i][j1 + 1] == "X": j1 += 1 while j2 - 1 >= 0 and mat[i][j2 - 1] == "X": j2 -= 1 if abs(j2 - j1) >= 4: return True i1 = i j1 = j i2 = i j2 = j while i1 + 1 <= n - 1 and mat[i1 + 1][j] == "X": i1 += 1 while i2 - 1 >= 0 and mat[i2 - 1][j] == "X": i2 -= 1 if abs(i1 - i2) >= 4: return True i1 = i j1 = j i2 = i j2 = j while i1 - 1 >= 0 and j1 + 1 <= m - 1 and mat[i1 - 1][j1 + 1] == "X": i1 -= 1 j1 += 1 while i2 + 1 <= n - 1 and j2 - 1 >= 0 and mat[i2 + 1][j2 - 1] == "X": i2 += 1 j2 -= 1 if abs(i1 - i2) >= 4 and abs(j1 - j2) >= 4: return True i1 = i j1 = j i2 = i j2 = j while i1 - 1 >= 0 and j1 - 1 >= 0 and mat[i1 - 1][j1 - 1] == "X": i1 -= 1 j1 -= 1 while i2 + 1 <= n - 1 and j2 + 1 <= m - 1 and mat[i2 + 1][j2 + 1] == "X": i2 += 1 j2 += 1 if abs(i1 - i2) >= 4 and abs(j1 - j2) >= 4: return True return False n, m = 10, 10 mat = [list(input()) for _ in range(m)] for i in range(n): for j in range(m): if mat[i][j] == ".": mat[i][j] = "X" if check(i, j): print("YES") exit(0) mat[i][j] = "." print("NO")
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(a, b, c, d, e): countX = 0 countD = 0 if a == "X": countX += 1 elif a == ".": countD += 1 if b == "X": countX += 1 elif b == ".": countD += 1 if c == "X": countX += 1 elif c == ".": countD += 1 if d == "X": countX += 1 elif d == ".": countD += 1 if e == "X": countX += 1 elif e == ".": countD += 1 return countX == 4 and countD == 1 def f(a): for i in range(10): for j in range(6): if ( check(a[i][j], a[i][j + 1], a[i][j + 2], a[i][j + 3], a[i][j + 4]) or i < 6 and check( a[i][j], a[i + 1][j + 1], a[i + 2][j + 2], a[i + 3][j + 3], a[i + 4][j + 4], ) ): return True for i in range(10): for j in range(6): if ( check(a[j][i], a[j + 1][i], a[j + 2][i], a[j + 3][i], a[j + 4][i]) or i > 3 and check( a[j][i], a[j + 1][i - 1], a[j + 2][i - 2], a[j + 3][i - 3], a[j + 4][i - 4], ) ): return True print("YES" if f([input() for _ in range(10)]) else "NO")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER RETURN VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [] for i in range(10): a.append([]) p = [c for c in input()] for j in range(10): if p[j] == "X": a[i].append(1) elif p[j] == "O": a[i].append(-1) elif p[j] == ".": a[i].append(0) f = True for i in range(10): for j in range(10): s1, s2, s3, s4 = 0, 0, 0, 0 if i <= 5: s1 = a[i][j] + a[i + 1][j] + a[i + 2][j] + a[i + 3][j] + a[i + 4][j] if j <= 5: s2 = a[i][j] + a[i][j + 1] + a[i][j + 2] + a[i][j + 3] + a[i][j + 4] if i <= 5 and j <= 5: s3 = ( a[i][j] + a[i + 1][j + 1] + a[i + 2][j + 2] + a[i + 3][j + 3] + a[i + 4][j + 4] ) if i >= 4 and j <= 5: s4 = ( a[i][j] + a[i - 1][j + 1] + a[i - 2][j + 2] + a[i - 3][j + 3] + a[i - 4][j + 4] ) if max(s1, s2, s3, s4) == 4: f = False if f: print("NO") else: print("YES")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
mat1 = [input() for l in range(10)] mat2 = list(reversed(mat1)) mat3 = [] for l in mat1: mat3.append(l[::-1]) def horizontal(inp, i, j): s = "" for k in range(j, j + 5): s = s + inp[i][k] return s def vertical(inp, i, j): s = "" for k in range(i, i + 5): s = s + inp[k][j] return s def diagonal(inp, i, j): first = range(i, i + 5, 1) second = range(j, j + 5, 1) s = "" for k, l in zip(first, second): s += inp[k][l] return s def checker(s): if "0" in s: return False elif s.count("X") < 4: return False elif "." not in s: return False return True def solve(mat): for i in range(6): for j in range(6): if checker(horizontal(mat, i, j)): return True if checker(vertical(mat, i, j)): return True if checker(diagonal(mat, i, j)): return True return False a = solve(mat1) b = solve(mat2) c = solve(mat3) if a or b or c: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF STRING VAR RETURN NUMBER IF FUNC_CALL VAR STRING NUMBER RETURN NUMBER IF STRING VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [] for i in range(10): a.append(input()) def valid(x, y): if 0 <= x <= 9 and 0 <= y <= 9: return True return False def check(x, y, direction): ans = 1 curr_x = x + direction[0] curr_y = y + direction[1] while valid(curr_x, curr_y) and a[curr_x][curr_y] == "X": ans += 1 curr_x += direction[0] curr_y += direction[1] curr_x = x - direction[0] curr_y = y - direction[1] while valid(curr_x, curr_y) and a[curr_x][curr_y] == "X": ans += 1 curr_x -= direction[0] curr_y -= direction[1] return ans curr = 0 for i in range(10): for j in range(10): if a[i][j] == ".": for direction in [[1, 0], [0, 1], [1, 1], [1, -1]]: curr = max(curr, check(i, j, direction)) if curr >= 5: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF NUMBER VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING FOR VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def solve(): grid = [input() for r in range(10)] def win(arr): return arr.count("X") == 4 and arr.count(".") == 1 for i in range(10): for j in range(10): if win(grid[i][j : j + 5]): return True elif win([grid[k][j] for k in range(i, min(i + 5, 10))]): return True elif win([grid[i + k][j + k] for k in range(min(5, 10 - i, 10 - j))]): return True elif win([grid[i + k][j - k] for k in range(min(5, j + 1, 10 - i))]): return True return False if solve(): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def main(): Map = [] for i in range(10): Map += [input()] for i in range(10): for j in range(10): count = 0 count2 = 0 if i <= 5: for k in range(5): if Map[i + k][j] == "X": count += 1 elif Map[i + k][j] == ".": count2 += 1 if count == 4 and count2 == 1: print("YES") return 0 count = 0 count2 = 0 if j <= 5: for k in range(5): if Map[i][j + k] == "X": count += 1 elif Map[i][j + k] == ".": count2 += 1 if count == 4 and count2 == 1: print("YES") return 0 count = 0 count2 = 0 if i <= 5 and j <= 5: for k in range(5): if Map[i + k][j + k] == "X": count += 1 elif Map[i + k][j + k] == ".": count2 = 1 if count == 4 and count2 == 1: print("YES") return 0 count = 0 count2 = 0 if i >= 4 and j <= 5: count = 0 for k in range(5): if Map[i - k][j + k] == "X": count += 1 elif Map[i - k][j + k] == "O": count -= 1 if count == 4: print("YES") return 0 print("NO") return 0 main()
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
t = [] for i in range(10): t.append(input()) for i in range(10): s = "" for j in range(10): s = s + t[j][i] t.append(s) for i in range(6): s = "" for j in range(10 - i): s = s + t[i + j][j] t.append(s) for i in range(1, 6): s = "" for j in range(10 - i): s = s + t[j][i + j] t.append(s) for i in range(6): s = "" for j in range(10 - i): s = s + t[i + j][9 - j] t.append(s) for i in range(1, 6): s = "" for j in range(10 - i): s = s + t[j][9 - j - i] t.append(s) for line in t: x, o, dot, f = 0, 0, 0, 0 for i in range(5): if line[i] == "X": x += 1 elif line[i] == "O": o += 1 elif line[i] == ".": dot += 1 if x == 4 and dot == 1: print("YES") f = 1 break if f: break for i in range(5, len(line)): if line[i - 5] == "X": x -= 1 elif line[i - 5] == "O": o -= 1 elif line[i - 5] == ".": dot -= 1 if line[i] == "X": x += 1 elif line[i] == "O": o += 1 elif line[i] == ".": dot += 1 if x == 4 and dot == 1: print("YES") f = 1 break if f: break if not f: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
l = [input() for _ in range(10)] for c in range(5): t = ["X"] * 5 t[c] = "." for i in range(10): for j in range(6): cnt = 0 for k in range(5): if l[i][j + k] == ".": cnt += 1 elif l[i][j + k] == "O": cnt += 2 if cnt == 1: print("YES") exit() for i in range(6): for j in range(10): cnt = 0 for k in range(5): if l[i + k][j] == ".": cnt += 1 elif l[i + k][j] == "O": cnt += 2 if cnt == 1: print("YES") exit() for i in range(6): for j in range(6): cnt = 0 for k in range(5): if l[i + k][j + k] == ".": cnt += 1 elif l[i + k][j + k] == "O": cnt += 2 if cnt == 1: print("YES") exit() for i in range(4, 10): for j in range(6): cnt = 0 for k in range(5): if l[i - k][j + k] == ".": cnt += 1 elif l[i - k][j + k] == "O": cnt += 2 if cnt == 1: print("YES") exit() print("NO")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def find(r, c, s1, s2): combo = 0 while a[r][c] == "X": r += s1 c += s2 combo += 1 return combo a = ["@@@@@@@@@@@@"] marks = [] dots = [] ans = 1 for i in range(10): a.append("@" + input() + "@") a.append("@@@@@@@@@@@@") for i in range(1, 11): for j in range(1, 11): if a[i][j] == ".": res1 = find(i, j - 1, 0, -1) + find(i, j + 1, 0, 1) res2 = find(i + 1, j, 1, 0) + find(i - 1, j, -1, 0) res3 = find(i + 1, j + 1, 1, 1) + find(i - 1, j - 1, -1, -1) res4 = find(i + 1, j - 1, 1, -1) + find(i - 1, j + 1, -1, 1) if res1 > 3 or res2 > 3 or res3 > 3 or res4 > 3: ans = 0 print("YNEOS"[ans::2])
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR STRING VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
k = [] for i in range(10): s = str(input()) k.append(s) def krestik(mast, nom_str, nom_symvol): x = 1 y = 1 z = 1 v = 1 if mast[nom_str][nom_symvol] == ".": lov = 1 else: lov = 0 if nom_symvol <= 5: for i in range(4): if ( mast[nom_str][nom_symvol + x] == "X" or mast[nom_str][nom_symvol + x] == "." ): if mast[nom_str][nom_symvol + x] == ".": lov += 1 x += 1 if x == 5 and lov == 1: return "YES" if mast[nom_str][nom_symvol] == ".": lov = 1 else: lov = 0 if nom_str <= 5: for i in range(4): if ( mast[nom_str + y][nom_symvol] == "X" or mast[nom_str + y][nom_symvol] == "." ): if mast[nom_str + y][nom_symvol] == ".": lov += 1 y += 1 if y == 5 and lov == 1: return "YES" if mast[nom_str][nom_symvol] == ".": lov = 1 else: lov = 0 if nom_str <= 5 and nom_symvol <= 5: for i in range(4): if ( mast[nom_str + z][nom_symvol + z] == "X" or mast[nom_str + z][nom_symvol + z] == "." ): if mast[nom_str + z][nom_symvol + z] == ".": lov += 1 z += 1 if z == 5 and lov == 1: return "YES" if mast[nom_str][nom_symvol] == ".": lov = 1 else: lov = 0 if nom_str <= 5 and nom_symvol >= 4: for i in range(4): if ( mast[nom_str + v][nom_symvol - v] == "X" or mast[nom_str + v][nom_symvol - v] == "." ): if mast[nom_str + v][nom_symvol - v] == ".": lov += 1 v += 1 if v == 5 and lov == 1: return "YES" return "NO" def vivod(mask): for i in range(10): for g in range(10): if mask[i][g] == "X" or mask[i][g] == ".": if krestik(mask, i, g) == "YES": return "YES" if krestik(mask, i, g) == "NO": continue return "NO" print(vivod(k))
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR STRING RETURN STRING IF FUNC_CALL VAR VAR VAR VAR STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
s = [] def check(): for i in range(10): for j in range(10): if j + 4 < 10: th = "" for k in range(5): th += s[i][j + k] if th == "XXXXX": return True for i in range(10): for j in range(10): if i + 4 < 10: th = "" for k in range(5): th += s[i + k][j] if th == "XXXXX": return True for i in range(10): for j in range(10): if i + 4 < 10 and j + 4 < 10: th = "" for k in range(5): th += s[i + k][j + k] if th == "XXXXX": return True for i in range(10): for j in range(10): if i + 4 < 10 and j - 4 >= 0: th = "" for k in range(5): th += s[i + k][j - k] if th == "XXXXX": return True return False for i in range(10): s.append(list(input())) flag = False if check(): flag = True for i in range(10): for j in range(10): if s[i][j] == ".": s[i][j] = "X" if check(): flag = True s[i][j] = "." if flag: print("YES") else: print("NO")
ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR IF VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [] f = False for i in range(10): s = input() a.append(s) if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True for i in range(10): s = "" for j in range(10): s += a[j][i] if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True for k in range(10): s = "" for i in range(k + 1): s += a[i][k - i] if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True for k in range(10, 19): s = "" for i in range(k - 9, 10): s += a[i][k - i] if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True for k in range(-9, 0): s = "" for i in range(k + 10): s += a[i][i - k] if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True for k in range(10): s = "" for i in range(k, 10): s += a[i][i - k] if ( s.find("XXXX.") != -1 or s.find("XXX.X") != -1 or s.find("XX.XX") != -1 or s.find("X.XXX") != -1 or s.find(".XXXX") != -1 ): f = True if f: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
l = [""] * 12 flag = False for i in range(10): x = input() cnt = int(0) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True x = list(x) for j in range(10): l[j] += x[j] for i in range(12): x = "".join(l[i]) cnt = int(0) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True for i in range(10): for j in range(10): a = "" if i >= 4 and j >= 4: a += ( l[i][j] + l[i - 1][j - 1] + l[i - 2][j - 2] + l[i - 3][j - 3] + l[i - 4][j - 4] ) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True x = "" if i <= 5 and j <= 5: x += ( l[i][j] + l[i + 1][j + 1] + l[i + 2][j + 2] + l[i + 3][j + 3] + l[i + 4][j + 4] ) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True x = "" if i <= 5 and j >= 4: x += ( l[i][j] + l[i + 1][j - 1] + l[i + 2][j - 2] + l[i + 3][j - 3] + l[i + 4][j - 4] ) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True x = "" if i >= 4 and j <= 5: x += ( l[i][j] + l[i - 1][j + 1] + l[i - 2][j + 2] + l[i - 3][j + 3] + l[i - 4][j + 4] ) if "XX.XX" in x or "X.XXX" in x or ".XXXX" in x or "XXX.X" in x or "XXXX." in x: flag = True print("YES" if flag == True else "NO")
ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [input() for i in range(10)] gg = False def checkAns(b): dot = 0 x = 0 for i in b: if i == "X": x += 1 if i == ".": dot += 1 if x == 4 and dot == 1 or x == 5: return True def find(b): if len(b) < 5: return global gg ans = 0 for i in range(len(b) - 4): if checkAns(b[i : i + 5]): gg = True return for i in range(10): find(a[i]) find("".join([a[j][i] for j in range(10)])) find("".join([a[j][j + i] for j in range(10) if j + i < 10])) find("".join([a[j + i][j] for j in range(10) if j + i < 10])) find("".join([a[j][9 - j - i] for j in range(10) if 9 - j - i >= 0])) find("".join([a[j + i][9 - j] for j in range(10) if j + i < 10])) if gg: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys input = sys.stdin.readline s = [ list(map(lambda x: 1 if x == "X" else 2 if x == "O" else 0, input().rstrip())) for _ in range(10) ] def check(sx, sy): return ( all(x < 10 and s[sy][x] == 1 for x in range(sx, sx + 5)) or all(y < 10 and s[y][sx] == 1 for y in range(sy, sy + 5)) or all( x < 10 and y < 10 and s[y][x] == 1 for x, y in zip(range(sx, sx + 5), range(sy, sy + 5)) ) or all( x < 10 and 0 <= y and s[y][x] == 1 for x, y in zip(range(sx, sx + 5), range(sy, sy - 5, -1)) ) ) for y in range(10): for x in range(10): if s[y][x] != 0: continue s[y][x] = 1 if any(check(i, j) for i in range(10) for j in range(10)): print("YES") exit() s[y][x] = 0 print("NO")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER VAR STRING NUMBER NUMBER FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
mat = [] n = 10 m = 10 for i in range(n): s = input() s = list(s) mat.append(s) f = 0 def check(mat): for i in range(10): for j in range(10): for k in range(5): if i + k >= 10 or mat[i + k][j] != "X": break else: return 1 for k in range(5): if j + k >= 10 or mat[i][j + k] != "X": break else: return 1 for k in range(5): if i + k >= 10 or j + k >= 10 or mat[i + k][j + k] != "X": break else: return 1 for k in range(5): if i + k >= 10 or j - k < 0 or mat[i + k][j - k] != "X": break else: return 1 return 0 for i in range(n): for j in range(m): if mat[i][j] == ".": mat[i][j] = "X" if check(mat): f = 1 print("YES") exit() else: mat[i][j] = "." print("NO")
ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matrix = list() for _ in range(10): matrix.append(list(input())) for i in range(10): for j in range(6): temp = matrix[i][j : j + 5] if temp.count("X") == 4 and "." in temp: print("YES") quit() for j in range(10): for i in range(6): temp = list() for k in range(i, i + 5): temp.append(matrix[k][j]) if temp.count("X") == 4 and "." in temp: print("YES") quit() for i in range(6): for j in range(6): temp = list() for k in range(5): temp.append(matrix[i + k][j + k]) if temp.count("X") == 4 and "." in temp: print("YES") quit() for i in range(0, 6): for j in range(4, 10): temp = list() for k in range(5): temp.append(matrix[i + k][j - k]) if temp.count("X") == 4 and "." in temp: print("YES") quit() print("NO")
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR STRING NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import itertools def main(): global MAP MAP = [] for i in range(10): MAP.append(list(input())) for i, j in itertools.product(range(10), range(10)): if check(i, j): print("YES") return print("NO") def check(i, j): for a, b in [(0, 1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, 0), (0, -1), (-1, -1)]: count = 0 ecount = 0 for k in range(5): if not 0 <= i + k * a <= 9 or not 0 <= j + k * b <= 9: break if MAP[i + k * a][j + k * b] == "X": count += 1 elif MAP[i + k * a][j + k * b] == ".": ecount += 1 if count == 4 and ecount == 1: return True return False main()
IMPORT FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FUNC_DEF FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matrix = [] for i in range(10): matrix.append(list(input())) alllines = matrix.copy() for i in range(10): line = [] for j in range(10): line.append(matrix[j][i]) alllines.append(line) for i in range(6): line = [] x = i y = 0 while x < 10 and y < 10: line.append(matrix[y][x]) x += 1 y += 1 alllines.append(line) for i in range(1, 6): line = [] x = 0 y = i while x < 10 and y < 10: line.append(matrix[y][x]) x += 1 y += 1 alllines.append(line) for i in range(9, 3, -1): line = [] x = i y = 0 while x >= 0 and y < 10: line.append(matrix[y][x]) x -= 1 y += 1 alllines.append(line) for i in range(1, 6): line = [] x = 9 y = i while x >= 0 and y < 10: line.append(matrix[y][x]) x -= 1 y += 1 alllines.append(line) f = False for i in alllines: i = "".join(i) for j in [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."]: if i.find(j) != -1: f = True break if f: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR LIST STRING STRING STRING STRING STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(a, x, y): left = 0 right = 0 for i in range(1, 11): if x - i >= 0: if a[x - i][y] == "X": left += 1 else: break else: break for i in range(1, 11): if x + i < 10: if a[x + i][y] == "X": right += 1 else: break else: break if right + left >= 4: return 1 left = 0 right = 0 for i in range(1, 11): if y - i >= 0: if a[x][y - i] == "X": left += 1 else: break else: break for i in range(1, 11): if y + i < 10: if a[x][y + i] == "X": right += 1 else: break else: break if right + left >= 4: return 1 left = 0 right = 0 for i in range(1, 11): if x - i >= 0 and y - i >= 0: if a[x - i][y - i] == "X": left += 1 else: break else: break for i in range(1, 11): if x + i < 10 and y + i < 10: if a[x + i][y + i] == "X": right += 1 else: break else: break if right + left >= 4: return 1 left = 0 right = 0 for i in range(1, 11): if x - i >= 0 and y + i < 10: if a[x - i][y + i] == "X": left += 1 else: break else: break for i in range(1, 11): if x + i < 10 and y - i >= 0: if a[x + i][y - i] == "X": right += 1 else: break else: break if right + left >= 4: return 1 return 0 a = [] for i in range(10): gg = input() a.append([]) for j in range(10): a[i].append(gg[j]) for i in range(10): for j in range(10): if a[i][j] == ".": a[i][j] = "X" if check(a, i, j): print("YES") return a[i][j] = "." print("NO")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [] for i in range(10): s = input() a.append(s) ans = 0 for i in range(10): for j in range(10): if a[i][j] == ".": k = i - 1 c = 1 while k >= 0 and a[k][j] == "X": c += 1 k -= 1 k = i + 1 while k < 10 and a[k][j] == "X": c += 1 k += 1 if c >= 5: ans = 1 k = j - 1 c = 1 while k >= 0 and a[i][k] == "X": c += 1 k -= 1 k = j + 1 while k < 10 and a[i][k] == "X": c += 1 k += 1 if c >= 5: ans = 1 k = i - 1 l = j - 1 c = 1 while k >= 0 and l >= 0 and a[k][l] == "X": c += 1 k -= 1 l -= 1 k = i + 1 l = j + 1 while k < 10 and l < 10 and a[k][l] == "X": c += 1 k += 1 l += 1 if c >= 5: ans = 1 k = i - 1 l = j + 1 c = 1 while k >= 0 and l < 10 and a[k][l] == "X": c += 1 k -= 1 l += 1 k = i + 1 l = j - 1 while k < 10 and l >= 0 and a[k][l] == "X": c += 1 k += 1 l -= 1 if c >= 5: ans = 1 if ans: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys def check(x): t, p = 0, 0 for i in range(5): if x[i] == "X": t += 1 elif x[i] == ".": p += 1 if t == 4 and p == 1: return True return False def main(): x = [] for i in range(10): x.append(sys.stdin.readline().rstrip()) flag = False for i in range(10): for j in range(10): if j + 4 < 10 and check([x[i][k] for k in range(j, j + 5)]): flag = True if i + 4 < 10 and check([x[k][j] for k in range(i, i + 5)]): flag = True if i + 4 < 10 and j + 4 < 10 and check([x[i + k][j + k] for k in range(5)]): flag = True if i + 4 < 10 and j - 4 >= 0 and check([x[i + k][j - k] for k in range(5)]): flag = True if flag: print("YES") else: print("NO") main()
IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matrix = [None] * 10 for i in range(10): matrix[i] = input() for i in range(10): for j in range(10): if 0 <= j and j <= 5: count_x = 0 has_o = False for k in range(5): if matrix[i][j + k] == "X": count_x += 1 elif matrix[i][j + k] == "O": has_o = True break if count_x == 4 and not has_o: print("YES") exit() if 0 <= i and i <= 5: count_x = 0 has_o = False for k in range(5): if matrix[i + k][j + k] == "X": count_x += 1 elif matrix[i + k][j + k] == "O": has_o = True break if count_x == 4 and not has_o: print("YES") exit() if 0 <= i and i <= 5: count_x = 0 has_o = False for k in range(5): if matrix[i + k][j] == "X": count_x += 1 elif matrix[i + k][j] == "O": has_o = True break if count_x == 4 and not has_o: print("YES") exit() if 4 <= j and j <= 9: count_x = 0 has_o = False for k in range(5): if matrix[i + k][j - k] == "X": count_x += 1 elif matrix[i + k][j - k] == "O": has_o = True break if count_x == 4 and not has_o: print("YES") exit() print("NO")
ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
T = [[] for i in range(10)] for i in range(10): a = list(input()) T[i] = a flag = False for i in range(10): for j in range(10): if T[i][j] == "X": for dx, dy in [ (0, -1), (-1, 0), (0, 1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), ]: flag2 = True cross = 0 emp = 0 for k in range(5): nx, ny = i + k * dx, j + k * dy if 0 <= nx < 10 and 0 <= ny < 10 and T[nx][ny] == "X": cross += 1 elif 0 <= nx < 10 and 0 <= ny < 10 and T[nx][ny] == ".": emp += 1 else: flag2 = False break if flag2 and cross == 4 and emp == 1: flag = True if flag: print("YES") else: print("NO")
ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF NUMBER VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER IF NUMBER VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
grid = [] for i in range(10): grid.append(input()) s2 = set(list(map(tuple, ".XXXX X.XXX XX.XX XXX.X XXXX.".split()))) s = set() for i in range(10): for j in range(10): r, d, d1, d2 = None, None, None, None if j + 4 < 10: r = tuple([grid[i][j + x] for x in range(5)]) if i + 4 < 10: d = tuple([grid[i + x][j] for x in range(5)]) if i + 4 < 10 and j + 4 < 10: d1 = tuple([grid[i + x][j + x] for x in range(5)]) if i - 4 >= 0 and j + 4 < 10: d2 = tuple([grid[i - x][j + x] for x in range(5)]) s.add(r) s.add(d) s.add(d1) s.add(d2) if len(s2 & s) > 0: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NONE NONE NONE NONE IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def din(matx): for i in range(10): for j in range(10): dd = False x = [[i, j], [i - 1, j - 1], [i - 2, j - 2], [i - 3, j - 3], [i - 4, j - 4]] for p in x: if p[0] > 9 or p[0] < 0 or p[1] > 9 or p[1] < 0: dd = True break if not dd: c = 0 for p in x: if matx[p[0]][p[1]] == "X": c += 1 if matx[p[0]][p[1]] == "O": c = 0 break if c == 4: return True return False def dix(matx): for i in range(10): for j in range(10): dd = False x = [[i, j], [i + 1, j - 1], [i + 2, j - 2], [i + 3, j - 3], [i + 4, j - 4]] for p in x: if p[0] > 9 or p[0] < 0 or p[1] > 9 or p[1] < 0: dd = True break if not dd: c = 0 for p in x: if matx[p[0]][p[1]] == "X": c += 1 if matx[p[0]][p[1]] == "O": c = 0 break if c == 4: return True return False def hoz(matx): for i in range(10): for j in range(10): dd = False x = [[i, j], [i, j - 1], [i, j - 2], [i, j - 3], [i, j - 4]] for p in x: if p[0] > 9 or p[0] < 0 or p[1] > 9 or p[1] < 0: dd = True break if not dd: c = 0 for p in x: if matx[p[0]][p[1]] == "X": c += 1 if matx[p[0]][p[1]] == "O": c = 0 break if c == 4: return True return False def vet(matx): for i in range(10): for j in range(10): dd = False x = [[i, j], [i - 1, j], [i - 4, j], [i - 3, j], [i - 2, j]] for p in x: if p[0] > 9 or p[0] < 0 or p[1] > 9 or p[1] < 0: dd = True break if not dd: c = 0 for p in x: if matx[p[0]][p[1]] == "X": c += 1 if matx[p[0]][p[1]] == "O": c = 0 break if c == 4: return True return False matx = [list(input().strip()) for i in range(10)] if vet(matx) | hoz(matx) | din(matx) | dix(matx): print("YES") else: print("NO")
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR LIST VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR FOR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER IF VAR VAR NUMBER VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys a = ( [(["."] * 20) for _ in range(5)] + [list("." * 5 + input() + "." * 5) for _ in range(10)] + [(["."] * 20) for _ in range(5)] ) def judge(y, x, dy, dx): return all(a[y + dy * d][x + dx * d] == "X" for d in range(5)) def solve(y, x): a[y][x] = "X" for delta in range(-4, 5): if ( judge(y + delta, x, 1, 0) or judge(y, x + delta, 0, 1) or judge(y + delta, x + delta, 1, 1) or judge(y + delta, x - delta, 1, -1) ): return True a[y][x] = "." return False for i in range(5, 15): for j in range(5, 15): if a[i][j] == "." and solve(i, j): print("YES") exit() print("NO")
IMPORT ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING NUMBER FUNC_CALL VAR BIN_OP STRING NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
N = 10 A = [] for _ in range(N): A += [list(input())] result = "NO" for i in range(N // 2 + 1): for j in range(N // 2 + 1): cross, dots = 0, 0 for k in range(N // 2): if A[i + k][j + k] == ".": dots += 1 elif A[i + k][j + k] == "X": cross += 1 if cross == 4 and dots == 1: result = "YES" for i in range(N // 2 + 1): for j in range(N // 2 - 1, N): cross, dots = 0, 0 for k in range(N // 2): if A[i + k][j - k] == ".": dots += 1 elif A[i + k][j - k] == "X": cross += 1 if cross == 4 and dots == 1: result = "YES" for i in range(N): for j in range(N // 2 + 1): cross, dots = 0, 0 for k in range(N // 2): if A[i][j + k] == ".": dots += 1 elif A[i][j + k] == "X": cross += 1 if cross == 4 and dots == 1: result = "YES" for i in range(N // 2 + 1): for j in range(N): cross, dots = 0, 0 for k in range(N // 2): if A[i + k][j] == ".": dots += 1 elif A[i + k][j] == "X": cross += 1 if cross == 4 and dots == 1: result = "YES" print(result)
ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def is_good(matrix): for i in range(10): for j in range(10): if matrix[i][j] == "X": if ( matrix[i][j - 2] == matrix[i][j - 1] == matrix[i][j] == matrix[i][j + 1] == matrix[i][j + 2] or matrix[i - 2][j] == matrix[i - 1][j] == matrix[i][j] == matrix[i + 1][j] == matrix[i + 2][j] ): return True for k in range(4): if ( matrix[i - k][j - k] == matrix[i - k + 1][j - k + 1] == matrix[i - k + 2][j - k + 2] == matrix[i - k + 3][j - k + 3] == matrix[i - k + 4][j - k + 4] ): return True if ( matrix[i - k][j + k] == matrix[i - k + 1][j + k - 1] == matrix[i - k + 2][j + k - 2] == matrix[i - k + 3][j + k - 3] == matrix[i - k + 4][j + k - 4] ): return True return False matrix = [(["."] * 14) for i in range(14)] for i in range(10): string = input() for j in range(10): matrix[i][j] = string[j] for i in range(10): for j in range(10): if matrix[i][j] == ".": matrix[i][j] = "X" if is_good(matrix): print("YES") exit() matrix[i][j] = "." print("NO")
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def diagL(coor, arr): tmp = coor opt = 1 while tmp - 11 >= 0 and tmp // 10 - 1 == (tmp - 11) // 10: tmp -= 11 if arr[tmp] == "X": opt += 1 else: break tmp = coor while tmp + 11 < 100 and tmp // 10 + 1 == (tmp + 11) // 10: tmp += 11 if arr[tmp] == "X": opt += 1 else: break if opt >= 5: return True return False def diagR(coor, arr): tmp = coor opt = 1 while tmp - 9 >= 0 and tmp // 10 - 1 == (tmp - 9) // 10: tmp -= 9 if arr[tmp] == "X": opt += 1 else: break tmp = coor while tmp + 9 < 100 and tmp // 10 + 1 == (tmp + 9) // 10: tmp += 9 if arr[tmp] == "X": opt += 1 else: break if opt >= 5: return True return False def sideX(coor, arr): tmp = coor opt = 1 while (tmp - 1) // 10 == coor // 10: tmp -= 1 if arr[tmp] == "X": opt += 1 else: break tmp = coor while (tmp + 1) // 10 == coor // 10: tmp += 1 if arr[tmp] == "X": opt += 1 else: break if opt >= 5: return True return False def sideY(coor, arr): tmp = coor opt = 1 while tmp - 10 >= 0: tmp -= 10 if arr[tmp] == "X": opt += 1 else: break tmp = coor while tmp + 10 < 100: tmp += 10 if arr[tmp] == "X": opt += 1 else: break if opt >= 5: return True return False ans = [] for i in range(10): a = list(input()) for k in range(10): ans.append(a[k]) a = [] for i in range(100): if ans[i] == ".": a.append(diagL(i, ans)) a.append(diagR(i, ans)) a.append(sideX(i, ans)) a.append(sideY(i, ans)) if any(a): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matrix = [] N = 10 for i in range(N): matrix.append(list(input())) won = False def check_alice_won(matrix): maxScore = 0 for i in range(N): curScore = 0 for j in range(N): if matrix[i][j] == "X": curScore += 1 else: if curScore > maxScore: maxScore = curScore curScore = 0 if curScore >= maxScore: maxScore = curScore if maxScore >= 5: return True maxScore = 0 for i in range(N): curScore = 0 for j in range(N): if matrix[j][i] == "X": curScore += 1 else: if curScore > maxScore: maxScore = curScore curScore = 0 if curScore >= maxScore: maxScore = curScore if maxScore >= 5: return True maxScore = 0 for p in range(0, 2 * N - 1): curScore = 0 for q in list(range(max(0, p - N + 1), min(p, N - 1) + 1)): if matrix[p - q][q] == "X": curScore += 1 else: if curScore > maxScore: maxScore = curScore curScore = 0 if curScore >= maxScore: maxScore = curScore if maxScore >= 5: return True maxScore = 0 for p in range(0, 2 * N - 1): curScore = 0 for q in list(range(max(0, p - N + 1), min(p, N - 1) + 1)): if matrix[p - q][N - 1 - q] == "X": curScore += 1 else: if curScore >= maxScore: maxScore = curScore curScore = 0 if curScore >= maxScore: maxScore = curScore if maxScore >= 5: return True return False for i in range(N): for j in range(N): if matrix[i][j] == "." and won == False: matrix[i][j] = "X" if check_alice_won(matrix) == True: won = True matrix[i][j] = "." if won: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
n = int(input()) a = tuple(map(int, input().split())) c = {} p = {} s = x = y = 0 m = -1e18 for i in range(0, len(a)): d = c.get(a[i]) if d != None and s - d + a[i] * 2 > m: m = s - d + a[i] * 2 x, y = p.get(a[i]), i if a[i] > 0: s += a[i] if p.get(a[i]) == None: p[a[i]] = i c[a[i]] = s a = [ str(i + 1) for i in range(0, len(a)) if i != x and i != y and (a[i] < 0 or i < x or i > y) ] print(m, len(a)) print(" ".join(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
n, t = int(input()), list(map(int, input().split())) a, b = {}, {} for i, j in enumerate(t): if not j in a: a[j] = i else: b[j] = i p = [(a[j], b[j] - 1) for j in b] s = [(j if j > 0 else 0) for j in t] u = v = 2 * t[p[0][0]] - 1 for i in range(n - 1): s[i + 1] += s[i] for i, j in p: u = 2 * t[i] + s[j] - s[i] if u > v: a, b, v = i, j, u s = ( list(range(1, a + 1)) + [i for i, j in enumerate(t[a + 1 : b + 1], a + 2) if j < 0] + list(range(b + 3, n + 1)) ) print(v, len(s)) print(" ".join(map(str, s)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR DICT DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
length = int(input()) array = [int(a) for a in input().split()] maxSum = -1e21 resIndexes = [] for i in range(length): for j in range(length - 1, -1, -1): if j > i and array[i] == array[j]: tmp = sum(array[i : j + 1]) indexes = [] for index in range(i + 1, j): if array[index] < 0: tmp -= array[index] indexes.append(index + 1) if tmp > maxSum: maxSum = tmp indexes += list(range(1, i + 1)) indexes += list(range(j + 2, length + 1)) resIndexes = indexes print(maxSum, len(resIndexes)) result = [str(a) for a in resIndexes] print(" ".join(result))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
N = int(input()) def sum_pos(L): n = len(L) ans = L[0] + L[-1] for i in range(1, n - 1): if L[i] > 0: ans += L[i] return ans A = input().split() Removed = [] Positive = [] cost = 0 for i in range(N): A[i] = int(A[i]) k = True for i in range(N): for j in range(N - 1, i, -1): if A[i] == A[j]: costed = sum(A[0:i]) + sum(A[j + 1 :]) if k: cost = costed start = i end = j k = False elif sum_pos(A[start : end + 1]) < sum_pos(A[i : j + 1]): cost = costed start = i end = j k = False x = cost for i in range(start): Removed.append(i + 1) for j in range(N - 1, end, -1): Removed.append(j + 1) for i in range(start + 1, end): if A[i] < 0: Removed.append(i + 1) ans = sum(A) for item in Removed: ans -= A[item - 1] Removed.sort() print(str(ans) + " " + str(len(Removed))) for item in Removed: print(item, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
def main(): n, aa = int(input()), list(map(int, input().split())) partialsum, s, d, ranges = [0] * n, 0, {}, [] for hi, a in enumerate(aa): if a in d: base = s + a * 2 for lo in d[a]: ranges.append((base - partialsum[lo], lo, hi)) d[a].append(hi) else: d[a] = [hi] if a > 0: s += a partialsum[hi] = s s, lo, hi = max(ranges) res = list(range(1, lo + 1)) for i in range(lo + 1, hi): if aa[i] < 0: res.append(i + 1) res.extend(range(hi + 2, n + 1)) print(s, len(res)) print(" ".join(map(str, res))) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST NUMBER VAR NUMBER DICT LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
n = int(input()) v = list(map(int, input().split())) valmax = max(v) + 100 valmin = min(v) - 100 sol = -(10**18) first = {} last = {} s = [(0) for i in range(-2, n + 5)] s[0] = max(v[0], 0) for i in range(1, len(v)): s[i] = s[i - 1] if v[i] > 0: s[i] += v[i] for i in range(0, len(v)): last[str(v[i])] = i if not str(v[i]) in first.keys(): first[str(v[i])] = i left = 0 right = 0 for i in range(0, len(v)): val = v[i] if first[str(val)] == last[str(val)]: continue total = s[last[str(val)]] - s[first[str(val)] - 1] if val < 0: total += 2 * val if total > sol: sol = total left = first[str(val)] right = last[str(val)] cutTrees = [] for i in range(0, left): cutTrees.append(i) for i in range(left + 1, right): if v[i] < 0: cutTrees.append(i) for i in range(right + 1, n): cutTrees.append(i) if n == 2: cutTrees = [] print("%i %i" % (sol, len(cutTrees))) for x in cutTrees: print(x + 1, end=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP STRING VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 5
import sys fin = sys.stdin n = int(fin.readline()) a = list(map(int, fin.readline().split())) table = dict() s = [0] * (n + 1) for i in range(n): rec = table.setdefault(a[i], {"begin": i, "end": i, "sum": a[i]}) rec["end"] = i if a[i] >= 0: s[i + 1] = s[i] + a[i] rec["sum"] = s[rec["end"] + 1] - s[rec["begin"]] else: s[i + 1] += s[i] rec["sum"] = s[rec["end"] + 1] - s[rec["begin"]] + 2 * a[i] ms = max(v["sum"] for v in table.values() if v["begin"] != v["end"]) for mi in table.keys(): if table[mi]["sum"] == ms: break mr = [ (i + 1) for i in range(n) if i < table[mi]["begin"] or i > table[mi]["end"] or table[mi]["begin"] < i < table[mi]["end"] and a[i] < 0 ] print(ms, len(mr)) print(" ".join(map(str, mr)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR DICT STRING STRING STRING VAR VAR VAR VAR ASSIGN VAR STRING VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR STRING BIN_OP VAR BIN_OP VAR STRING NUMBER VAR VAR STRING VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR STRING BIN_OP BIN_OP VAR BIN_OP VAR STRING NUMBER VAR VAR STRING BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR IF VAR VAR STRING VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR STRING VAR VAR VAR STRING VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def solve(): n, k, m = map(int, input().split(" ")) a = [0] + sorted(map(int, input().split(" "))) for _ in range(1, n + 1): a[_] = a[_] + a[_ - 1] ans = 0 for _ in range(min(n, m + 1)): n_, m_ = n - _, m - _ ans = max((a[-1] - a[_] + min(m_, k * n_)) / n_, ans) print("%.9f" % ans) solve()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a = sorted(a)[::-1] su = [0] for i in range(1, n + 1): su.append(su[i - 1] + a[i - 1]) ans = 0.0 for i in range(max(1, n - m), n + 1): ans = max(ans, (su[i] + min(m - (n - i), i * k)) / i) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) t = list(map(int, input().split())) s = sum(t) if n == 1: print("{0:.6f}".format(min(s + k, s + m))) elif k * n <= m: print("{0:.6f}".format(max(t) + k)) else: t.sort() t = [0] + t max_avg = s / n remove = 0 for i in range(min(n, m + 1)): remove += t[i] max_avg = max(max_avg, (s - remove + min(m - i, k * (n - i))) / (n - i)) print("{0:.6f}".format(max_avg))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def read_nums(): return [int(x) for x in input().split()] def count_deletes(nums, m, k): pass def main(): n, k, m = read_nums() nums = sorted(read_nums()) cum_nums = [nums[0]] for i in range(1, len(nums)): cum_nums.append(nums[i] + cum_nums[i - 1]) total_sum = cum_nums[-1] results = [] for del_index in range(min(m + 1, n)): right_sum = total_sum - cum_nums[del_index - 1] if del_index > 0 else total_sum elem_left = n - del_index to_add = min(m - del_index, k * elem_left) cur_res = (right_sum + to_add) / elem_left results.append(cur_res) print(max(results)) main()
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = [int(i) for i in input().split()] a.sort() rs = sum(a) cnt = n for i in range(n): if ( cnt == 1 or (rs + min(m, k * cnt)) / cnt > (rs - a[i] + min(m - 1, k * (cnt - 1))) / (cnt - 1) or m == 0 ): break else: rs -= a[i] cnt -= 1 m -= 1 print((rs + min(m, k * cnt)) / cnt)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) ans, i, j, x = 0, 0, 0, sum(a) length = n while i < n and j <= m: avg = (x + min((k * length, max(0, m - i)))) / length if avg > ans: ans = avg x -= a[i] length -= 1 j += 1 i += 1 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = [int(c) for c in input().split()] a = [int(c) for c in input().split()] a.sort() sm = sum(a) pref = [i for i in range(n + 1)] for i in range(1, n + 1): pref[i] = pref[i - 1] + a[i - 1] avg, mx = 0, -1 for i in range(min(m, n - 1) + 1): sm_of_left = sm - pref[i] avg = (sm_of_left + min(m - i, k * (n - i))) / (n - i) if avg > mx: mx = avg print(mx)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def func(OpCount, n, k, s): if n is 1: return min(OpCount, k) + li[0] Max = (s + min(m, n * k)) / n SumOfM = 0 for i in range(n - 1): if i >= m: break SumOfM = SumOfM + li[i] t = s - SumOfM + min(OpCount - (i + 1), (n - (i + 1)) * k) t = t / (n - (i + 1)) Max = max(t, Max) return Max t = input().split() n, k, m = int(t[0]), int(t[1]), int(t[2]) t = input().split() li = [int(x) for x in t] li.sort() x = func(m, n, k, sum(li)) print(x)
FUNC_DEF IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) aa = [int(i) for i in input().split()] aa.sort() ss = sum(aa) maxi = (ss + min(n * k, m)) / n for i in range(1, min(m + 1, n)): ss -= aa[i - 1] left = m - i can_add = (n - i) * k to_add = min(left, can_add) maxi = max(maxi, (ss + to_add) / (n - i)) print(maxi)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = sum(a) ans = 0 i = 0 while i < n and i <= m: r = n - i ans = max(ans, (s + min(r * k, m - i)) / r) s -= a[i] i += 1 print("%.18f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = list(map(int, input().split())) a = [] a.append(0) for i in arr: a.append(i) a = sorted(a) mm = (sum(arr) + min(m, n * k)) / n ss = sum(arr) for i in range(1, min(n - 1, m) + 1): ss -= a[i] baaki = ss + min(m - i, (n - i) * k) mm = max(mm, baaki / (n - i)) print("%.20f" % mm)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def main(): n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() total_sum = sum(a) ret = (total_sum + min(m, n * k)) / n for i in range(min(n - 1, m)): total_sum -= a[i] temp = total_sum + min(m - i - 1, (n - i - 1) * k) ret = max(ret, temp / (n - i - 1)) print(ret) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = map(int, input().split()) b = sorted(a) sum_b = sum(b) len_b = len(b) res = sum_b / len_b + min(m, len_b * k) / len_b for i in range(min(m, n - 1)): sum_b -= b[i] len_b -= 1 res = max(res, sum_b / len_b + min(m - i - 1, len_b * k) / len_b) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) s = [0] * n s[-1] = a[-1] for i in range(n - 2, -1, -1): s[i] = s[i + 1] + a[i] if len(a) != 1 and m != k and len(set(a)) == 1: print((s[0] + m) / n) elif m >= n: if n != 1: print(float(a[-1] + min(k, m - n + 1))) else: print(float(a[-1] + k)) else: ans = s[0] / n for i in range(k + 1): d = (s[m - i] + i) / (n - m + i) if d > ans: ans = d print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def main(): [n, k, m] = list(map(int, input().split(" "))) ar = list(map(int, input().split(" "))) ar.sort() length = len(ar) prevSum = sum(ar) prev = sum(ar) / length maxAvg = prev while True: toadd = min(length * k, m) newAvg = (prevSum + toadd) / length if newAvg > maxAvg: maxAvg = newAvg popped = ar.pop(0) m -= 1 length -= 1 if length == 0 or m < 0: break prevSum = prevSum - popped print(str.format("{0:.20f}", maxAvg)) return main()
FUNC_DEF ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING VAR RETURN EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N, K, M = map(int, input().split()) L = list(map(int, input().split())) S = sum(L) L = sorted(L) ans = -float("inf") ans = (S + min(M, K * N)) / N for i in range(0, min(M, N - 1)): rM = M - i - 1 rN = N - i - 1 S -= L[i] tmpA = (S + min(rM, rN * K)) / rN ans = max(tmpA, ans) print(ans)
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def main(): n, k, m = map(int, input().split()) a = sorted([int(i) for i in input().split()]) s = sum(a) ans = (min(m, n * k) + s) / n for i in range(1, min(n, m + 1)): s -= a[i - 1] ans = max((s + min(m - i, (n - i) * k)) / (n - i), ans) print(ans) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
from sys import stdin, stdout def inp(): return stdin.readline() def minp(): return map(int, stdin.readline().rstrip().split()) def linp(): return list(minp()) def main(): n, k, m = minp() lst = linp() lst.sort() l = 0 if n * k > m: ss = m else: ss = n * k SUM = sum(lst) d = (SUM + ss) / n ll = [d] for i in range(n - 1): SUM -= lst[i] lst[i] = 0 m -= 1 l += 1 if m > (n - l) * k: ss = (n - l) * k else: ss = m if (SUM + ss) / (n - l) > d: d = (SUM + ss) / (n - l) if m < 1: m = 0 break if m > (n - l) * k: ad = (n - l) * k else: ad = m print(max((SUM + ad) / (n - l), d)) main()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(list(map(int, input().split()))) av = (sum(a) + min(n * k, m)) / n r = 0 l = sum(a) for i in range(min(n - 1, m)): r += a[i] av = max(av, (l - r + min(m - i - 1, (n - i - 1) * k)) / (n - i - 1)) print(av)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
import sys sys.setrecursionlimit(200000) input = sys.stdin.readline n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(key=lambda x: -x) go = sum(a) ans = (go + min(n * k, m)) / n for i in range(n - 1): ke = a.pop() m -= 1 go -= ke if m < 0: break ans = max(ans, (go + min((n - 1 - i) * k, m)) / (n - 1 - i)) print(ans)
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = map(int, input().split()) arr = sorted(arr, reverse=True) sub_s = [0, arr[0]] for e in arr[1:]: sub_s.append(sub_s[-1] + e) M = -1 for i in range(0, min(n - 1, m) + 1): l_s = (sub_s[n - i] + min((n - i) * k, m - i)) / (n - i) M = max(l_s, M) print(M)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) partial = [0] for val in a: partial.append(partial[-1] + val) best = 0.0 for num_remove in range(0, min(n, m + 1)): num_operations = m - num_remove num_remain = n - num_remove num_increase = min(num_operations, num_remain * k) average = (partial[num_remain] + num_increase) / num_remain best = max(best, average) print(best)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() sum = 0 for i in arr: sum = sum + i mx = 0 for i in range(len(arr)): if i > m: break mx = max(mx, (sum + min(m - i, (n - i) * k)) / (n - i)) sum = sum - arr[i] print(mx)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) p = [0] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] + a[i - 1] ans = 0 for i in range(0, min(n - 1, m) + 1): ans = max(ans, (p[n - i] + min(m - i, (n - i) * k)) / (n - i)) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = [int(x) for x in input().split()] k = min(k, m) arr.sort() s = [sum(arr)] for i in range(1, len(arr)): s.append(s[i - 1] - arr[i - 1]) r = [0] * len(s) for i in range(len(s)): f = m - i if f < 0: break r[i] = s[i] + min(k * (n - i), f) r[i] /= n - i print(max(r))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
N, K, M = map(int, input().split()) a = sorted(map(int, input().split())) total = sum(a) ans = (total + min(K * N, M)) / N for n in a: if not M or N == 1: break M -= 1 N -= 1 total -= n ans = max(ans, (total + min(K * N, M)) / N) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = (int(i) for i in input().strip().split()) arr = [int(x) for x in input().split()] arr = sorted(arr) sum = sum(arr) for i in range(n): mid1 = ( 0 if n - i - 1 == 0 else (sum - arr[i] + min(k * (n - i - 1), m - 1)) / (n - i - 1) ) mid2 = (sum + min(k * (n - i), m)) / (n - i) if mid1 > mid2 and m != 0: m -= 1 sum -= arr[i] else: print(mid2) break
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = input().split() n = int(n) k = int(k) m = int(m) a = [int(x) for x in input().split()] a.sort() avg = [] s = sum(a) for i in range(0, n): if i > 0: s = s - a[i - 1] if i > m: break if (m - i) / k <= n - i: avg.append((s + m - i) / (n - i)) else: avg.append((s + (n - i) * k) / (n - i)) print(max(avg))
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = [int(i) for i in input().split()] a = sorted(a) s = sum(a) ans = 0 for i in range(min(n, m + 1)): s += min(k * (n - i), m - i) ans = max(s / (len(a) - i), ans) s -= min(k * (n - i), m - i) s -= a[i] print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = 0 for i in range(n): s += a[i] mx = (s + min(m, k * n)) / n for i in range(min(m, n - 1)): s -= a[i] mx = max(mx, (s + min(m - 1 - i, k * (n - 1 - i))) / (n - i - 1)) print(round(mx, 6))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = sorted(list(map(int, input().split()))) csum = [0] for i in arr: csum.append(csum[-1] + i) def f(i): return (csum[-1] - csum[i] + min(m - i, k * (n - i))) / (n - i) max = 0 for i in range(min(m + 1, n)): if f(i) > max: max = f(i) print(max)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = list(map(int, input().split())) l = list(map(int, input().split())) res = 0 avg = sum(l) / n s = sum(l) l.sort() for i in range(min(n, m + 1)): if i > 0: s -= l[i - 1] left = m - i temp = min(left, k * (n - i)) res = max(res, (s + temp) / (n - i)) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() sum_A = sum(A) avg = sum_A / n i = 0 potential = lambda n, k, m: min(k * n, m) / n avg_subtracted = lambda s, n, a: (s - a) / (n - 1) while ( n > 1 and m > 0 and i < len(A) and avg_subtracted(sum_A, n, A[i]) + potential(n - 1, k, m - 1) >= avg + potential(n, k, m) ): sum_A -= A[i] n -= 1 avg = sum_A / n i += 1 m -= 1 if i < len(A): avg += potential(n, k, m) print(avg)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() res = 0 if m < n: res = (sum(a) + m) / n for i in range(1, m + 1): res = max(res, (sum(a[i:]) + (m - i)) / (n - i)) else: res = a[-1] + min(m - n + 1, k) print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
import sys input = sys.stdin.readline n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = sum(a) ans = (min(k * n, m) + s) / n for i in range(n - 1): if i + 1 > m: break s -= a[i] ans = max(ans, (min(k * (n - i - 1), m - i - 1) + s) / (n - i - 1)) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(map(int, input().split())) s = sum(a) ans = s / n for i in range(min(n, m + 1)): x = s + min((n - i) * k, m - i) ans = max(ans, x / (n - i)) s -= a[i] print("%.17f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) arr = list(map(int, input().split())) arr.sort() s = sum(arr) i = 0 ans = -1 if n == 1: print(arr[0] + min(k, m)) else: elements = n while i < n - 1 and m > 0: avg1 = s + min(elements * k, m) avg1 = avg1 / elements avg2 = s - arr[i] + min((elements - 1) * k, m - 1) avg2 = avg2 / (elements - 1) if avg1 >= avg2: ans = max(avg1, ans) else: ans = max(avg2, ans) s -= arr[i] elements -= 1 m -= 1 i += 1 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) players = list(map(int, input().split())) players.sort() s = sum(players) ans = 0 for i in range(n): if i <= m: gain = min(m - i, k * (n - i)) avg = (s + gain) / (n - i) if avg > ans: ans = avg else: break s -= players[i] print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
R = lambda: map(int, input().split()) n, k, m = R() L = sorted(R(), reverse=True) s = sum(L) s1 = 0 i = n - 1 ma = 0 j = 0 while i >= 0 and j <= m: ma = max(ma, (s + min(m - j, k * (n - j))) / (n - j)) s -= L[i] j += 1 i -= 1 print(ma)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() curn, curs = n, sum(a) ans = (curs + min(k * curn, m)) / curn for i in range(n - 1): if i + 1 > m: break curn -= 1 curs -= a[i] ans = max(ans, (curs + min(k * curn, m - i - 1)) / curn) print("%.8f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def solve(a, n, k, m): a.sort(reverse=True) sm = sum(a) avg = float((sm + min(len(a) * k, m)) / len(a)) while len(a) > 1 and m > 0: m -= 1 sm -= a.pop() avg = max(avg, (sm + min(len(a) * k, m)) / len(a)) return avg n, k, m = map(int, input().split()) a = list(map(int, input().split())) print(solve(a, n, k, m))
FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
def main(): n, k, m = [int(v) for v in input().split()] vals = [int(v) for v in input().split()] vals.sort() data = [vals[0]] for i in range(1, n): data.append(data[i - 1] + vals[i]) max_v = 0 total = data[-1] for i in range(0, min(m + 1, n)): s = total - (data[i - 1] if i > 0 else 0) add_v = min(k * (n - i), m - i) max_v = max(max_v, (s + add_v) / (n - i)) print(max_v) main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = sum(a) ans = (b + min(n * k, m)) / len(a) for i in range(min(n - 1, m)): b = b - a[i] ans = max(ans, (b + min((n - 1 - i) * k, m - 1 - i)) / (n - 1 - i)) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
import sys data = sys.stdin.read().splitlines() n, k, m = map(int, data[0].split()) nums = list(map(int, data[1].split())) nums.sort() s = sum(nums) mx = (s + min(m, k * n)) / n for idx, num in enumerate(nums): if idx == n - 1: break if idx < m: s -= num add = min((n - idx - 1) * k, m - idx - 1) mx = max(mx, (s + add) / (n - idx - 1)) else: break print(mx)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = input().split() k = int(k) m = int(m) n = int(n) niz = [int(n) for n in input().split()] niz.sort() suma = sum(niz) curMax = (suma + min(m, n * k)) / n for i in range(1, min(n - 1, m) + 1): suma -= niz[i - 1] tempMax = (suma + min(m - i, (n - i) * k)) / (n - i) if tempMax > curMax: curMax = tempMax print(curMax)
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = list(map(int, input().split())) l = sorted(list(map(int, input().split()))) tot = 0 prefix = [] ans = 0.0 for i in range(n): tot += l[i] prefix.append(tot) prefix.insert(0, 0) for i in range(n + 1): if m > 0: t = prefix[n] - prefix[i] if i != 0: m -= 1 if m <= (n - i) * k: t += m else: t += (n - i) * k if n - i != 0: t = 1.0 * t / (n - i) if ans < t: ans = t print("%0.20f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(map(int, input().split())) s = sum(a) ans = 0.0 for i in range(n): ans = max(ans, (s + min((n - i) * k, m)) / (n - i)) s -= a[i] if m == 0: break m -= 1 print("%.8f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) power_list = list(map(float, input().split())) power_list.sort() sum_list = [0] for i in range(n): sum_list.append(sum_list[i] + power_list[i]) ans = -1.0 for i in range(min(m + 1, n)): ans = max( ans, float(sum_list[n] - sum_list[i] + float(min(m - i, (n - i) * k))) / float(n - i), ) print("{:.10f}".format(ans))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are $n$ superheroes in avengers team having powers $a_1, a_2, \ldots, a_n$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $1$. They can do at most $m$ operations. Also, on a particular superhero at most $k$ operations can be done. Can you help the avengers team to maximize the average power of their crew? -----Input----- The first line contains three integers $n$, $k$ and $m$ ($1 \le n \le 10^{5}$, $1 \le k \le 10^{5}$, $1 \le m \le 10^{7}$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the initial powers of the superheroes in the cast of avengers. -----Output----- Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$. -----Examples----- Input 2 4 6 4 7 Output 11.00000000000000000000 Input 4 2 6 1 3 2 3 Output 5.00000000000000000000 -----Note----- In the first example, the maximum average is obtained by deleting the first element and increasing the second element four times. In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $2$ each.
n, k, m = map(int, input().split()) a = sorted(map(int, input().split()), reverse=True) best = 0 summation = sum(a) while n > 0 and m >= 0: best = max(best, (summation + min(m, k * n)) / n) summation -= a[-1] n -= 1 m -= 1 a.pop() print(best)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR