code
string
generator
string
label
int64
language
string
python def solve(n, a, b, c, d): """Check if each grain can weigh from a to b and the sum of all weighs from c to d""" possible_weights = range(a-b, a+b+1) total_weight = sum(possible_weights) if total_weight < c - d or c - d > total_weight + b - a: return "No" if n%len(possible_weight...
01-ai/Yi-Coder-1.5B-Chat
1
Python
python def king_moves(position): col = ord(position[0]) - ord('a') + 1 row = int(position[1]) # Total possible moves for a king without considering borders total_moves = 8 # Adjust based on borders: # Left edge if col == 1: total_moves -= 3 # Left side elif col == 2...
microsoft/Phi-3-medium-4k-instruct
1
Python
from math import ceil from math import factorial from collections import Counter from operator import itemgetter ii = lambda : int(input()) iia = lambda : list(map(int, input().split())) isa = lambda : list(input().split()) t = ii() for i in range(t): n = ii() a = iia() d = Counter(a) d = sorted(d.items(), key=item...
human
0
Python
import sys def calculate_beauty_difference(n, flowers): flowers.sort() max_beauty_difference = flowers[-1] - flowers[0] count = 0 for i in range(len(flowers)): for j in range(i + 1, len(flowers)): if flowers[j] - flowers[i] == max_beauty_difference: count += 1 ...
meta-llama/Llama-3.3-70B-Instruct
1
Python
print(solve(n, k)) #Solution def solve(n, k): letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] my_str = "" for d in range(k+1): my_str += letters[d] sub_my_str = [] ans = [] count = 0 i...
google/codegemma-2b
1
Python
import itertools def Runs(a, key=lambda k: k): i = 0 while i < len(a): j = i while j < len(a) and key(a[i]) == key(a[j]): j += 1 if i != j - 1: yield (i, j - 1) i = j def Intersection(x, y): result = [] ai = 0 bi = 0 while ai < len(x) and bi < len(y): a = x[ai] b = y[bi] if a[1] < b[0]: a...
human
0
Python
a = input() b = input() def dfs(sa, sb): if sa == sb: return True if len(sa) & 1: return False n = len(sa) // 2 sa1 = sa[:n] sa2 = sa[n:] sb1 = sb[:n] sb2 = sb[n:] if dfs(sa1, sb2) and dfs(sa2, sb1): return True if dfs(sa1, sb1) and dfs(sa2, sb2): return True return False if dfs(a, b): print('YES') ...
human
0
Python
def games_bought(n, m, c, a): bought_count = 0 wallet_index = 0 for game_cost in c: if wallet_index < m and a[wallet_index] >= game_cost: bought_count += 1 wallet_index += 1 return bought_count # Example usage: if __name__ == "__main__": n, m = map(int, input().spl...
microsoft/Phi-3-medium-4k-instruct
1
Python
word1 = input().split(' ') word2 = input().split(' ') n = int(word1[0]) m = int(word1[1]) arr = [] for i in range(m): arr.append(int(word2[i])) arr.sort() k = arr[n - 1] - arr[0] for i in range(m - n + 1): if arr[i + n - 1] - arr[i] < k: k = arr[i + n - 1] - arr[i] print(k)
human
0
Python
import math def prime_factor(n): ass = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: ass.append(i) n = n // i if n != 1: ass.append(n) return ass (N, M) = map(int, input().split()) L = prime_factor(M) L.append(0) K = [] cur = L[0] cnt = 0 for i in range(len(L)): if cur == L[i]: cnt += 1 ...
human
0
Python
t = 1 # int(input()) for i in range(t): n = int(input()) p = list(map(int, input().split())) p.sort() for i in range(n-2): if p[i] < p[i+1] and p[i+1] > p[i+2]: print("YES") print(str(i+1) + " " + str(i+2) + " " + str(i+3)) break else: print("NO")
google/codegemma-2b
1
Python
import math def solve(x, y, cx, cy): d = y // (x + 1) return ''.join(((d + (i < y % (x + 1))) * cy + cx for i in range(x))) + d * cy def main(n, r, b): res = solve(r, b, 'R', 'B') if r < b else solve(b, r, 'B', 'R') assert len(res) == n, (n, r, b) return res t = int(input()) for _ in range(t): (_n, _r, _b) = ma...
human
0
Python
def solve(n, A): """ Determines whether it is possible to remove all the stones from the boxes. Args: n (int): The number of boxes. A (list): A list of integers representing the number of stones in each box. Returns: str: 'YES' if it is possible to remove all the stones, 'NO' otherwise. ...
meta-llama/Llama-3.3-70B-Instruct
1
Python
import sys t = int(input()) for i in range(t): n = int(input()) a = list(map(int, sys.stdin.readline().strip().split())) x1 = [] x2 = [] x = a[0] mni = 0 for j in range(n): if a[j] < x: x = a[j] mni = j x1.append([x, mni]) x = a[n - 1] mni = n - 1 for j in range(n - 1, -1, -1): if a[j] < x: x =...
human
0
Python
for t in range(int(input())): n = int(input()) a = input().rstrip().replace(' ', '').strip('0') print(a.count('0'))
human
0
Python
s = str(input()) i = 0 ans = 0 t = [] while i < len(s): if int(s[i]) % 3 == 0: ans += 1 t = [] else: t.append(int(s[i]) % 3) if t == [1, 1, 1] or t == [1, 1, 2] or t == [1, 2] or (t == [2, 1]) or (t == [2, 2, 1]) or (t == [2, 2, 2]): t = [] ans += 1 i = i + 1 print(ans)
human
0
Python
import java.util.*; import java.io.*; public class cf1485f { static int mod=(int)1e9+7; public static void main(String[] args) throws IOException{ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); ...
human
0
Java
class Solution: def isAnagram(self, a, b): a_dict = {} for i in a: if i not in a_dict: a_dict[i] = 1 else: a_dict[i] += 1 b_dict = {} for i in b: if i not in b_dict: b_dict[i] = 1 else: b_dict[i] += 1 return a_dict == b_dict
human
0
Python
typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) me...
human
0
C++
(n, k) = list(map(int, input().split())) prime = [True for i in range(n + 2)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 ans = [] for i in range(2, n + 1): if prime[i]: ans.append(i) cnt = 0 for i in range(len(ans)): for j in range(1, i): if ans[j]...
human
0
Python
def is_byte(number): if number < 0 or number > 255: return False else: return True def run(): numbers = list(map(int, input().split())) l = sum_num(numbers[0]) h = sum_num(numbers[1]) s = sum_num(math.ceil(l/3)) count = 1 while s > h: count += 1 s = su...
bigcode/starcoder
1
Python
def f(a1, k): while k-1>0: a1 += int(min(str(a1)))*int(max(str(a1))) if int(min(str(a1))) == 0: break k -= 1 return a1 for _ in range(int(input())): a1, k= map(int, input().split()) print(f(a1, k))
human
0
Python
s = [] for x in range(len(str)): -----Constraints----- - 1 ≤ M ≤ 100 000 - M ≤ K ≤ 100 000 - γ ≤ M ≤ 100 000 - γ ≤ H ≤ 2 62 000 000 - H ≤ N ≤ 10 000 - N ≤ γ ≤ 10 000 1 ≤ i ≤ N. 1 ≤ j ≤ H. -----Input----- M K H i j A_h i j B_h i j C_h i j Salmon Frankfurter(h Groock. ekhtebal m + 1 kalase in abod h ta be ri Ba...
google/codegemma-2b
1
Python
The program is run on Python 3 Sample Input/Output 1: Input: S = "Hello" Output: Svool Sample Input/Output 2: Input: S = "GfG" Output: TuT */ import re def convert(S): string = list(input()) Al=[chr(65+i) for i in range(charset)) converted_string = '' key = 0 input_size = len(input()) ...
meta-llama/Llama-3.2-1B
1
Python
C++ A graph can be depicted as a pair consisting of a set of nodes (vertices) and a set of edges (lines connecting the vertices). In C++, a graph can be represented as an STL vector of vectors. Each pair of i and j (i < j) represents an undirected edge from i to j. Our graph has to contain n nodes (i.e., vertices), an...
deepseek-ai/deepseek-coder-6.7b-instruct
1
Python
. ''' from typing import List def find_least_zeros(matrix: List[List[int]]) -> str: n = len(matrix) dp = [[0] * n for _ in range(n)] # initialize the first row and column for i in range(n): dp[0][i] = dp[i][0] = (matrix[0][i] * matrix[i][0]) % 10 # fill the dp table for i in range(...
microsoft/Phi-3-small-8k-instruct
1
Python
arr = dict() k = int(input()) d = int(input()) cnt = 0 while cnt <= 100: S = sum([int(el) for el in str(cnt)]) dr = S if S >= 10: dr = dr_of_k(arr, S) if dr == d and len(str(cnt)) == k: print(cnt) break else: cnt += 1 if cnt > 100: print("No solution") First, the solution in this problem is based on finding the numbe...
bigcode/starcoder2-7b
1
Python
import math from bisect import bisect_right from collections import Counter from functools import reduce from itertools import accumulate, combinations, compress, count, permutations, product from operator import add, itemgetter MOD = 10**9 + 7 def count_multiples(D, K): count, high, digit, digit_sum = 0,...
microsoft/Phi-3-small-8k-instruct
1
Python
def pick_me(arr): plateau = None for (i, p) in enumerate(arr[1:-1]): if arr[i] < p > arr[i + 2]: yield (i + 1, p) plateau = None if arr[i] < p == arr[i + 2]: plateau = (i + 1, p) if plateau and arr[i] == p > arr[i + 2]: yield plateau plateau = None def pick_peaks(arr): picked = list(zip(*pick_m...
human
0
Python
import os, sys from io import BytesIO, IOBase from collections import defaultdict, deque from copy import deepcopy def longest_path(path, n): st = [1] depth = [[0, 0] for _ in range(n + 1)] ans = 0 while len(st): if not len(path[st[-1]]): x = depth[st.pop()] ans = max(ans, sum(x)) if len(st): y = de...
human
0
Python
def grader(input): if input > 1 or input < 0.6: return 'F' if input >= 0.9: return 'A' elif input >= 0.8: return 'B' elif input >= 0.7: return 'C' elif input >= 0.6: return 'D'
human
0
Python
s = input() n = len(s) for i in range(1, 6): if (n + i - 1) // i <= 20: sim = n // i kol = (i - n % i) % i res = [] j = 0 print(i, (n + i - 1) // i) for j in range(kol): res.append(s[j * sim:j * sim + sim] + '*') j = kol * sim sim = (n + i - 1) // i for j in range(j, n, sim): res.append(s[j:j +...
human
0
Python
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ int n, m; cin >> n >> m; vector<vector<int>> grid(n, vector<int>(m)); for(auto& row: grid){ string s; cin >> s...
Qwen/Qwen2.5-Coder-32B-Instruct
1
C++
import sys n = int(input()) winners = input() count = winners.count('A') winner = '' if count > n / 2: winner = 'Anton' elif count == n / 2: winner = 'Friendship' else: winner = 'Danik' print(winner)
human
0
Python
from math import ceil for _ in range(int(input())): (n, w) = map(int, input().split()) l = list(map(int, input().split())) x = ceil(w / 2) su = 0 for i in l: if i <= w: su += i if min(l) > w or su < x: print(-1) else: (ans, f) = (0, 0) num = [] for i in range(n): if x <= l[i] <= w: f = 1 ...
human
0
Python
def minCoins(self, V, M, coins): dp = [1000001] * V for i in range(M): dp[0] = min( dp[0], dp[i] + 1 ) for j in range(1, coins[i]+1): temp = dp[ j-1 ] if dp[ j -1 ] < V+1 else 10 ** 5 ...
microsoft/phi-2
1
Python
python def advance(n,k,a): count=0 for i in range(k-1,-1,-1): if a[i]>=a[k-1]: count+=1 else: break return n-count if count>=k else 0 n,k = list(map(int,input().split())) a = list(map(int,input().split())) print(advance(n,k,a))
01-ai/Yi-Coder-1.5B-Chat
1
Python
(n, b, d) = map(int, input().split()) l = [int(x) for x in input().split()] count = 0 x = 0 for i in range(n): if l[i] <= b: x = x + l[i] if x > d: x = 0 count += 1 if x > d: count += 1 print(count)
human
0
Python
python class Solution: def alertNames(self, keyName: List[str], keyTime: List[str]) -> List[str]: d = defaultdict(list) for n, t in zip(keyName, keyTime): h, m = map(int, t.strip().split(":")) d[n].append((h, m)) res = set() for n, v in d.items(): ...
Qwen/Qwen2.5-Coder-1.5B-Instruct
1
Python
from math import sqrt def distance(x, y): return sqrt((x[0] - y[0]) * (x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1])) def taxi(init, lst): time = 1000 ** 3 for elem in lst: time = min(time, distance(init, elem) / elem[2]) return '{0:.20f}'.format(time) (a, b) = [int(i) for i in input().split()] n = int(input()) ...
human
0
Python
import sys input = sys.stdin.readline def solve(): n, k = map(int, input().split()) p = [0] + list(map(int, input().split())) adj = [[] for _ in range(n + 1)] for i in range(2, n + 1): adj[p[i - 1]].append(i) def dfs(node, parent): d = 0 for child in adj[node]: ...
codellama/CodeLlama-34b-Instruct-hf
1
Python
def part(arr): l = ['Partridge', 'PearTree', 'Chat', 'Dan', 'Toblerone', 'Lynn', 'AlphaPapa', 'Nomad'] s = len([i for i in arr if i in l]) return "Mine's a Pint" + '!' * s if s > 0 else "Lynn, I've pierced my foot on a spike!!"
human
0
Python
python class Solution: def longestContinuousSubstring(self, s: str) -> int: prevCharIdx = 0 maxN = 0 n = len(s) for i in range(1,n): prevChar = ord(s[prevCharIdx]) thisChar = ord(s[i]) if (prevChar+1) != thisChar: maxN = max(maxN,i-...
deepseek-ai/deepseek-coder-6.7b-base
1
Python
(X, Soldiers) = (list(map(int, input().split())), []) for i in range(X[1] + 1): Soldiers.append(int(input())) print(sum([bin(Soldiers[i] ^ Soldiers[-1]).count('1') <= X[2] for i in range(X[1])]))
human
0
Python
a = input() b = a[0] c = b.upper() x = a.replace(b, '', 1) d = c + x print(d)
human
0
Python
. In the second example all substrings $s[1\ldotsn]$ are possible, but only those辗转 equal substrings are correct ones: $s[1\ldots2]$, $s[2\ldots4]$, $s[3\ldots5]$, $s[1\ldots6]$, $s[3\ldots8]$, $s[1\ldots9]$, $s[3\ldots10]$, $s[1\ldots11]$, $s[3\ldots12]$. Next code is prohibited: $s[1\ldots1]$, $s[2\ldots2]$, $s[3\ldo...
01-ai/Yi-Coder-1.5B
1
Python
class Solution: def skipMdeleteN(self, head, M, N): cn = 1 curr = head while curr: if cn == M: k = 0 curr1 = curr while curr1 and k <= N: curr1 = curr1.next k += 1 cn = 0 curr.next = curr1 curr = curr.next cn += 1 return head
human
0
Python
python import sys def solve(n, a): for i in range(n): if i > 0 and a[i] <= a[i-1]: diff = a[i-1] - a[i] + 1 a[i] += diff print("1", i+1, diff) if a[0] == 0: print("1", 1, 1) a[0] = 1 for i in range(n): if i > 0 and a[i] <= a[i-1]: ...
deepseek-ai/deepseek-coder-6.7b-instruct
1
Python
import java.io.*; import java.util.*; public class Education { public static void main(String[] args) { Kattio io = new Kattio(); int t = io.nextInt(); while (t --> 0) { int n = io.nextInt(); int c = io.nextInt(); int[] income = new int[n]; for (int i = 0;i < n;i++) { inco...
human
0
Java
python def numSubmat(mat): m, n = len(mat), len(mat[0]) dp = [[0]*n for _ in range(m)] res = 0 for i in range(m): for j in range(n): if mat[i][j]: width = dp[i][j] = dp[i][j-1] + 1 if j else 1 for k in range(i, -1, -1): width = min...
01-ai/Yi-Coder-1.5B-Chat
1
Python
(n, m) = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() ls = [] ls.extend(lst) i = 0 j = 0 a = 0 while i < n: if lst[j] == 0: j += 1 z = lst[j] a += z lst[j] = z - 1 i += 1 i = 0 b = 0 while i < n: x = max(ls) y = ls.index(x) ls[y] = x - 1 b += x i += 1 print(b, a)
human
0
Python
import io, os, sys a = os.read(0, os.fstat(0).st_size) inp = [] i = 0 numb = 0 try: while True: if a[i] >= b'0'[0]: numb = 10 * numb + a[i] - 48 elif a[i] != b'\r'[0]: inp.append(numb) numb = 0 i += 1 except: pass if a and a[-1] >= b'0'[0]: inp.append(numb) ii = 0 def merge(a, b): s = [] ma = a[0] ...
human
0
Python
(n, *x) = [int(input()) for _ in range(6)] print(-(-n // min(x)) + 4)
human
0
Python
for t in range(test): n = int(input()) adj = [[] for i in range(n+1)] for i in range(n-1): u, v, b = map(int, input().split()) adj[u].append((v, b)) adj[v].append((u, b)) a = list(map(int, input().split())) ans = 0 for i in range(1, n+1): if a[i-1] < min(a[j-1] fo...
ibm-granite/granite-8b-code-base-4k
1
Python
#include <bits/stdc++.h> using namespace std;using ll=long long;using vi=vector<int>;using pii=pair<int,int>; int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,1,-1,-1,1},inf=1061109567,mod=1000000007; int bits(ll s){return __builtin_popcount((s));}int bit(ll s,int i){return s>>i&1;} template<typename T> void mxm(T& a,T b){...
human
0
C++
python class Solution: def lenLongestFibSubseq(self, A: List[int]) -> int: n = len(A) A = set(A) max_len = 2 seen = {0: 0, 1: 1} for i in range(n): for j in range(i+1, n): a, b = A[i], A[j] k = 2 while a + b in A: ...
meta-llama/Llama-3.1-8B-Instruct
1
Python
e = list(a) n1 = int(n[:-1]) n2 = int(n[-1]) ok = 0 for i in range(10): a = int(str(i) + str(n1)) b = int(str(i) + str(n2)) if ((a > 0) and (a <= 99) and (b > 0) and (b <= 99)): ok = ok + 1 for i in range(1, 10): a = int(str(i) + str(n1)) b = int(str(i) + str(n2)) if ((a > 0) and (a <= 99) and (b > 0) and (b <= 99)): o...
meta-llama/Llama-3.2-3B
1
Python
input = stdin.readline def writeliner(string: str): stdout.write(string + '\n') def writeint(n: int): str_n = str(n) stdout.write(str_n + '\n') def writeints(ints: list): ints = list(map(lambda x: str(x) , ints)) string_ints = ' '.join(ints) writeliner(string_ints) de...
google/codegemma-7b
1
Python
for i in range(int(input())): (a, b, c) = sorted([int(j) for j in input().split()]) s = min(c - b, a) (c, a) = (c - s, a - s) if a == 0: s += min(c, b) else: s += a // 2 * 2 s += min(b, c) - a // 2 print(s)
human
0
Python
a single character. Because sum(A) of 2 3 = 2 + 3 = 5. / *Use gcd() to calculate number of greatest common divisor.*/ /*If sum of any two elements of the list is greater than greater than gcd。” MODULAR PROBLEM SOLVED by A INPUT Testing Case OUTPUT Test Case 1 Example: Test Case 1 Format x space y SIZE Constrain...
meta-llama/Llama-3.2-1B
1
Python
cases = int(input()) for case in range(cases): knights = int(input()) attacked_squares = [] king_sqaures = [] for line in range(knights): (x, y) = map(int, input().split()) attacked_squares.extend([[x + 2, y - 1], [x + 2, y + 1], [x - 2, y - 1], [x - 2, y + 1], [x - 1, y - 2], [x + 1, y - 2], [x - 1, y + 2], [x...
human
0
Python
def minus_two(N): if N < 0: N = -N return str(1) + bin(N)[2:] return bin(N)[2:] print(minus_two(N))
bigcode/starcoder2-15b
1
Python
python from fractions import Fraction def solve(N): total = Fraction(N, 1) for i in range(1, N): total += Fraction(N - i, 2 ** i) return total def inverse(a, mod): return pow(a, mod - 2, mod) def main(): import sys input = sys.stdin.read data = input().split() T = int(dat...
Qwen/Qwen2.5-Coder-7B-Instruct
1
Python
n = int(input()) for _ in range(n): (n, k1, k2) = map(int, input().split()) p1Max = max(map(int, input().split())) p2Max = max(map(int, input().split())) if p1Max > p2Max: print('YES') else: print('NO')
human
0
Python
if you want to test Code expected Input 6 1 5 2 0 1 2 4 5 6 8 1 4 6 Code expected Input Help wanted I understand the problem as follows: Given a list of $n$ positions, the task is to find the greatest distance between two numbers $a, b$ on that list that can be achieved by swapping adjacent positions at most $x$ times....
Qwen/Qwen2.5-Coder-1.5B
1
Python
array = list(map(int, input().split())) def f(x, y): return (x | y) - y ans = [] def helper(k, arr): if k == len(arr) - 1: ans.append(arr.pop(k)) return arr, ans for i in range(len(arr)): arr.insert(k, arr.pop(i)) arr, res = helper(k+1, arr) arr.pop(i) return ar...
microsoft/phi-2
1
Python
def delNode(head, k): if k == 1: head = head.next else: temp = head count = 2 while temp != None and count < k: temp = temp.next count += 1 temp.next = temp.next.next return head
human
0
Python
m = returnSizeOfFirstLine n = returnSizeOfSecondLine k = returnSizeOfThirdLine d = SizeOfColumn sizeOfRead = len(str(map(input().split()))) matrix = zeros(sizeOfRead, (m, n, k)) for i in rnge(sizeOfRead) : line = map(str, input().split()) for j in rnge(sizeOfRead) : matrix[i, j, :] = i*j # Save number/ string...
google/codegemma-2b
1
Python
n = int(input()) l = list(map(int, input().split())) l.sort() ans = [] if n % 2 == 0: p = (n - 1) // 2 else: p = n // 2 a1 = l[:p] a2 = l[p:] i = 0 (j, k) = (0, 0) while j < len(a1) and k < len(a2): if i % 2 == 0: ans += [a2[k]] k += 1 else: ans += [a1[j]] j += 1 i += 1 if k < len(a2): ans += a2[k:] print...
human
0
Python
i = 1 n = int(input()) line = '' while i <= n: l = str(i) line = line + l i = i + 1 line = list(line) print(line[n - 1])
human
0
Python
n = int(input()) ok = False a = list(map(int, str(input()).split())) try: a.index(1) print(-1) except: print(1)
human
0
Python
# class TreeNode(object): # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution(object): def smallestFromLeaf(self, root): """ :type root: TreeNode :rtype: str """ /Leetcode/DP A...
bigcode/starcoder2-3b
1
Python
being compared against nasm & asm_cluster Primery keyed on [Task 40](https://i.stack.imgur.com/BR9Cj.png) error is fixed with previous change. def min_modifications(A, K): N = len(A) dp = [0] * (N - K + 1) for i in range(N - K + 1): dp[i] = sum(A[i:i+K]) count = 0 for i in range(N...
Qwen/Qwen2.5-Coder-1.5B
1
Python
class Solution: def decodeIt(self, Str, k): new_string = '' for i in Str: if i.isnumeric(): new_string = new_string * int(i) else: new_string += i if len(new_string) < k: return -1 return new_string[k - 1]
human
0
Python
class Solution { public int countDistinctIntegers(int[] nums) { HashSet <Integer> set = new HashSet(); for(int i : nums) { set.add(i); set.add(f(i)); } return set.size(); } int f(int x) { int res = 0; while(x != 0) { res *=...
human
0
Java
class Solution: def toh(self, n, from_rod, to_rod, aux_rod): if n == 0: return 0 k = self.toh(n - 1, from_rod, aux_rod, to_rod) print('move disk', n, 'from rod', from_rod, 'to rod', to_rod) p = self.toh(n - 1, aux_rod, to_rod, from_rod) return 1 + k + p
human
0
Python
To solve this problem, we need to determine if we can partition the graph such that every edge connects nodes in successive groups. If it is possible, we return the maximum number of such groups; otherwise, we return `-1`. Here's a step-by-step approach to solving the problem: 1. **Graph Representation**: Represent t...
microsoft/Phi-3-medium-4k-instruct
1
Java
for _ in range(int(input())): (N, A, B) = map(int, input().split()) (C, rounds) = (1, 0) while C < N: C = C * 2 rounds += 1 print(rounds * A + (rounds - 1) * B)
human
0
Python
myLis = [] lis = list(map(int, input().split())) lis.sort() p = lis.pop() for i in lis: myLis.append(p - i) print(*myLis)
human
0
Python
import sys s = input().strip() word_count = 0 for c in s: if c.isupper(): word_count += 1 word_count += 1 print(word_count)
human
0
Python
(n, s) = map(int, input().split()) a = list(map(int, input().split())) def find(k): b = [(i + 1) * k + a[i] for i in range(n)] b = sorted(b) return sum(b[:k]) (l, r) = (0, n) ans = 0 while l < r: md = (l + r + 1) // 2 ans = find(md) if ans <= s: l = md else: r = md - 1 print(l, find(l))
human
0
Python
n = int(input()) s = str(input()) a_cnt = 0 d_cnt = 0 for char in s: if char == 'A': a_cnt += 1 else: d_cnt += 1 if a_cnt > d_cnt: print('Anton') elif a_cnt == d_cnt: print('Friendship') else: print('Danik')
human
0
Python
, no extra print statement. #(python) def maxPrice(): A = list(map(int, input().split(' '))) M = int(input()) sortedA = sorted(A, reverse=True) return sum(sortedA[:M]) Explanation: Input format: N , M , A[ ], size N ,M , A[ ]. Limits Input: 1 ≤ N ≤ 10^5; 1 ≤ M ≤ 10^5, -10^6 ≤ A[i] ≤ 10^6. Outp...
microsoft/Phi-3-mini-4k-instruct
1
Python
#include <bits/stdc++.h> using namespace std; template <typename Fun> struct y_combinator { const Fun fun; explicit y_combinator(const Fun&& fun) : fun(std::forward<const Fun>(fun)) {} template <typename... Args> auto operator()(Args&&... args) const { return fun(std::ref(*this),...
human
0
C++
. Write above comment if going for explanation. def calc_min_capacity(n, stops): min_capacity = 0 current_capacity = 0 for i in range(n): current_capacity = current_capacity - stops[i][0] + stops[i][1] if current_capacity > min_capacity: min_capacity = current_capacity retu...
deepseek-ai/deepseek-coder-6.7b-instruct
1
Python
import java.io.*; import java.util.*; public class Main { static long MOD = 998244353; static class Edge { long to; long w; public Edge(long to, long w) { this.to = to; this.w = w; } } static class Pair { long first; long secon...
codellama/CodeLlama-34b-Instruct-hf
1
Java
using namespace std; int main() { int t; cin >> t; while (t--) { int p, q; cin >> p >> q; int x = p / q; if (x * q == p) { cout << x << endl; } else { cout << x + 1 << endl; } } return 0;
google/codegemma-2b
1
C++
python def maxHappiness(happiness, k): prefix_sums = [0] * (len(happiness) + 1) for i in range(len(happiness)): prefix_sums[i+1] = prefix_sums[i] + happiness[i] children = [(happiness[i], i) for i in range(len(happiness))] children.sort(reverse=True) dp = [0] * (k + 1) for i in range(1...
01-ai/Yi-Coder-1.5B-Chat
1
Java
, no extra text or explanation needed. solution: import sys def can_flow(pipes): directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] visited = [[False] * len(pipes[0]) for _ in range(2)] def dfs(i, j, di, dj): if 0 <= i < len(pipes) and 0 <= j < len(pipes[0]) and not visited[i][j]: visite...
microsoft/Phi-3-small-8k-instruct
1
Python
python def max_beauty(n, k, s): max_len = max(s.count('a'), s.count('b')) # Find the longest alternating sequence of 'a' and 'b' for i in range(n): if i > 0 and s[i] != s[i-1]: # If there needs to be a change, calculate the length of the longest alternating sequence alt ...
Qwen/Qwen2.5-Coder-1.5B-Instruct
1
Python
(h, w) = map(int, input().split()) mp = [] for _ in range(h): lst = list(map(int, input().split())) cum = [] acc = 0 for i in lst: if i == 0: acc += 1 else: acc = 0 cum.append(acc) mp.append(cum) mp.append([-1] * w) ans = 0 for x in range(w): score_stack = [] ind_stack = [] for y in range(h + 1): ...
human
0
Python
from operator import itemgetter N = int(input()) A = list(map(int, input().split())) i = max(enumerate(map(abs, A)), key=itemgetter(1))[0] print(2 * N) if A[i] < 0: print(i + 1, N) print(i + 1, N) for j in range(N, 1, -1): print(j, j - 1) print(j, j - 1) else: print(i + 1, 1) print(i + 1, 1) for j in range(1,...
human
0
Python
for x in range(int(input())): (n, x, a, b) = list(map(int, input().split())) (a, b) = (max(a, b), min(a, b)) c = a a += min(n - a, x) x -= min(x, n - c) if x > 0: d = b b -= min(b - 1, x) x -= min(x, d - 1) print(a - b)
human
0
Python
import functools class Solution: def largestSumOfAverages(self, A: List[int], K: int) -> float: @functools.lru_cache(None) def dp(start, p): if p == 1: return sum(A[start:]) / (len(A) - start) if start == len(A): return 0 curr_sum = A[start] ret = 0 for i in range(start + 1, len(A)): ...
human
0
Python
n = int(input()) a = [] k = 0 while k < n: s = input() a.append([int(i) for i in s.split()]) k += 1 m = 0 d = [] for i in range(n): m = 0 for j in range(n): if a[i][j] == 1 or a[i][j] == 3: m += 1 if m == 0: d.append(i + 1) d.sort() print(len(d)) for i in range(0, len(d)): print(d[i], end=' ')
human
0
Python
for _ in range(t): # take this range into list a = int(input()) # int taking not int = '45sasaasaasa7',this number contains chr but using,type lstt = list(input().raiter()).map(int , aplit()) lsttpri = [] # first taking this list for i i if type1 = int (input()[print('he...
bigcode/starcoder2-15b
1
Python
python from copy import deepcopy def partition_value(p, k): n, max_value = len(p), 0 for i in range(n-k+1): current_val = max(p[j] for j in range(i, i+k)) if current_val > max_value: max_value = current_val return max_value def count_partitions_with_max_value(p, k, max_value): ...
Qwen/Qwen2.5-Coder-1.5B-Instruct
1
Python
n = int(input()) al = [0] * n ansl = [0] * n ml = list(map(int, input().split())) mx = 0 for i in range(n): al[i] = ml[i] j = i - 1 while j >= 0: al[j] = min(al[j + 1], ml[j]) j = j - 1 j = i + 1 while j < n: al[j] = min(al[j - 1], ml[j]) j = j + 1 cans = 0 j = 0 for j in range(n): cans += al[j] if c...
human
0
Python
. a,b = raw_input() ,raw_input();print "". join(["1"if a[i] != b[i] else "0"] for i in map(ord,b)) print "".join(["1"if int(a[i]) != int(b[i])+ 2 else str(0) for i in range(min(map(len,(a,b))) ) ]); print "".join(map(lambda x:x-1 ,list(int(y) for y in bin( int("0" .join([["1" i...
meta-llama/Llama-3.1-8B-Instruct
1
Python
def dist(a, b): return abs(a[0] - b[0]) + abs(a[1] - b[1]) n = int(input()) p = [] for i in range(n): p.append(list(map(int, input().split()))) c = list(map(int, input().split())) k = list(map(int, input().split())) st = [] ed = [] ans = 0 is_st = [1] * n parent = [-1] * n d = {i: c[i] for i in range(n)} for i in ran...
human
0
Python