Model: Nan-Do/CP-Ranker
Author: Nan-Do
Pipeline: sentence-similarity
Library: sentence-transformers
Tags: sentence-transformers, safetensors, new, sentence-similarity, feature-extraction, dense, generated_from_trainer, dataset_size:865218, loss:TripletLoss, custom_code, arxiv:1908.10084, arxiv:1703.07737, base_model:Salesforce/SFR-Embedding-Code-400M_R, base_model:finetune:Salesforce/SFR-Embedding-Code-400M_R, text-embeddings-inference, endpoints_compatible, region:us
Base models (finetune): id: Salesforce/SFR-Embedding-Code-400M_R
Card metadata: tags: sentence-transformers, sentence-similarity, feature-extraction, dense, generated_from_trainer, dataset_size:865218, loss:TripletLoss
base_model: Salesforce/SFR-Embedding-Code-400M_R
widget: source_sentence: Swaps in a String
You are given a string $S$ that contains of the characters $A$, $B$ or $C$ only.

In one operation, you can do either of the following:

- Choose an occurrence of $\text{AB}$ in the string, convert it to $\text{BA}$.
- Choose an occurrence of $\text{BC}$ in the string, convert it to $\text{CB}$.

Note that you are only allowed to operate on adjacent elements.

Find the maximum number of operations you can do. It can be proven the answer is finite.

Input Format:
- The first line of input will contain a single integer $T$, denoting the number of test cases.
- Each test case consists of multiple lines of input.
    - The first line of each test case contains $N$ - the length of the string.
    - The second line contains $S$ - the string.

Output Format:
For each test case, output on a new line the maximum number of operations possible.

Constraints:
- $1 \le T \le 10^4$
- $2 \le N \le 2 \cdot 10^5$
- $|S| = N$
- $S_i \in \{A, B, C\}$
- The sum of $N$ over all test cases does not exceed $2 \cdot 10^5$.

Sample 1:
Input:
3
4
ABCC
5
BAABB
2
BA

Output:
2
4
0
Explanation:
**Test Case 1** : We can convert $\text{ABCC}$ to $\text{ACBC}$ and then to $\text{ACCB}$. More than $2$ operations can be proven to be impossible.

**Test Case 2** : $\text{BAABB} \rightarrow \text{BABAB} \rightarrow \text{BBAAB} \rightarrow \text{BBABA} \rightarrow \text{BBBAA}$.

sentences: #from collections import Counter
#import math
#import deque
t=int(input())
for _ in range(t):
    n=int(input())
    a=input()
    C1=[]
    C2=[]
    c1=0
    c2=0
    res=0
    for i in a:
        if i=='A':
            c1+=1
        elif i=='B':
            pass
        else:
            c1=0
        C1.append(c1)
    for i in a[::-1]:
        if i=='A':
            c2=0
        elif i=='B':
            pass
        else:
            c2+=1
        C2.append(c2)
    C2=C2[::-1]
    for i in range(n):
        if a[i]=='B':
            res+=max(C1[i],C2[i])
    print(res), #from collections import Counter
#import math
#import deque
t=int(input())
for _ in range(t):
    n=int(input())
    a=input()
    C1=[]
    C2=[]
    c1=0
    c2=0
    res=0
    for i in a:
        if i=='A':
            c1+=1
        elif i=='C':
            c1=0
        C1.append(c1)
    for i in a[::-1]:
        if i=='A':
            c2=0
        elif i=='C':
            c2+=1
        C2.append(c2)
    C2=C2[::-1]
    for i in range(n):
        if a[i]=='B':
            res+=max(C1[i],C2[i])
    print(res), # cook your dish here
