benjamintli/modernbert-code-v4-hard-negatives
Sentence Similarity • 0.1B • Updated • 126
query large_stringlengths 4 15k | positive large_stringlengths 5 373k | source large_stringclasses 7
values | hard_negatives listlengths 1 6 |
|---|---|---|---|
A valid parentheses sequence is a non-empty string where each character is either '(' or ')', which satisfies the following constraint:
You can find a way to repeat erasing adjacent pairs of parentheses '()' until it becomes empty.
For example, '(())' and '()((()()))' are valid parentheses sequences, but ')()(' and... | try:
for i in range(int(input())):
s=input()
balance=0
max_balance=0
for i in s:
if i=='(':balance+=1
else:
balance-=1
max_balance=max(max_balance,balance)
print('('*max_balance,')'*max_balance,sep="")
except Exception as e:... | apps | [
"t=int(input())\n\nfor tt in range(t):\n a,b,p=map(int,input().split())\n s=input()\n n=len(s)\n cost = [0]*n\n cost[-1] = 0\n typ = ''\n i=n-2\n while i>=0:\n if s[i]==typ:\n cost[i] = cost[i+1]\n else:\n typ = s[i]\n cost[i] = cost[i+1] + (a i... |
Chef has a cubic die with 6 faces kept on an infinite plane. Each face has a distinct integer in the range [1,6] written on it, but the exact arrangement of the numbers on the faces of the die is unknown to Chef. Curiosity gets the better of Chef and he wants to find out o(1), o(2), ..., o(6), where o(i) is the number... | from itertools import permutations
def solve(n,a):
ans=[]
for des in desire:
check=1
for i in range(n-1):
if (a[i]==a[i+1]):
return [-1]
if a[i+1]==des[a[i]-1]:
check=0
break
if check:
ans=des
break
if ans:
return ans
return [-1]
per=permutations([1,2,3,4,5,6])
desire=[]
... | apps | [
"def solve():\n n = int(input())\n lst = list(map(int,input().split()))\n if sum(lst) <= n // 2:\n print(n//2)\n print(\"0 \" * (n // 2))\n else:\n print(n//2 + (n // 2) % 2)\n print(\"1 \" * (n//2 + (n // 2) % 2))\nfor i in range(int(input())):\n solve()",
"import sys\n... |
DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers.
You are given the information of DevuLand
by an array D of size n. If D[i] is non-negative, it means that there are D[i] villagers in that village.
Otherwise, it mean... | # cook your dish here
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
curr = 0
ans = 0
for x in a:
curr += x
ans += abs(curr)
print(ans) | apps | [
"from collections import deque \r\nT=int(input())\r\ndef break_down(num):\r\n count=0\r\n while(len(num)!=1):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=str(temp)\r\n count=count+1\r\n return (int(num),count)\r\ndef digit_sum(num):\r\... |
The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture:
Let's consider a walk W in graph G, which consists of L vertices W1, W2, ..., WL, such that Wi is connected with Wi + 1 f... | let_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]}
num_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E',
5:'A', 6:'B', 7:'C', 8:'D', 9:'E'}
connections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8),
6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)}
T = int(in... | apps | [
"T = int(input())\nfor _ in range(T):\n W = list(map(int, input().strip().split()))\n S = W[0]\n W = W[1:]\n W = W[::-1]\n i = 0\n c = 0\n flag = 0\n while (len(W) != 0 or flag != 1) and i<len(W):\n k = i\n su = 0\n while su <= S and k<len(W)-1:\n su += W[k]\n k += 1\n if su-W[k-1]<=S:\n c += 1\n else:\n... |
Three numbers A, B and C are the inputs. Write a program to find second largest among them.
-----Input-----
The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C.
-----Output-----
For each test case, display the second largest among A... | # cook your dish here
x=int(input())
for i in range(x):
s=list(map(int,input().split()))
s.sort()
print(s[1])
| apps | [
"\nT = int(input())\n\nfor _ in range(T):\n a, b = list(map(int, input().split()))\n print(max(max(a, b), min(a, b) * 2)**2)\n",
"T = int(input())\nfor t in range(T):\n a, b, n = [int(i) for i in input().split()]\n if n%3 == 2:\n print(a^b)\n elif n%3 == 1:\n print(b)\n else:\n ... |
import readline
while True:
try:
print(input('> '))
except:
break
| #include <iostream>
#include <string>
#include <vector>
std::vector<std::string> hist;
std::ostream& operator<<(std::ostream& os, const std::string& str) {
return os << str.c_str();
}
void appendHistory(const std::string& name) {
hist.push_back(name);
}
void hello() {
std::cout << "Hello World!\n";
... | codetrans_contest | [
"#include <iostream>\n#include <vector>\n\nint main()\n{\n \n int numberOfLines;\n std::cin >> numberOfLines;\n std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\\n'); \n \n \n std::vector<std::string> lines(numberOfLines); \n for(int i = 0; i < numberOfLines; ++i)\n {\n ... |
STEP = 100
count = 0
def setup():
global x, y, direction
size(100, 100, P2D)
background(255)
x = width / 2
y = height / 2
direction = 0
def draw():
global count
for i in range(STEP):
count += 1
pix = get(x, y) != -1
setBool(x, y, pix)
... | #include <windows.h>
#include <string>
using namespace std;
const int BMP_SIZE = 600, CELL_SIZE = 4, GRID_SIZE = BMP_SIZE / CELL_SIZE;
const bool INFINIT_RUN = false;
enum cellState { WHITE, BLACK, ANT };
enum facing { NOR, EAS, SOU, WES };
enum state { RUNNING, RESTING };
class myBitmap
{
public:
myBitmap()... | codetrans_contest | [
"#include <windows.h>\n#include <list>\n#include <iostream>\n\n\nusing namespace std;\n\n\nclass point\n{\npublic:\n int x, y;\n point() { x = y = 0; }\n point( int a, int b ) { x = a; y = b; }\n void set( int a, int b ) { x = a; y = b; }\n};\n\nclass rndCircle\n{\npublic:\n void ... |
நிரல்பாகம் எண்_கூட்டல்( எண் )
தொகை = 0
@( எண் > 0 ) வரை
d = எண்%10;
பதிப்பி "digit = ",d
எண் = (எண்-d)/10;
தொகை = தொகை + d
முடி
பின்கொடு தொகை
முடி
பதிப்பி எண்_கூட்டல்( 1289)
பதிப்பி எண்_கூட்டல்( 123456789)
| #include <iostream>
#include <cmath>
int SumDigits(const unsigned long long int digits, const int BASE = 10) {
int sum = 0;
unsigned long long int x = digits;
for (int i = log(digits)/log(BASE); i>0; i--){
const double z = std::pow(BASE,i);
const unsigned long long int t = x/z;
sum += t;
x ... | codetrans_contest | [
"#include <algorithm>\n#include <iostream>\n#include <numeric>\n#include <sstream>\n#include <vector>\n\nstd::vector<int> divisors(int n) {\n std::vector<int> divs{ 1 };\n std::vector<int> divs2;\n\n for (int i = 2; i*i <= n; i++) {\n if (n%i == 0) {\n int j = n / i;\n divs.pus... |
def CastOut(Base=10, Start=1, End=999999):
ran = [y for y in range(Base-1) if y%(Base-1) == (y*y)%(Base-1)]
x,y = divmod(Start, Base-1)
while True:
for n in ran:
k = (Base-1)*x + n
if k < Start:
continue
if k > End:
return
yield k
x += 1
for V in CastOut(Base=1... |
#include <iostream>
int main() {
int Base = 10;
const int N = 2;
int c1 = 0;
int c2 = 0;
for (int k=1; k<pow((double)Base,N); k++){
c1++;
if (k%(Base-1) == (k*k)%(Base-1)){
c2++;
std::cout << k << " ";
}
}
std::cout << "\nTrying " << c2 << " numbers instead of " << c1 << " numbers saves " << 100 ... | codetrans_contest | [
"#include <cmath>\n#include <iostream>\n\ndouble vdc(int n, double base = 2)\n{\n double vdc = 0, denom = 1;\n while (n)\n {\n vdc += fmod(n, base) / (denom *= base);\n n /= base; \n }\n return vdc;\n}\n\nint main() \n{\n for (double base = 2; base < 6; ++base)\n {\n std::c... |
def isLongAlternator(s):
def p(a, b):
return isVowel(a) != isVowel(b)
return 9 < len(s) and all(map(p, s, s[1:]))
def isVowel(c):
return c in 'aeiou'
def main():
matches = [
x for x in readFile('unixdict.txt').splitlines()
if isLongAlternator(x)
]
... | #include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
bool is_vowel(char ch) {
switch (ch) {
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return true;
}
return false;
}
bool alternat... | codetrans_contest | [
"#include <fstream>\n#include <iostream>\n#include <set>\n#include <string>\n\nint main() {\n std::ifstream input(\"unixdict.txt\");\n if (input) {\n std::set<std::string> words; \n std::string word; \n size_t count = 0; \n\n while (input >> word) {\n std::string drow(wo... |
def isStrange(n):
def test(a, b):
return abs(a - b) in [2, 3, 5, 7]
xs = digits(n)
return all(map(test, xs, xs[1:]))
def main():
xs = [
n for n in range(100, 1 + 500)
if isStrange(n)
]
print('\nStrange numbers in range [100..500]\n')
print('(Total:... | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> digits(int n) {
std::vector<int> result;
while (n > 0) {
auto rem = n % 10;
result.push_back(rem);
n /= 10;
}
std::reverse(result.begin(), result.end());
return result;
}
bool is_strange(int n) {
... | codetrans_contest | [
"#include <iostream>\n#include <sstream>\n#include <vector>\n\nuint64_t ipow(uint64_t base, uint64_t exp) {\n uint64_t result = 1;\n while (exp) {\n if (exp & 1) {\n result *= base;\n }\n exp >>= 1;\n base *= base;\n }\n return result;\n}\n\nint main() {\n using... |
def main():
lalpha = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"
ralpha = "PTLNBQDEOYSFAVZKGJRIHWXUMC"
msg = "WELLDONEISBETTERTHANWELLSAID"
print("L:", lalpha)
print("R:", ralpha)
print("I:", msg)
print("O:", do_chao(msg, lalpha, ralpha, 1, 0), "\n")
do_chao(msg, lalpha, ralpha, 1, 1)
d... | #include <iostream>
enum class Mode {
ENCRYPT,
DECRYPT,
};
const std::string L_ALPHABET = "HXUCZVAMDSLKPEFJRIGTWOBNYQ";
const std::string R_ALPHABET = "PTLNBQDEOYSFAVZKGJRIHWXUMC";
std::string exec(std::string text, Mode mode, bool showSteps = false) {
auto left = L_ALPHABET;
auto right = R_ALPHABET;... | codetrans_contest | [
"#include <iostream>\n#include <string>\n#include <map>\n#include <algorithm> \nusing namespace std;\n\nclass StraddlingCheckerboard\n{\n map<char, string> table;\n char first[10], second[10], third[10];\n int rowU, rowV;\n\npublic:\n StraddlingCheckerboard(const string &alphabet, int u, int v)\n {\n rowU =... |
def twoDiagonalMatrix(n):
return matrix(
n, n, lambda row, col: int(
row in (col, 1 + (n - col))
)
)
def main():
for n in [7, 8]:
print(
showMatrix(
twoDiagonalMatrix(n)
) + '\n'
)
def matrix(nRows, nC... | #include <concepts>
#include <iostream>
void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
for(int y = 0; y < size; y++)
{
for(int x = 0; x < size; x++)
{
std::cout << " " << f(x, y, size);
}
std::cout << "\n";
}
std::cout << "\n";
}
int main()
{
auto diagonals = [... | codetrans_contest | [
"#include <cassert>\n#include <iomanip>\n#include <iostream>\n#include <vector>\n\ntemplate <typename scalar_type> class matrix {\npublic:\n matrix(size_t rows, size_t columns)\n : rows_(rows), columns_(columns), elements_(rows * columns) {}\n matrix(size_t rows, size_t columns,\n const std::ini... |
from random import randint
playercount = 2
maxscore = 100
safescore = [0] * playercount
player = 0
score=0
while max(safescore) < maxscore:
rolling = input("Player %i: (%i, %i) Rolling? (Y) "
% (player, safescore[player], score)).strip().lower() in {'yes', 'y', ''}
if rolling:
... | #include <windows.h>
#include <iostream>
#include <string>
using namespace std;
const int PLAYERS = 2, MAX_POINTS = 100;
class player
{
public:
player() { reset(); }
void reset()
{
name = "";
current_score = round_score = 0;
}
string getName() { return name; }
void setName( s... | codetrans_contest | [
"#include <iostream>\n#include <map>\n#include <random>\n\nstd::default_random_engine generator;\nstd::uniform_int_distribution<int> dice(1, 6);\nint rollDice() {\n return dice(generator);\n}\n\nconst bool sixesThrowAgain = true;\nconst std::map<int, int> snl{\n {4, 14},\n {9, 31},\n {17, 7},\n {20, ... |
import inflect
import time
before = time.perf_counter()
p = inflect.engine()
print(' ')
print('eban numbers up to and including 1000:')
print(' ')
count = 0
for i in range(1,1001):
if not 'e' in p.number_to_words(i):
print(str(i)+' ',end='')
count += 1
print(' ')
print(' ')
print... | #include <iostream>
struct Interval {
int start, end;
bool print;
};
int main() {
Interval intervals[] = {
{2, 1000, true},
{1000, 4000, true},
{2, 10000, false},
{2, 100000, false},
{2, 1000000, false},
{2, 10000000, false},
{2, 100000000, false},
... | codetrans_contest | [
"#include <iostream>\n#include <iomanip>\nusing namespace std;\n\nvoid getPrimeFactors( int li )\n{\n int f = 2; string res;\n if ( li == 1 ) res = \"1\";\n else\n {\n\twhile ( true )\n\t{\n\t if( !( li % f ) ) \n\t {\n\t\tres += to_string(f);\n\t\tli /= f; if( li == 1 ) break;\n\t\tres += \" x \"... |
import sys
from socket import inet_aton, inet_ntoa
from struct import pack, unpack
args = sys.argv[1:]
if len(args) == 0:
args = sys.stdin.readlines()
for cidr in args:
dotted, size_str = cidr.split('/')
size = int(size_str)
numeric = unpack('!I', inet_aton(dotted))[0]
binary = f'{numeric:
... | #include <cstdint>
#include <iomanip>
#include <iostream>
#include <sstream>
class ipv4_cidr {
public:
ipv4_cidr() {}
ipv4_cidr(std::uint32_t address, unsigned int mask_length)
: address_(address), mask_length_(mask_length) {}
std::uint32_t address() const {
return address_;
}
unsi... | codetrans_contest | [
"#include <iostream>\n#include <iomanip>\n\nint main()\n{\n for (int i = 0; i <= 33; i++)\n std::cout << std::setw(6) << std::dec << i << \" \"\n << std::setw(6) << std::hex << i << \" \"\n << std::setw(6) << std::oct << i << std::endl;\n\n return 0;\n}\n",
"#include<iostream>\nusin... |
passwd_list=[
dict(account='jsmith', password='x', UID=1001, GID=1000,
GECOS=dict(fullname='Joe Smith', office='Room 1007', extension='(234)555-8917',
homephone='(234)555-0077', email='jsmith@rosettacode.org'),
directory='/home/jsmith', shell='/bin/bash'),
dict(accoun... | #include <iostream>
#include <fstream>
#include <string>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string s) {
return out << s.c_str();
}
struct gecos_t {
std::string fullname, office, extension, homephone, email;
friend std::ostream& operator<<(std::ostream&, const gecos_t... | codetrans_contest | [
"#include <iostream>\n#include <string>\n#include <algorithm>\n#include <ctime>\n\nconst std::string CHR[] = { \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\", \"abcdefghijklmnopqrstuvwxyz\", \n \"0123456789\", \"!\\\"#$%&'()*+,-./:;<=>?@[]^_{|}~\" };\nconst std::string UNS = \"O0l1I5S2Z\";\n\nstd::string... |
a1 = [[1, 2], [3, 4]]
b1 = [[0, 5], [6, 7]]
a2 = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]
b2 = [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]]
def kronecker(matrix1, matrix2):
final_list = []
sub_list = []
count = len(matrix2)
for elem1 in matrix1:
counter = 0
check = 0
while check <... | #include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns,
const std::initializer_list<s... | codetrans_contest | [
"#include <algorithm>\n#include <cassert>\n#include <iomanip>\n#include <iostream>\n#include <vector>\n\ntemplate <typename scalar_type> class matrix {\npublic:\n matrix(size_t rows, size_t columns)\n : rows_(rows), columns_(columns), elements_(rows * columns) {}\n\n matrix(size_t rows, size_t columns,... |
from livewires import *
horiz=640; vert=480; pruh=vert/4; dpp=255.0
begin_graphics(width=horiz,height=vert,title="Gray stripes",background=Colour.black)
def ty_pruhy(each):
hiy=each[0]*pruh; loy=hiy-pruh
krok=horiz/each[1]; piecol=255.0/(each[1]-1)
for x in xrange(0,each[1]):
barva=Colour(piecol*x/dpp,piecol*... | #ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
class QPaintEvent ;
class MyWidget : public QWidget {
public :
MyWidget( ) ;
protected :
void paintEvent( QPaintEvent * ) ;
} ;
#endif
| codetrans_contest | [
"#include <windows.h>\n#include <list>\n#include <iostream>\n\n\nusing namespace std;\n\n\nclass point\n{\npublic:\n int x, y;\n point() { x = y = 0; }\n point( int a, int b ) { x = a; y = b; }\n void set( int a, int b ) { x = a; y = b; }\n};\n\nclass rndCircle\n{\npublic:\n void ... |
from sympy import factorint
NUM_WANTED = 100
for num in range(1, NUM_WANTED + 1):
fac = factorint(num, multiple=True)
product = fac[0] * fac[-1] if len(fac) > 0 else 1
print(f'{product:5}', end='\n' if num % 10 == 0 else '')
| #include <iomanip>
#include <iostream>
#include <utility>
auto min_max_prime_factors(unsigned int n) {
unsigned int min_factor = 1;
unsigned int max_factor = 1;
if ((n & 1) == 0) {
while ((n & 1) == 0)
n >>= 1;
min_factor = 2;
max_factor = 2;
}
for (unsigned int ... | codetrans_contest | [
"#include <iostream>\n#include <iomanip>\n#include <vector>\n#include <algorithm>\n#include <iterator>\n\nstd::vector<int> GenerateFactors(int n) {\n std::vector<int> factors = { 1, n };\n for (int i = 2; i * i <= n; ++i) {\n if (n % i == 0) {\n factors.push_back(i);\n if (i * i !... |
import copy
from fractions import Fraction
def gauss(a, b):
a = copy.deepcopy(a)
b = copy.deepcopy(b)
n = len(a)
p = len(b[0])
det = 1
for i in range(n - 1):
k = i
for j in range(i + 1, n):
if abs(a[j][i]) > abs(a[k][i]):
k = j
if k != i:
... | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns... | codetrans_contest | [
"#include <iostream>\n#include <iomanip>\n#include <cmath>\n\nnamespace Rosetta {\n\n \n template <int N>\n class GaussLegendreQuadrature {\n public:\n enum {eDEGREE = N};\n\n \n template <typename Function>\n double integrate(double a, double b, Function f) {\n do... |