import math
for _ in range(int(input())):
    n=int(input())
    x=math.ceil(n/2)
    y=math.ceil(n/3)
    print(x,y)
    , source_sentence: We have N coins numbered 1 to N with two distinguishable sides. A string S represents the current state of the coins. If the i-th character of S is 1, coin i is showing heads; if that character is 0, coin i is showing tails.

  You can repeat the following operation zero or more times.

    * Choose a pair of integers (i,j) such that 1\leq i < j\leq N and j-i\geq \bm{2}. Flip coin i and coin j.

  Determine whether it is possible to make all the N coins show tails. If it is possible, find the minimum number of operations needed.

  You are given T test cases to solve.

  Constraints

    * 1 \leq T \leq 2\times 10^5
    * 3 \leq N \leq 2\times 10^5
    * S is a string of length N consisting of 0 and 1.
    * All numbers in the input are integers.
    * For each input file, the sum of N over the test cases is at most 2\times 10^5.

    Input

    The input is given from Standard Input in the following format:

    T
    \mathrm{case}_1
    \vdots
    \mathrm{case}_T
    

    ​ Each case is in the following format:

    N
    S
    

    Output

    Print T lines. The i-th line (1\leq i \leq T) should contain the minimum number of operations needed to make all the coins show tails if it is possible, and -1 otherwise.

  Sample Input 1

  5
  3
  101
  6
  101101
  5
  11111
  6
  000000
  30
  111011100110101100101000000111
  

  Sample Output 1

  1
  2
  -1
  0
  8
  

  For the first test case, you can perform the operation with (i,j)=(1,3) to make all the coins show tails in one operation.

  For the second test case, you can perform the operation with (i,j)=(1,3) and then with (i,j)=(4,6) to make all the coins show tails in two operations.

  For the third test case, you can prove that there is no way to make all the coins show tails, so you should print -1.

  For the fourth test case, the coins already show tails, so no operation is needed.
sentences: A, B, X = map(int, input().split())

ans = 0

for i in range(1, 12):
    rem = X - i * B
    if rem <= 0:
        continue
    if rem // A < 10**(i - 1):
        continue

    if 10**(i - 1) <= rem // A < 10**(i):
        ans = max(ans, rem // A)
    elif rem // A >= 10**(i - 1) - 1:
        cand = []
        for i in range(i):
            cand.append('9')
        ans = max(int(''.join(cand)), ans)
    else:
        ans = max(ans, rem // A)

print(min(10**9, ans)), t=int(input())
import itertools
import heapq

for i in range(t):
  n=int(input())
  s=list(input())
  #print(s)
  if s==['1','1','0'] or s==['0','1','1']:
    print(-1)
    continue
  if s==['0','1','1','0'] :
    print(3)
    continue
  g=itertools.groupby(s)
  q=[]#heapq.heapify([])
  cnt=0
  cnt2=0
  ans=0
  l2=0
  for k,v in g:
    
    v=list(v)
    #print(v)
    #print(len(v))
    if k=='1':
      l=len(v)
      cnt2+=1
      l2=len(v)
      cnt+=l
      #print(k,list(v),'d')
      #print(l2,len(list(v)),list(v))
      heapq.heappush(q,-l)
  if cnt2==1 and l2==2:
    ans+=1
  #print(cnt2,l2)
  if cnt%2==1:
    print(-1)
    continue
 # print(q)
  while q:
    #print(q)
    if len(q)==1:
      l1=heapq.heappop(q)
      ans+=(-l1)//2
    else:
      l1=heapq.heappop(q)
      l2=heapq.heappop(q)
      ans+=-max(l1,l2)
      if l1!=l2:heapq.heappush(q,-abs(l1-l2))
  print(ans), t=int(input())
import itertools
import heapq

for i in range(t):
  n=int(input())
  s=list(input())
  #print(s)
  g=itertools.groupby(s)
  q=[]#heapq.heapify([])
  cnt=0
  cnt2=0
  ans=0
  l2=0
  for k,v in g:
    
    v=list(v)
   # print(v)
    if k=='1':
      l=len(v)
      cnt2+=1
      l2=len(v)
      cnt+=l
      #print(k,list(v),'d')
      #print(l2,len(list(v)),list(v))
      heapq.heappush(q,-l)
  if cnt2==1 and l2==2:
    ans+=1
  #print(cnt2,l2)
  if cnt%2==1:
    print(-1)
    continue
 # print(q)
  while q:
    #print(q)
    if len(q)==1:
      l1=heapq.heappop(q)
      ans+=(-l1)//2
    else:
      l1=heapq.heappop(q)
      l2=heapq.heappop(q)
      ans+=-max(l1,l2)
      if l1!=l2:heapq.heappush(q,-abs(l1-l2))
  print(ans), source_sentence: Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions:

    * 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9
    * The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2.

  We can prove that there always exist six integers that satisfy the conditions under the constraints of this problem.

  Constraints

    * 1 \leq S \leq 10^{18}
    * All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    S
    

    Output

    Print six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfy the conditions, in this order, with spaces in between. If multiple solutions exist, any of them will be accepted.

  Sample Input 1

  3
  

  Sample Output 1

  1 0 2 2 0 1
  

  The area of the triangle in a two-dimensional plane whose vertices are (1,0),(2,2), and (0,1) is 3/2. Printing 3 0 3 1 0 1 or 1 0 0 1 2 2 will also be accepted.

  Sample Input 2

  100
  

  Sample Output 2

  0 0 10 0 0 10
  

  Sample Input 3

  311114770564041497
  

  Sample Output 3

  314159265 358979323 846264338 327950288 419716939 937510582
sentences: import sys
input = sys.stdin.readline

x, y = map(int, input().split())
INF = 10**10
if y >= x:
    ans1 = y-x
else:
    ans1 = INF
if -y >= x:
    ans2 = -y - x + 1
else:
    ans2 = INF
if y >= -x:
    ans3 = y - (-x) + 1
else:
    ans3 = INF
if -y >= -x:
    ans4 = -y - (-x) + 2
else:
    ans4 = INF
ans = min(ans1, ans2, ans3, ans4)
print(ans)
, s=int(input())
if s+1<=10**9:
  b=str(s+1)
  a=['0','0',b,'1','1','1']
else:
  a=int(s**(1/2))
  if a**2>=s:
    a_=a
  else:
    if a*(a+1)>=s:
      a_=a+1
    else:
      if a*(a+2)>=s and a+2<=10**9:
        a_=a+2
      else:
        a_=a+1
        a+=1
  x2=str(a)
  y3=str(a_)
  
  y2=str(1)
  x3=str(int(x2)*int(y3)-s)
  x1=str(0)
  y1=str(0)
  a=[x1,y1,x2,y2,x3,y3]
print((' ').join(a))
, s=int(input())
if s+1<=10**9:
  b=str(s+1)
  a=['0','0',b,'1','1','1']
else:
  x2=int(s**(1/2))
  y3=int(s**(1/2))
  while s>x2*y3:
    y3+=1
  x2=str(x2)
  y3=str(y3)
  y2=str(1)
  x3=str(int(x2)*int(y3)-s)
  x1=str(0)
  y1=str(0)
  a=[x1,y1,x2,y2,x3,y3]
print((' ').join(a)) , source_sentence: There is a directed graph with N vertices and M edges, where vertices are numbered from 1 to N and edges are numbered from 1 to M. Edge i is a directed edge from vertex A_i to vertex B_i with weight W_i.

  Find the minimum value of the bitwise \mathrm{XOR} of the weights of edges included in a walk from vertex 1 to vertex N.

  What is a walk from vertex 1 to vertex N?

  Intuitively, it is "a path from vertex 1 to vertex N that may visit the same vertex or edge multiple times." Formally, it is a sequence of edges (e_1,\ldots,e_k) that satisfies all of the following conditions:

    * e_1 starts at vertex 1.
    * For all 1 \leq i < k, the endpoint of e_i and the starting point of e_{i+1} are the same.
    * e_k ends at vertex N.
  What is the bitwise \mathrm{XOR} operation?

  The bitwise \mathrm{XOR} of non-negative integers A and B, denoted A\ \mathrm{XOR}\ B, is defined as follows:

    * When A\ \mathrm{XOR}\ B is written in binary, the digit at the 2^k place (k \geq 0) is 1 if exactly one of the digits at the 2^k place of A and B in binary is 1, and 0 otherwise.
  For example, 3\ \mathrm{XOR}\ 5 = 6 (in binary: 011\ \mathrm{XOR}\ 101 = 110).
  In general, the bitwise \mathrm{XOR} of k non-negative integers p_1, p_2, p_3, \dots, p_k is defined as (\dots ((p_1\ \mathrm{XOR}\ p_2)\ \mathrm{XOR}\ p_3)\ \mathrm{XOR}\ \dots\ \mathrm{XOR}\ p_k), and it can be proved that this does not depend on the order of p_1, p_2, p_3, \dots p_k.

  Constraints

    * 2 \leq N \leq 1000
    * 0 \leq M \leq 1000
    * 1 \leq A_i,B_i \leq N
    * 0 \leq W_i < 2^{10}
    * All input values are integers.

    Input

    The input is given from Standard Input in the following format:

    N M
    A_1 B_1 W_1
    A_2 B_2 W_2
    \vdots
    A_M B_M W_M
    

    Output

    If there is no walk from vertex 1 to vertex N, output -1.

    If there is a walk from vertex 1 to vertex N, output the minimum value of the bitwise \mathrm{XOR} of the weights of edges included in such a walk.

  Sample Input 1

  3 3
  1 2 4
  2 3 5
  1 3 2
  

  Sample Output 1

  1
  

  The bitwise \mathrm{XOR} of the weights of edges included in the walk (edge 1, edge 2) is 1.

  Sample Input 2

  4 4
  1 4 7
  4 2 2
  2 3 4
  3 4 1
  

  Sample Output 2

  0
  

  The bitwise \mathrm{XOR} of the weights of edges included in the walk (edge 1, edge 2, edge 3, edge 4) is 0.

  Note that the walk may include vertex N in the middle.

  Sample Input 3

  999 4
  1 2 9
  2 1 8
  1 2 7
  1 1 6
  

  Sample Output 3

  -1
  

  If there is no walk from vertex 1 to vertex N, output -1.
sentences: import sys
import os
from io import StringIO
import unittest
from typing import *

from bisect import *
from collections import *
from heapq import *
from itertools import *
from math import *

MOD = 998244353
INF = 1<<60
LABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SABC = "abcdefghijklmnopqrstuvwxyz"

def resolve():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b, w = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append((b, w))
    
    dp = [[set() for _ in range(N)] for _ in range(N + 1)]
    for b, w in graph[0]:
        dp[1][b].add(w)
    
    for i in range(1, N):
        for a in range(N):
            for curr_w in dp[i][a]:
                for b, w in graph[a]:
                    if len(dp[i + 1][b]) < 50:
                        dp[i + 1][b].add(curr_w ^ w)
    
    ans = 1 << 60
    for i in range(N + 1):
        for w in dp[i][N - 1]:
            ans = min(ans, w)
    if ans >= 1 << 60:
        ans = -1
    print(ans)

def meguru(judge, ok=-1, ng=1<<60):
    while abs(ok - ng) > 1:
        med = (ok + ng) // 2
        if judge(med):
            ok = med
        else:
            ng = med
    return ok

class TestClass(unittest.TestCase):
    def test_sample1(self):
        input = """3 3
1 2 4
2 3 5
1 3 2"""
        expected = """1"""
        self.judge(input, expected)

    def test_sample2(self):
        input = """4 4
1 4 7
4 2 2
2 3 4
3 4 1"""
        expected = """0"""
        self.judge(input, expected)

    def test_sample3(self):
        input = """999 4
1 2 9
2 1 8
1 2 7
1 1 6"""
        expected = """-1"""
        self.judge(input, expected)

    def judge(self, input, expected):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        actual = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(expected, actual)

if __name__ == "__main__":
    if "ATCODER" in os.environ:
        resolve()
    else:
        unittest.main(verbosity=2)
, import sys
import os
from io import StringIO
import unittest
from typing import *

from bisect import *
from collections import *
from heapq import *
from itertools import *
from math import *

MOD = 998244353
INF = 1<<60
LABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SABC = "abcdefghijklmnopqrstuvwxyz"

def resolve():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b, w = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append((b, w))
    
    dp = [[set() for _ in range(N)] for _ in range(N + 1)]
    seen = [set() for _ in range(N)]
    for b, w in graph[0]:
        dp[1][b].add(w)
    
    for i in range(1, N):
        for a in range(N):
            if not dp[i][a]:
                continue
            for curr_w in dp[i][a] - seen[a]:
                for b, w in graph[a]:
                    seen[a].add(curr_w)
                    dp[i + 1][b].add(curr_w ^ w)
    
    ans = 1 << 60
    for i in range(N + 1):
        for w in dp[i][N - 1]:
            ans = min(ans, w)
    if ans >= 1 << 60:
        ans = -1
    print(ans)

def meguru(judge, ok=-1, ng=1<<60):
    while abs(ok - ng) > 1:
        med = (ok + ng) // 2
        if judge(med):
            ok = med
        else:
            ng = med
    return ok

class TestClass(unittest.TestCase):
    def test_sample1(self):
        input = """3 3
1 2 4
2 3 5
1 3 2"""
        expected = """1"""
        self.judge(input, expected)

    def test_sample2(self):
        input = """4 4
1 4 7
4 2 2
2 3 4
3 4 1"""
        expected = """0"""
        self.judge(input, expected)

    def test_sample3(self):
        input = """999 4
1 2 9
2 1 8
1 2 7
1 1 6"""
        expected = """-1"""
        self.judge(input, expected)

    def judge(self, input, expected):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        actual = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(expected, actual)

if __name__ == "__main__":
    if "ATCODER" in os.environ:
        resolve()
    else:
        unittest.main(verbosity=2)
, a1, a2, a3 = map(int, input().split())
num1 = a2 - a1
num2 = a3 - a2
num3 = a3 - a1
if num3 > 0:
    if num1 <= num2:
        if num3 % 2 == 0:
            print(a3 - num3 // 2 - a2)
        else:
            print(a3 - num3 // 2 - a2 + 1)
    else:
        print(a2 - num2 - a1)
elif num3 < 0:
    if num1 <= num2:
        if num3 % 2 == 0:
            print(a1 + num3 // 2 - a2)
        else:
            print(a1 + num3 // 2 - a2 + 2)
    else:
        print(a2 + num1 - a3)
else:
    if a1 < a2:
        print((a2 - a1) * 2)
    else:
        print(a1 - a2)
, source_sentence: You are given an array of n integer numbers a0 , a1 , ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

      Input

    The first line contains positive integer n ( 2 ≤ n ≤ 10 5) — size of the given array. The second line contains n integers a0 , a1 , ..., an - 1 ( 1 ≤ ai ≤ 10 9) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

      Output

    Print the only number — distance between two nearest minimums in the array.

      Examples
          Input
        2
        3 3
          Output
        1
          Input
        3
        5 6 5
          Output
        2
          Input
        9
        2 1 3 5 4 1 2 3 1
          Output
        3
sentences: def is_letter(char):
    return (
        ord('a') <= ord(char) <= ord('z') or
        ord('A') <= ord(char) <= ord('Z')
    )

n, kk = map(int, input().split())
placement = [
    [i for i in input()] for j in range(n)
]


kc = 0 

for row in placement:
    for i in range(len(row)):
        if (row[i] == '.'):
            count = 0
            if (i > 0 and row[i - 1] == 'S'):
                count += 1
            if (i < len(row) - 1 and row[i + 1] == 'S'):
                count += 1
            row[i] = count
        if (row[i] == 'S'):
            if (i > 0 and is_letter(str(row[i - 1]))):
                kc += 1
            if (i < len(row) - 1 and is_letter(str(row[i + 1]))):
                kc += 1
 
for i in range(3):
    for j in range(len(placement)):
        if (kk == 0):
            # print(f'broken here {i}, {j}') 
            break
        for k in range(len(placement[j])):
            if placement[j][k] == i:
                placement[j][k] = 'x'
                kc += i
                kk -= 1
                if (kk == 0):
                    # print("broken")                    
                    break

kkk = 0

for i in range(len(placement)):
    for j in range(len(placement[i])):
        if type(placement[i][j]) == type(1):
            placement[i][j] = '.'

print(kc)
for row in placement:
    print(''.join(row)), import sys
n=int(input())
l=list(map(int,input().split()))
m=min(l)
#print (m)
indices = [i for i, x in enumerate(l) if x == m]
#print (indices)
mi=(sys.maxsize)
for i in range(len(indices)-1):
    x=(indices[i+1]-indices[i])
    if x<mi:
        mi=x
print (mi), n = int(input())

arr = list(map(int, input().split()))

minimum = min(arr)

index1 = arr.index(minimum)

for i in range(index1+1, len(arr)):
 if arr[i] == minimum:
  print(i - index1)
  break
pipeline_tag: sentence-similarity
library_name: sentence-transformers
Likes: 0 | All-time downloads: 197
Created: 2025-10-30 22:54:30