Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
12
25
problem_id
int64
1
14.1k
language
stringclasses
7 values
split
stringclasses
1 value
strategy
stringclasses
1 value
code
stringlengths
46
6.1k
roles
dict
10005:Python:baseline
10,005
Python
train
baseline
def maxPresum ( a , b ) : X = max ( a [ 0 ] , 0 ) for i in range ( 1 , len ( a ) ) : a [ i ] += a [ i - 1 ] X = max ( X , a [ i ] ) Y = max ( b [ 0 ] , 0 ) for i in range ( 1 , len ( b ) ) : b [ i ] += b [ i - 1 ] Y = max ( Y , b [ i ] ) return X + Y A = [ 2 , - 1 , 4...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10010:Python:baseline
10,010
Python
train
baseline
import math def sumOfTwoCubes ( n ) : lo = 1 hi = round ( math . pow ( n , 1 / 3 ) ) while ( lo <= hi ) : curr = ( lo * lo * lo + hi * hi * hi ) if ( curr == n ) : return True if ( curr < n ) : lo += 1 else : hi -= 1 return False N = 28...
{ "index_key": [], "accumulator": [ "hi", "lo" ], "iterator": [], "boolean": [], "class_struct": [] }
10023:Python:baseline
10,023
Python
train
baseline
def findNthNumber ( N ) : result = 0 p = 1 while ( N > 0 ) : result += ( p * ( N % 9 ) ) N = N // 9 p = p * 10 return result if __name__ == ' _ _ main _ _ ' : N = 9 print ( findNthNumber ( N ) )
{ "index_key": [], "accumulator": [ "result" ], "iterator": [], "boolean": [], "class_struct": [] }
10046:Python:baseline
10,046
Python
train
baseline
def sameProductQuadruples ( nums , N ) : umap = { } ; res = 0 ; for i in range ( N ) : for j in range ( i + 1 , N ) : prod = nums [ i ] * nums [ j ] ; if prod in umap : res += 8 * umap [ prod ] ; umap [ prod ] += 1 ; else : ...
{ "index_key": [ "i", "j", "prod" ], "accumulator": [ "res" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10068:Python:baseline
10,068
Python
train
baseline
def isCycleExists ( arr , N ) : valley = 0 for i in range ( 1 , N ) : if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) : print ( " Yes " ) return print ( " No " ) if __name__ == ' _ _ main _ _ ' : arr = [ 1 , 3 , 2 , 4 , 5 ] N = len ( arr ) isCycleEx...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10080:Python:baseline
10,080
Python
train
baseline
def getMax ( arr , N , K ) : for i in range ( 1 , N , 1 ) : cur_val = arr [ i ] while ( K >= i ) : if ( cur_val > 0 ) : arr [ 0 ] = arr [ 0 ] + 1 cur_val = cur_val - 1 K = K - i else : break print ( arr [ 0 ]...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10110:Python:baseline
10,110
Python
train
baseline
def minSwaps ( b ) : n = len ( b ) for i in range ( n ) : for j in range ( n ) : if ( b [ 0 ] [ 0 ] ^ b [ 0 ] [ j ] ^ b [ i ] [ 0 ] ^ b [ i ] [ j ] ) : return - 1 rowSum = 0 colSum = 0 rowSwap = 0 colSwap = 0 for i in range ( n ) : rowSum += b [ i ...
{ "index_key": [ "i", "j" ], "accumulator": [ "colSum", "colSwap", "rowSum", "rowSwap" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10116:Python:baseline
10,116
Python
train
baseline
mod = 1000000007 def ValOfTheExpression ( n ) : global mod factorial = [ 0 for i in range ( n + 1 ) ] factorial [ 0 ] = 1 factorial [ 1 ] = 1 for i in range ( 2 , n + 1 , 1 ) : factorial [ i ] = ( ( factorial [ i - 1 ] % mod ) * ( i % mod ) ) % mod dp = [ 0 for i in range ( n + 1 ) ] ...
{ "index_key": [ "i", "n" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10117:Python:baseline
10,117
Python
train
baseline
def minChocolates ( A , N ) : B = [ 1 for i in range ( N ) ] for i in range ( 1 , N ) : if ( A [ i ] > A [ i - 1 ] ) : B [ i ] = B [ i - 1 ] + 1 else : B [ i ] = 1 for i in range ( N - 2 , - 1 , - 1 ) : if ( A [ i ] > A [ i + 1 ] ) : B [ i ] = max ...
{ "index_key": [ "i" ], "accumulator": [ "sum" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10135:Python:baseline
10,135
Python
train
baseline
from math import sqrt , ceil , floor def constructArrayWithGivenLCM ( N ) : newArr = [ ] for i in range ( 1 , ceil ( sqrt ( N + 1 ) ) ) : if ( N % i == 0 ) : newArr . append ( i ) if ( N // i != i ) : newArr . append ( N // i ) newArr = sorted ( newArr ) f...
{ "index_key": [], "accumulator": [ "newArr" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10144:Python:baseline
10,144
Python
train
baseline
def getPower ( p ) : res = 1 while ( p ) : res *= 5 p -= 1 return res def countNumbersUtil ( N ) : count = 0 digits = [ ] while ( N ) : digits . append ( N % 10 ) N //= 10 digits . reverse ( ) D = len ( digits ) for i in range ( 1 , D + 1 , 1 ) : ...
{ "index_key": [], "accumulator": [ "N", "count", "digits", "res" ], "iterator": [ "i", "p" ], "boolean": [], "class_struct": [] }
10161:Python:baseline
10,161
Python
train
baseline
def alternatingSumOfFirst_N ( N ) : alternateSum = 0 for i in range ( 1 , N + 1 ) : if ( i % 2 == 0 ) : alternateSum += - i else : alternateSum += i return alternateSum if __name__ == " _ _ main _ _ " : N = 6 print ( alternatingSumOfFirst_N ( N ) )
{ "index_key": [], "accumulator": [ "alternateSum" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10200:Python:baseline
10,200
Python
train
baseline
def gcd ( a , b ) : if ( a == 0 ) : return b ; return gcd ( b % a , a ) ; def findSum ( N ) : sum = 0 ; for i in range ( 1 , N ) : if ( gcd ( i , N ) == 1 ) : sum += i ; return sum ; if __name__ == ' _ _ main _ _ ' : N = 5 ; print ( findSum ( N ) ) ;
{ "index_key": [], "accumulator": [ "sum" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10201:Python:baseline
10,201
Python
train
baseline
def solve ( arr , n ) : mp = { } for i in arr : mp [ i ] = mp . get ( i , 0 ) + 1 cnt = 0 for x in mp : cnt += ( ( mp [ x ] ) * ( mp [ x ] - 1 ) // 2 ) ans = [ 0 ] * n for i in range ( n ) : ans [ i ] = cnt - ( mp [ arr [ i ] ] - 1 ) for i in ans : print ( i ,...
{ "index_key": [ "i", "x" ], "accumulator": [ "cnt" ], "iterator": [ "i", "x" ], "boolean": [], "class_struct": [] }
10207:Python:baseline
10,207
Python
train
baseline
def findMode ( a , n ) : mp = { } max = 0 mode = 0 for i in range ( n ) : if a [ i ] in mp : mp [ a [ i ] ] += 1 else : mp [ a [ i ] ] = 1 if ( mp [ a [ i ] ] >= max ) : max = mp [ a [ i ] ] mode = a [ i ] print ( mode , end...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10213:Python:baseline
10,213
Python
train
baseline
def modexp ( x , n , m ) : if ( n == 0 ) : return 1 else : if ( n % 2 == 0 ) : return modexp ( ( x * x ) % m , n / 2 , m ) ; else : return ( x * modexp ( ( x * x ) % m , ( n - 1 ) / 2 , m ) % m ) def modInverse ( x , m ) : return modexp ( x , m - 2 , m ) def c...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10231:Python:baseline
10,231
Python
train
baseline
def Kmultiples ( n , k ) : a = n for i in range ( 1 , k + 1 ) : print ( " { } ▁ * ▁ { } ▁ = ▁ { } " . format ( n , i , a ) ) j = 0 while ( n >= ( 1 << j ) ) : a += n & ( 1 << j ) j += 1 N = 16 K = 7 Kmultiples ( N , K )
{ "index_key": [], "accumulator": [ "a", "j" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10234:Python:baseline
10,234
Python
train
baseline
def calculateB ( x , y , n ) : sx = sum ( x ) sy = sum ( y ) sxsy = 0 sx2 = 0 for i in range ( n ) : sxsy += x [ i ] * y [ i ] sx2 += x [ i ] * x [ i ] b = ( n * sxsy - sx * sy ) / ( n * sx2 - sx * sx ) return b def leastRegLine ( X , Y , n ) : b = calculateB ( X , Y , n ...
{ "index_key": [ "i" ], "accumulator": [ "sx2", "sxsy" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10236:Python:baseline
10,236
Python
train
baseline
def countRepeatingDigits ( N ) : res = 0 cnt = [ 0 ] * 10 while ( N > 0 ) : rem = N % 10 cnt [ rem ] += 1 N = N // 10 for i in range ( 10 ) : if ( cnt [ i ] > 1 ) : res += 1 return res N = 12 print ( countRepeatingDigits ( N ) )
{ "index_key": [ "i", "rem" ], "accumulator": [ "res" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10257:Python:baseline
10,257
Python
train
baseline
def findAandB ( n , k ) : flag = 0 for i in range ( 1 , n ) : if str ( i ) . count ( chr ( k + 48 ) ) == 0 and str ( n - i ) . count ( chr ( k + 48 ) ) == 0 : print ( i , n - i ) flag = 1 break if ( flag == 0 ) : print ( - 1 ) if __name__ == ' _ _ main _ _...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10266:Python:baseline
10,266
Python
train
baseline
def calculate ( p , q ) : mod = 998244353 expo = 0 expo = mod - 2 while ( expo ) : if ( expo & 1 ) : p = ( p * q ) % mod q = ( q * q ) % mod expo >>= 1 return p if __name__ == ' _ _ main _ _ ' : p = 1 q = 4 print ( calculate ( p , q ) )
{ "index_key": [], "accumulator": [ "expo" ], "iterator": [], "boolean": [], "class_struct": [] }
10282:Python:baseline
10,282
Python
train
baseline
def MaxSubarrayLength ( arr , n , k ) : left = - 1 sum = 0 for i in range ( n ) : if ( ( arr [ i ] % k ) != 0 ) : if ( left == - 1 ) : left = i right = i sum += arr [ i ] if ( ( sum % k ) != 0 ) : return n elif ( left == - 1 ) : ...
{ "index_key": [ "i" ], "accumulator": [ "sum" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10297:Python:baseline
10,297
Python
train
baseline
from collections import defaultdict def countQuadraples ( N ) : cnt = 0 m = defaultdict ( int ) for a in range ( 1 , N + 1 ) : for b in range ( 1 , N + 1 ) : x = a * a + b * b m [ x ] += 1 for c in range ( 1 , N + 1 ) : for d in range ( 1 , N + 1 ) : x...
{ "index_key": [ "x" ], "accumulator": [ "cnt" ], "iterator": [ "a", "b", "c", "d" ], "boolean": [], "class_struct": [] }
10302:Python:baseline
10,302
Python
train
baseline
from bisect import bisect_left def numberOfPairs ( a , b , n ) : c = [ 0 for i in range ( n ) ] for i in range ( n ) : c [ i ] = a [ i ] - b [ i ] c = sorted ( c ) answer = 0 for i in range ( 1 , n ) : if ( c [ i ] <= 0 ) : continue pos = bisect_left ( c , - c [ i...
{ "index_key": [ "i" ], "accumulator": [ "answer" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10312:Python:baseline
10,312
Python
train
baseline
def print_h_index ( arr , N ) : ms = [ ] for i in range ( N ) : ms . append ( arr [ i ] ) ms . sort ( ) if ( ms [ 0 ] < len ( ms ) ) : ms . pop ( 0 ) print ( len ( ms ) , end = ' ▁ ' ) if __name__ == ' _ _ main _ _ ' : arr = [ 9 , 10 , 7 , 5 , 0 , 10 , 2 , 0 ] ...
{ "index_key": [ "i" ], "accumulator": [ "ms" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10316:Python:baseline
10,316
Python
train
baseline
def findPrimes ( arr , n ) : max_val = max ( arr ) prime = [ True for i in range ( max_val + 1 ) ] prime [ 0 ] = False prime [ 1 ] = False p = 2 while ( p * p <= max_val ) : if ( prime [ p ] == True ) : for i in range ( p * 2 , max_val + 1 , p ) : prime [ i ] ...
{ "index_key": [ "entry", "i", "p" ], "accumulator": [], "iterator": [ "entry", "i" ], "boolean": [], "class_struct": [] }
10318:Python:baseline
10,318
Python
train
baseline
def prefixProduct ( a , n ) : for i in range ( 1 , n ) : a [ i ] = a [ i ] * a [ i - 1 ] ; for j in range ( 0 , n ) : print ( a [ j ] , end = " , ▁ " ) ; return 0 ; arr = [ 2 , 4 , 6 , 5 , 10 ] ; N = len ( arr ) ; prefixProduct ( arr , N ) ;
{ "index_key": [ "i", "j" ], "accumulator": [], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10326:Python:baseline
10,326
Python
train
baseline
def countWays ( N ) : if ( N < 4 ) : return 0 ans = ( ( N - 1 ) * ( N - 2 ) ) // 2 s = 0 for i in range ( 2 , N - 2 , 1 ) : for j in range ( 1 , i , 1 ) : if ( N == 2 * i + j ) : s += 1 if ( N % 3 == 0 ) : s = 3 * s + 1 else : s = 3 * s...
{ "index_key": [], "accumulator": [ "s" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10338:Python:baseline
10,338
Python
train
baseline
def isPrime ( n ) : if ( n <= 1 ) : return False if ( n <= 3 ) : return True if ( n % 2 == 0 ) or ( n % 3 == 0 ) : return False i = 5 while ( i * i <= n ) : if ( n % i == 0 or n % ( i + 2 ) == 0 ) : return False i = i + 6 return True def isMagn...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10342:Python:baseline
10,342
Python
train
baseline
limit = 10000000 position = [ 0 ] * ( limit + 1 ) def sieve ( ) : position [ 0 ] = - 1 position [ 1 ] = - 1 pos = 0 for i in range ( 2 , limit + 1 ) : if ( position [ i ] == 0 ) : pos += 1 position [ i ] = pos for j in range ( i * 2 , limit + 1 , i ) : ...
{ "index_key": [ "i", "j", "n" ], "accumulator": [ "pos" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10364:Python:baseline
10,364
Python
train
baseline
import math def isPrime ( n ) : if ( n <= 1 ) : return False ; for i in range ( 2 , ( int ) ( math . sqrt ( n ) ) + 1 ) : if ( n % i == 0 ) : return False ; return True ; def takeSum ( a ) : s = 0 for i in range ( 0 , 4 ) : for j in range ( 0 , 5 ) : s...
{ "index_key": [ "i", "j" ], "accumulator": [ "s" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10365:Python:baseline
10,365
Python
train
baseline
def sumOfSumSeries ( N ) : _sum = 0 for i in range ( N + 1 ) : _sum = _sum + ( i * ( i + 1 ) ) // 2 return _sum N = 5 print ( sumOfSumSeries ( N ) )
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10369:Python:baseline
10,369
Python
train
baseline
def isContaindigit ( n ) : temp = str ( n ) for i in temp : if i not in [ '0' , '1' , '8' ] : return False return True def ispalindrome ( n ) : temp = str ( n ) if temp == temp [ : : - 1 ] : return True return False def isTetradic ( n ) : if ispalindrome ( n ) : ...
{ "index_key": [ "i", "p" ], "accumulator": [], "iterator": [ "i", "p" ], "boolean": [], "class_struct": [] }
10374:Python:baseline
10,374
Python
train
baseline
def concat ( a , b ) : s1 = str ( a ) s2 = str ( b ) s = s1 + s2 c = int ( s ) return c def isAstonishing ( n ) : for i in range ( n ) : sum = 0 for j in range ( i , n ) : sum += j if ( sum == n ) : concatenation = concat ( i , j ) ...
{ "index_key": [], "accumulator": [ "sum" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10386:Python:baseline
10,386
Python
train
baseline
def checkSame ( n , b ) : m = { } while ( n != 0 ) : r = n % b n = n // b if r in m : m [ r ] += 1 else : m [ r ] = 1 last = - 1 for i in m : if last != - 1 and m [ i ] != last : return False else : last = m ...
{ "index_key": [ "i", "r" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10392:Python:baseline
10,392
Python
train
baseline
def seriesSum ( n ) : sum1 = 0 ; currProd = 1 ; currSum = 1 ; for i in range ( 2 , n + 1 ) : currProd *= i ; currSum += i ; sum1 += currProd - currSum ; return sum1 ; N = 5 ; print ( seriesSum ( N ) , end = " ▁ " ) ;
{ "index_key": [], "accumulator": [ "currProd", "currSum", "sum1" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10398:Python:baseline
10,398
Python
train
baseline
def count ( a , n ) : countElements = 0 for i in range ( n ) : flag = True for j in range ( n ) : if ( i == j ) : continue if ( a [ i ] % a [ j ] == 0 ) : flag = False break if ( flag == True ) : countEle...
{ "index_key": [ "i", "j" ], "accumulator": [ "countElements" ], "iterator": [ "i", "j" ], "boolean": [ "flag" ], "class_struct": [] }
10411:Python:baseline
10,411
Python
train
baseline
def CountPairs ( arr , n ) : count = 0 for i in range ( n ) : for j in range ( i + 1 , n ) : if ( arr [ i ] % 2 == 0 or arr [ j ] % 2 == 0 ) : count += 1 return count arr = [ 8 , 2 , 3 , 1 , 4 , 2 ] n = len ( arr ) print ( CountPairs ( arr , n ) )
{ "index_key": [ "i", "j" ], "accumulator": [ "count" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10431:Python:baseline
10,431
Python
train
baseline
import math def isComposite ( n ) : if ( n <= 1 ) : return False if ( n <= 3 ) : return False if ( n % 2 == 0 or n % 3 == 0 ) : return True i = 5 while ( i * i <= n ) : if ( n % i == 0 or n % ( i + 2 ) == 0 ) : return True i += 6 return False d...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10435:Python:baseline
10,435
Python
train
baseline
import math ; def isDroll ( n ) : if ( n == 1 ) : return False ; sum_even = 0 ; sum_odd = 0 ; while ( n % 2 == 0 ) : sum_even += 2 ; n = n // 2 ; for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) : while ( n % i == 0 ) : sum_odd += i ; n...
{ "index_key": [], "accumulator": [ "sum_even", "sum_odd" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10457:Python:baseline
10,457
Python
train
baseline
import math as m def CountPairs ( n ) : cnt = 0 i = 1 while i * i <= n : if ( n % i == 0 ) : div1 = i div2 = n // i sum = div1 + div2 ; if ( m . gcd ( sum , n ) == 1 ) : cnt += 1 i += 1 return cnt n = 24 print ( CountPairs (...
{ "index_key": [], "accumulator": [ "cnt", "i" ], "iterator": [], "boolean": [], "class_struct": [] }
10489:Python:baseline
10,489
Python
train
baseline
import math sub = [ 0 for i in range ( 100005 ) ] def minDivisorDifference ( n ) : num1 = 0 num2 = 0 for i in range ( int ( math . sqrt ( n ) ) , n + 1 ) : if ( n % i == 0 ) : num1 = i num2 = n // i break return abs ( num1 - num2 ) def dfs ( g , u , par ) : ...
{ "index_key": [ "u" ], "accumulator": [], "iterator": [ "c", "i" ], "boolean": [], "class_struct": [] }
10501:Python:baseline
10,501
Python
train
baseline
def isCenteredcube ( N ) : i = 1 ; while ( True ) : ith_term = ( ( 2 * i + 1 ) * ( i * i + i + 1 ) ) ; if ( ith_term == N ) : return True ; if ( ith_term > N ) : return False ; i += 1 ; N = 9 ; if ( isCenteredcube ( N ) ) : print ( " Yes " ) ; else : ...
{ "index_key": [], "accumulator": [ "i" ], "iterator": [], "boolean": [], "class_struct": [] }
10510:Python:baseline
10,510
Python
train
baseline
def productOfGP ( a , r , n ) : product = 1 ; for i in range ( 0 , n ) : product = product * a ; a = a * r ; return product ; a = 1 r = 2 ; N = 4 ; print ( productOfGP ( a , r , N ) )
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10523:Python:baseline
10,523
Python
train
baseline
def gcd ( a , b ) : if ( b == 0 ) : return a return gcd ( b , a % b ) def findlcm ( arr , n ) : ans = arr [ 0 ] for i in range ( 1 , n ) : ans = ( ( ( arr [ i ] * ans ) ) // ( gcd ( arr [ i ] , ans ) ) ) return ans def addReduce ( n , num , den ) : final_numerator = 0 final_d...
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10524:Python:baseline
10,524
Python
train
baseline
import sys def gcd ( a , b ) : if ( b == 0 ) : return a ; return gcd ( b , a % b ) ; def minLCM ( arr , n ) : ans = 1000000000 ; for i in range ( n ) : for j in range ( i + 1 , n ) : g = gcd ( arr [ i ] , arr [ j ] ) ; lcm = arr [ i ] / g * arr [ j ] ; ...
{ "index_key": [ "i", "j" ], "accumulator": [], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10538:Python:baseline
10,538
Python
train
baseline
from math import pow , ceil def solve ( n ) : upper_limit = ceil ( pow ( n , 1.0 / 4 ) ) ; for x in range ( upper_limit + 1 ) : for y in range ( upper_limit + 1 ) : num1 = x * x * x * x ; num2 = y * y * y * y ; if ( num1 - num2 == n ) : print ( " x ▁ =...
{ "index_key": [], "accumulator": [], "iterator": [ "x", "y" ], "boolean": [], "class_struct": [] }
10549:Python:baseline
10,549
Python
train
baseline
import math def divisorsSame ( n ) : even_div = 0 ; odd_div = 0 ; for i in range ( 1 , int ( math . sqrt ( n ) ) ) : if ( n % i == 0 ) : if ( n // i == i ) : if ( i % 2 == 0 ) : even_div += 1 ; else : odd_div += 1 ; ...
{ "index_key": [], "accumulator": [ "even_div", "odd_div" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10560:Python:baseline
10,560
Python
train
baseline
def isPrime ( n ) : if n <= 1 : return False if n <= 3 : return True if n % 2 == 0 or n % 3 == 0 : return False i = 5 while i * i <= n : if ( n % i == 0 or n % ( i + 2 ) == 0 ) : return False i += 6 return True def isBalancedPrime ( n ) : i...
{ "index_key": [], "accumulator": [ "i", "next_prime", "previous_prime" ], "iterator": [], "boolean": [], "class_struct": [] }
10570:Python:baseline
10,570
Python
train
baseline
import math N = 100001 adj = [ [ ] for i in range ( N ) ] a = [ 0 for i in range ( N ) ] ans = [ 0 for i in range ( N ) ] def hasOddNumberOfDivisors ( n ) : if ( math . sqrt ( n ) == int ( math . sqrt ( n ) ) ) : return True return False def dfs ( node , parent ) : count = 0 for i in adj [ node ...
{ "index_key": [ "i", "node" ], "accumulator": [ "count" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10571:Python:baseline
10,571
Python
train
baseline
def lowerBound ( array , length , value ) : low = 0 high = length while ( low < high ) : mid = ( low + high ) // 2 if ( value <= array [ mid ] ) : high = mid else : low = mid + 1 return low def costCalculation ( current , arr , n , pref , a , r , minimum )...
{ "index_key": [ "i", "index", "mid", "n" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10582:Python:baseline
10,582
Python
train
baseline
from math import * def countBinaries ( N ) : ctr = 1 ans = 0 while ( N > 0 ) : if ( N % 10 == 1 ) : ans += pow ( 2 , ctr - 1 ) elif ( N % 10 > 1 ) : ans = pow ( 2 , ctr ) - 1 ctr += 1 N //= 10 return ans if __name__ == ' _ _ main _ _ ' : N = 20...
{ "index_key": [], "accumulator": [ "N", "ans", "ctr" ], "iterator": [], "boolean": [], "class_struct": [] }
10583:Python:baseline
10,583
Python
train
baseline
def countBinaries ( N ) : powersOfTwo = [ 0 ] * 11 powersOfTwo [ 0 ] = 1 for i in range ( 1 , 11 ) : powersOfTwo [ i ] = powersOfTwo [ i - 1 ] * 2 ctr = 1 ans = 0 while ( N > 0 ) : if ( N % 10 == 1 ) : ans += powersOfTwo [ ctr - 1 ] elif ( N % 10 > 1 ) : ...
{ "index_key": [ "ctr", "i" ], "accumulator": [ "ans" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10587:Python:baseline
10,587
Python
train
baseline
def center_heptagonal_num ( n ) : return ( 7 * n * n - 7 * n + 2 ) // 2 def sum_center_heptagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += center_heptagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_center_heptagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10588:Python:baseline
10,588
Python
train
baseline
def Centered_Dodecagonal_num ( n ) : return 6 * n * ( n - 1 ) + 1 def sum_Centered_Dodecagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Centered_Dodecagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Centered_Dodecagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10589:Python:baseline
10,589
Python
train
baseline
def center_Octagonal_num ( n ) : return ( 4 * n * n - 4 * n + 1 ) def sum_center_Octagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += center_Octagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_center_Octagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10590:Python:baseline
10,590
Python
train
baseline
def Centered_decagonal_num ( n ) : return ( 5 * n * n - 5 * n + 1 ) def sum_Centered_decagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Centered_decagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Centered_decagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10592:Python:baseline
10,592
Python
train
baseline
def center_octadecagon_num ( n ) : return ( 9 * n * n - 9 * n + 1 ) def sum_center_octadecagon_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += center_octadecagon_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 3 print ( sum_center_octadecagon_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10593:Python:baseline
10,593
Python
train
baseline
def Centered_Pentadecagonal_num ( n ) : return ( 15 * n * n - 15 * n + 2 ) // 2 def sum_Centered_Pentadecagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Centered_Pentadecagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Centered_Pentadeca...
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10610:Python:baseline
10,610
Python
train
baseline
def Icosagonal_num ( n ) : return ( 18 * n * n - 16 * n ) // 2 def sum_Icosagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Icosagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Icosagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10611:Python:baseline
10,611
Python
train
baseline
def Centered_Pentagonal_num ( n ) : return ( 5 * n * n - 5 * n + 2 ) // 2 def sum_Centered_Pentagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Centered_Pentagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Centered_Pentagonal_num ( n ) )
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10612:Python:baseline
10,612
Python
train
baseline
def Centered_tridecagonal_num ( n ) : return ( 13 * n * ( n - 1 ) + 2 ) // 2 def sum_Centered_tridecagonal_num ( n ) : summ = 0 for i in range ( 1 , n + 1 ) : summ += Centered_tridecagonal_num ( i ) return summ if __name__ == ' _ _ main _ _ ' : n = 5 print ( sum_Centered_tridecagonal_num...
{ "index_key": [], "accumulator": [ "summ" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10627:Python:baseline
10,627
Python
train
baseline
def computePrime ( N ) : Prime = [ True ] * ( N + 1 ) Prime [ 0 ] = False Prime [ 1 ] = False i = 2 while i * i <= N : if ( Prime [ i ] ) : for j in range ( i * i , N , i ) : Prime [ j ] = False i += 1 return Prime def countSexyPairs ( arr , n ) : ...
{ "index_key": [ "i", "j" ], "accumulator": [ "count" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10691:Python:baseline
10,691
Python
train
baseline
def isAutoBiographyNum ( number ) : count = 0 ; NUM = str ( number ) ; size = len ( NUM ) ; for i in range ( size ) : position = ord ( NUM [ i ] ) - ord ( '0' ) ; count = 0 ; for j in range ( size ) : digit = ord ( NUM [ j ] ) - ord ( '0' ) ; if ( digit ==...
{ "index_key": [ "i", "j" ], "accumulator": [ "count", "current_length" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10700:Python:baseline
10,700
Python
train
baseline
MAX = 100000 graph = [ [ ] for i in range ( MAX + 1 ) ] Prime = [ True for i in range ( MAX + 1 ) ] height = [ 0 for i in range ( MAX + 1 ) ] def SieveOfEratosthenes ( ) : Prime [ 0 ] = Prime [ 1 ] = False i = 2 while i * i <= MAX : if ( Prime [ i ] ) : for j in range ( 2 * i , MAX , i )...
{ "index_key": [ "i", "j", "node" ], "accumulator": [], "iterator": [ "i", "j", "to" ], "boolean": [], "class_struct": [] }
10708:Python:baseline
10,708
Python
train
baseline
def reverse ( a ) : rev = 0 ; while ( a != 0 ) : r = a % 10 ; rev = rev * 10 + r ; a = a // 10 ; return ( rev ) ; def prime ( a ) : k = 0 ; for i in range ( 2 , a ) : if ( a % i == 0 ) : k = 1 ; break ; if ( k == 1 ) : return ( 0 ) ...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10733:Python:baseline
10,733
Python
train
baseline
def digit_sum ( n ) : sum = 0 while ( n > 0 ) : m = n % 10 ; sum = sum + m ; n = n // 10 return ( sum ) def reverse ( n ) : r = 0 while ( n != 0 ) : r = r * 10 r = r + n % 10 n = n // 10 return ( r ) def operation ( n ) : i = 1 count = 0 ...
{ "index_key": [], "accumulator": [ "count", "i" ], "iterator": [], "boolean": [], "class_struct": [] }
10734:Python:baseline
10,734
Python
train
baseline
def createSets ( N ) : if ( N <= 2 ) : print ( " - 1" ) ; return ; for i in range ( 2 , N + 1 , 2 ) : print ( i , end = " ▁ " ) ; print ( " " ) ; for i in range ( 1 , N + 1 , 2 ) : print ( i , end = " ▁ " ) ; if __name__ == ' _ _ main _ _ ' : N = 6 ; createSets ( ...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10741:Python:baseline
10,741
Python
train
baseline
graph = [ [ ] for i in range ( 100 ) ] weight = [ 0 ] * 100 ans = 0 def isPowerful ( n ) : while ( n % 2 == 0 ) : power = 0 ; while ( n % 2 == 0 ) : n /= 2 ; power += 1 ; if ( power == 1 ) : return False ; factor = 3 while ( factor * factor <= n ) ...
{ "index_key": [ "Node" ], "accumulator": [ "factor", "n", "power" ], "iterator": [ "to" ], "boolean": [], "class_struct": [] }
10752:Python:baseline
10,752
Python
train
baseline
def findNthNumber ( N ) : arr = [ 0 for i in range ( N + 1 ) ] q = [ ] for i in range ( 1 , 10 , 1 ) : q . append ( i ) for i in range ( 1 , N + 1 , 1 ) : arr [ i ] = q [ 0 ] q . remove ( q [ 0 ] ) if ( arr [ i ] % 10 != 0 ) : q . append ( arr [ i ] * 10 + arr...
{ "index_key": [ "N", "i" ], "accumulator": [ "q" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10754:Python:baseline
10,754
Python
train
baseline
def findUniqueElements ( arr , N , K ) : s = set ( ) for x in arr : s . add ( x ) arr_sum = sum ( arr ) set_sum = 0 for x in s : set_sum += x print ( ( K * set_sum - arr_sum ) // ( K - 1 ) ) if __name__ == ' _ _ main _ _ ' : arr = [ 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , ...
{ "index_key": [], "accumulator": [ "s", "set_sum" ], "iterator": [ "x" ], "boolean": [], "class_struct": [] }
10760:Python:baseline
10,760
Python
train
baseline
from math import sqrt def dydx ( x , y ) : return ( x - y ) / 2 def Gill ( x0 , y0 , x , h ) : n = ( ( x - x0 ) / h ) y = y0 for i in range ( 1 , int ( n + 1 ) , 1 ) : k1 = h * dydx ( x0 , y ) k2 = h * dydx ( x0 + 0.5 * h , y + 0.5 * k1 ) k3 = h * dydx ( x0 + 0.5 * h , y + 0.5 * ...
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10764:Python:baseline
10,764
Python
train
baseline
def PrintReverseOrder ( N ) : for i in range ( N , 0 , - 1 ) : print ( i , end = " ▁ " ) ; if __name__ == ' _ _ main _ _ ' : N = 5 ; PrintReverseOrder ( N ) ;
{ "index_key": [], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10769:Python:baseline
10,769
Python
train
baseline
from math import sqrt def ArithmeticMean ( A , B ) : return ( A + B ) / 2 def HarmonicMean ( A , B ) : return ( 2 * A * B ) / ( A + B ) def CheckArithmeticHarmonic ( arr , A , B , N ) : AM = ArithmeticMean ( A , B ) HM = HarmonicMean ( A , B ) Hash = set ( ) for i in range ( N ) : Hash ....
{ "index_key": [ "i" ], "accumulator": [ "Hash" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10774:Python:baseline
10,774
Python
train
baseline
def PythagoreanTriplet ( n ) : flag = 0 for a in range ( 1 , n , 1 ) : b = ( n * n - 2 * n * a ) // ( 2 * n - 2 * a ) c = n - a - b if ( a * a + b * b == c * c and b > 0 and c > 0 ) : print ( a , b , c ) flag = 1 break if ( flag == 0 ) : pr...
{ "index_key": [], "accumulator": [], "iterator": [ "a" ], "boolean": [], "class_struct": [] }
10777:Python:baseline
10,777
Python
train
baseline
from math import sqrt def check ( X , K ) : prime = 0 temp = X sqr = int ( sqrt ( X ) ) for i in range ( 2 , sqr + 1 , 1 ) : while ( temp % i == 0 ) : temp = temp // i prime += 1 if ( temp > 2 ) : prime += 1 if ( X == 1 ) : return False if ( pr...
{ "index_key": [], "accumulator": [ "prime" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10785:Python:baseline
10,785
Python
train
baseline
class Node : def __init__ ( self , key ) : self . key = key self . left = None self . right = None def newNode ( key ) : temp = Node ( key ) return temp N = 1000000 prime = [ ] def SieveOfEratosthenes ( ) : check = [ True for i in range ( N + 1 ) ] p = 2 while ( p * p <= ...
{ "index_key": [ "i", "p" ], "accumulator": [ "ct", "prime" ], "iterator": [ "i", "x" ], "boolean": [], "class_struct": [ "Node" ] }
10790:Python:baseline
10,790
Python
train
baseline
mod = 1000000007 ; def countSubsets ( a , n ) : answer = 0 ; for i in range ( 1 << n ) : bitwiseAND = - 1 ; bitwiseOR = 0 ; bitwiseXOR = 0 ; for j in range ( n ) : if ( i & ( 1 << j ) ) : if ( bitwiseAND == - 1 ) : bitwiseAND = a [ ...
{ "index_key": [ "j" ], "accumulator": [ "bitwiseAND", "bitwiseOR", "bitwiseXOR" ], "iterator": [ "i", "j" ], "boolean": [], "class_struct": [] }
10792:Python:baseline
10,792
Python
train
baseline
def count ( arr , N , K ) : count = 0 ans = 0 for i in range ( N ) : if ( arr [ i ] == K ) : count = count + 1 else : ans += ( count * ( count + 1 ) ) // 2 count = 0 ans = ans + ( count * ( count + 1 ) ) // 2 return ans if __name__ == ' _ _ main _ ...
{ "index_key": [ "i" ], "accumulator": [ "ans" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10820:Python:baseline
10,820
Python
train
baseline
def countOfGreaterElements ( arr , n ) : mp = { i : 0 for i in range ( 1000 ) } for i in range ( n ) : mp [ arr [ i ] ] += 1 x = 0 p = [ ] q = [ ] m = [ ] for key , value in mp . items ( ) : m . append ( [ key , value ] ) m = m [ : : - 1 ] for p in m : temp = ...
{ "index_key": [ "i" ], "accumulator": [ "m", "x" ], "iterator": [ "i", "key", "p", "value" ], "boolean": [], "class_struct": [] }
10852:Python:baseline
10,852
Python
train
baseline
import sys class Node ( ) : def __init__ ( self , data ) : self . data = data self . next = None def push ( head_ref , new_data ) : new_node = Node ( new_data ) new_node . next = head_ref head_ref = new_node return head_ref def largestElement ( head_ref ) : max = - sys . maxsize ...
{ "index_key": [], "accumulator": [ "hash", "prod", "sum" ], "iterator": [], "boolean": [], "class_struct": [ "Node" ] }
10862:Python:baseline
10,862
Python
train
baseline
def val ( c ) : if ( ord ( c ) >= ord ( '0' ) and ord ( c ) <= ord ( '9' ) ) : return ord ( c ) - ord ( '0' ) else : return ord ( c ) - ord ( ' A ' ) + 10 def toDeci ( str , base ) : Len = len ( str ) power = 1 num = 0 for i in range ( Len - 1 , - 1 , - 1 ) : if ( val ( s...
{ "index_key": [ "i" ], "accumulator": [ "num" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10884:Python:baseline
10,884
Python
train
baseline
fact = [ 0 ] * 21 def preCompute ( ) : fact [ 0 ] = 1 for i in range ( 1 , 18 ) : fact [ i ] = ( fact [ i - 1 ] * i ) def nextFactorial ( N ) : for i in range ( 21 ) : if N < fact [ i ] : print ( fact [ i ] ) break preCompute ( ) N = 120 nextFactorial ( N )
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10904:Python:baseline
10,904
Python
train
baseline
def findDistinctOddsumm ( n , k ) : if ( ( k * k ) <= n and ( n + k ) % 2 == 0 ) : val = 1 summ = 0 for i in range ( 1 , k ) : print ( val , end = " ▁ " ) summ += val val += 2 print ( n - summ ) else : print ( " NO " ) n = 100 k = 4 fin...
{ "index_key": [], "accumulator": [ "summ", "val" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10907:Python:baseline
10,907
Python
train
baseline
def checkArray ( a , b , n ) : operations = 0 ; i = 0 ; while ( i < n ) : if ( a [ i ] - b [ i ] == 0 ) : i += 1 ; continue ; diff = a [ i ] - b [ i ] ; i += 1 ; while ( i < n and a [ i ] - b [ i ] == diff ) : i += 1 ; operations +=...
{ "index_key": [ "i" ], "accumulator": [ "operations" ], "iterator": [], "boolean": [], "class_struct": [] }
10925:Python:baseline
10,925
Python
train
baseline
import math def insertPF ( primeFact , fact ) : if ( fact in primeFact ) : primeFact [ fact ] += 1 else : primeFact [ fact ] = 1 return primeFact def primeFactors ( n ) : primeFact = { } while ( n % 2 == 0 ) : primeFact = insertPF ( primeFact , 2 ) n = n // 2 for ...
{ "index_key": [ "fact", "x" ], "accumulator": [], "iterator": [ "i", "x" ], "boolean": [], "class_struct": [] }
10941:Python:baseline
10,941
Python
train
baseline
import math def ways ( n ) : if n < 3 : return 0 c2 = 0 c1 = n - 3 l = c1 + 1 s = 0 exp_c2 = c1 / 2 while exp_c2 >= c2 : f1 = math . factorial ( l ) f2 = math . factorial ( c1 ) f3 = math . factorial ( c2 ) s += f1 // ( f2 * f3 ) c2 += 1 ...
{ "index_key": [], "accumulator": [ "c1", "c2", "l", "s" ], "iterator": [], "boolean": [], "class_struct": [] }
10958:Python:baseline
10,958
Python
train
baseline
m = { } ; def precompute ( ) : fact = 1 ; for i in range ( 1 , 19 ) : fact = fact * i ; m [ fact ] = i ; if __name__ == " _ _ main _ _ " : precompute ( ) ; K = 120 ; print ( m [ K ] ) ; K = 6 ; print ( m [ K ] ) ;
{ "index_key": [ "K", "fact" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
10997:Python:baseline
10,997
Python
train
baseline
N = 100005 mod = ( 10 ** 9 + 7 ) factorial = [ 0 ] * N modinverse = [ 0 ] * N def factorialfun ( ) : factorial [ 0 ] = 1 for i in range ( 1 , N ) : factorial [ i ] = ( factorial [ i - 1 ] * i ) % mod def modinversefun ( ) : modinverse [ N - 1 ] = pow ( factorial [ N - 1 ] , mod - 2 , mod ) % mod ...
{ "index_key": [ "i", "n", "r" ], "accumulator": [ "ans" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11006:Python:baseline
11,006
Python
train
baseline
def countNumber ( N , S ) : countElements = 0 ; currSum = 0 ; while ( currSum <= S ) : currSum += N ; N = N - 1 ; countElements = countElements + 1 ; return countElements ; N = 5 ; S = 11 ; count = countNumber ( N , S ) ; print ( count ) ;
{ "index_key": [], "accumulator": [ "currSum" ], "iterator": [], "boolean": [], "class_struct": [] }
11009:Python:baseline
11,009
Python
train
baseline
import sys INT_MAX = sys . maxsize ; def countDistinct ( n ) : arr = [ 0 ] * 10 ; count = 0 ; while ( n != 0 ) : r = int ( n % 10 ) ; arr [ r ] = 1 ; n //= 10 ; for i in range ( 10 ) : if ( arr [ i ] != 0 ) : count += 1 ; return count ; def countDigit ( n ...
{ "index_key": [ "i", "r" ], "accumulator": [ "c", "count", "n" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11011:Python:baseline
11,011
Python
train
baseline
mod = 10 ** 9 + 7 N = 1000005 lpf = [ 0 for i in range ( N ) ] def least_prime_factor ( ) : for i in range ( 1 , N ) : lpf [ i ] = i for i in range ( 2 , N ) : if ( lpf [ i ] == i ) : for j in range ( i * 2 , N , i ) : if ( lpf [ j ] == j ) : lpf [...
{ "index_key": [ "i", "j", "temp", "x" ], "accumulator": [], "iterator": [ "i", "j", "x" ], "boolean": [], "class_struct": [] }
11029:Python:baseline
11,029
Python
train
baseline
def findNumberOfEvenCells ( n , q , size ) : row = [ 0 ] * n ; col = [ 0 ] * n for i in range ( size ) : x = q [ i ] [ 0 ] ; y = q [ i ] [ 1 ] ; row [ x - 1 ] += 1 ; col [ y - 1 ] += 1 ; r1 = 0 ; r2 = 0 ; c1 = 0 ; c2 = 0 ; for i in range ( n ) : if...
{ "index_key": [ "i" ], "accumulator": [ "c1", "c2", "r1", "r2" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11043:Python:baseline
11,043
Python
train
baseline
from math import ceil , sqrt def FermatFactors ( n ) : if ( n <= 0 ) : return [ n ] if ( n & 1 ) == 0 : return [ n / 2 , 2 ] a = ceil ( sqrt ( n ) ) if ( a * a == n ) : return [ a , a ] while ( True ) : b1 = a * a - n b = int ( sqrt ( b1 ) ) if ( b * b...
{ "index_key": [], "accumulator": [ "a" ], "iterator": [], "boolean": [], "class_struct": [] }
11044:Python:baseline
11,044
Python
train
baseline
def findNums ( arr , n ) : S = 0 ; X = 0 ; for i in range ( n ) : S += arr [ i ] ; X ^= arr [ i ] ; print ( X , X + S ) ; if __name__ == " _ _ main _ _ " : arr = [ 1 , 7 ] ; n = len ( arr ) ; findNums ( arr , n ) ;
{ "index_key": [ "i" ], "accumulator": [ "S", "X" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11053:Python:baseline
11,053
Python
train
baseline
from math import gcd as __gcd def findLargest ( arr , n ) : gcd = 0 for i in range ( n ) : gcd = __gcd ( arr [ i ] , gcd ) return gcd if __name__ == ' _ _ main _ _ ' : arr = [ 3 , 6 , 9 ] n = len ( arr ) print ( findLargest ( arr , n ) )
{ "index_key": [ "i" ], "accumulator": [], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11061:Python:baseline
11,061
Python
train
baseline
def digitSum ( n ) : sum = 0 ; while ( n > 0 ) : sum += ( n % 10 ) ; n //= 10 ; return sum ; def isPalindrome ( n ) : divisor = 1 ; while ( n // divisor >= 10 ) : divisor *= 10 ; while ( n != 0 ) : leading = n // divisor ; trailing = n % 10 ; if ( ...
{ "index_key": [], "accumulator": [ "divisor", "n", "sum" ], "iterator": [], "boolean": [], "class_struct": [] }
11071:Python:baseline
11,071
Python
train
baseline
N = 100005 mod = ( int ) ( 1e9 + 7 ) factorial = [ 0 ] * N ; modinverse = [ 0 ] * N ; def power ( a , m1 ) : if ( m1 == 0 ) : return 1 ; elif ( m1 == 1 ) : return a ; elif ( m1 == 2 ) : return ( a * a ) % mod ; elif ( m1 & 1 ) : return ( a * power ( power ( a , m1 // 2 ) ...
{ "index_key": [ "i", "n", "r" ], "accumulator": [ "ans" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
11086:Python:baseline
11,086
Python
train
baseline
def findNthDigit ( p , q , N ) : while ( N > 0 ) : N -= 1 ; p *= 10 ; res = p // q ; p %= q ; return res ; if __name__ == " _ _ main _ _ " : p = 1 ; q = 2 ; N = 1 ; print ( findNthDigit ( p , q , N ) ) ;
{ "index_key": [], "accumulator": [ "N", "p" ], "iterator": [], "boolean": [], "class_struct": [] }
11093:Python:baseline
11,093
Python
train
baseline
def sumArr ( arr , n ) : sum = 0 ; for i in range ( n ) : sum += arr [ i ] ; return sum ; def sumModArr ( arr , n ) : subSum = arr [ n - 1 ] ; for i in range ( n - 2 , - 1 , - 1 ) : curr = arr [ i ] ; arr [ i ] -= subSum ; subSum += curr ; return sumArr ( arr , n ...
{ "index_key": [ "i" ], "accumulator": [ "subSum", "sum" ], "iterator": [ "i" ], "boolean": [], "class_struct": [] }
End of preview. Expand in Data Studio

XLCoST Variable Roles

Program-level code with structurally derived variable-role labels for probing how code LLMs represent variables. Built from XLCoST (Zhu et al., 2022).

Five roles, labeled from AST/structural analysis — never from the variable's name — so probes trained on these labels must rely on context:

Role Definition
index_key used as an array index or dict key (arr[i], d[key])
accumulator target of +=-style updates or .append()-style calls inside a loop
iterator bound in a loop header (for x in …, for (int i = …)
boolean assigned a boolean literal
class_struct declared class/struct name

Configs

python_perturbations — every Python program under 10 naming strategies: baseline, random_nouns, single_chars (a, b, c…), all_same (everything → x), numeric_vars (v1, v2…), and misleading_<role> for each role (role variables get counter-role names, all other variables get role-looking names). Role labels are re-extracted from the transformed code.

multilingual_baseline — original programs in all 7 XLCoST languages (C++, Java, Python, C#, Javascript, PHP, C) with role labels, for cross-language transfer experiments.

Fields

{
  "id": "10005:Python:baseline",
  "problem_id": 10005,
  "language": "Python",
  "split": "train",
  "strategy": "baseline",
  "code": "def maxPresum(a, b): ...",
  "roles": {
    "index_key": ["i"],
    "accumulator": ["X"],
    "iterator": ["i"],
    "boolean": [],
    "class_struct": []
  }
}

Rows store code plus role-name sets rather than token-level labels, so the dataset is model-agnostic: map names to token labels with whatever tokenizer you are probing (reference implementation in the companion pipeline's probing.label_tokens).

Labeling method

Python roles come from the ast module; the other six languages use regex extractors (subscripts, augmented assignments/increments/collector calls, loop headers, boolean assignments, class/struct declarations) with per-language keyword exclusion. PHP identifiers are labeled without the $ sigil. Programs with no role-labeled variable are dropped.

Provenance and credits

Source programs are the program-level nl2code_search release of XLCoST, which pairs GeeksforGeeks solutions across 7 languages. All credit for the underlying corpus goes to the XLCoST authors; this dataset adds only the role labels and the renaming variants. XLCoST is released under the Apache 2.0 license, as is this derivative.

@article{zhu2022xlcost,
  title   = {XLCoST: A Benchmark Dataset for Cross-lingual Code Intelligence},
  author  = {Zhu, Ming and Jain, Aneesh and Suresh, Karthik and
             Ravindran, Roshan and Tipirneni, Sindhu and Reddy, Chandan K.},
  journal = {arXiv preprint arXiv:2206.08474},
  year    = {2022}
}

If you use the role labels or perturbations, please also cite this dataset.

Known limitations

  • Non-Python role labels are regex-derived and inherit that noise (e.g. ++ in a for-header counts toward accumulator, matching the original experimental protocol).
  • XLCoST code is competitive-programming style; identifier names are already short and partially uninformative, which attenuates renaming effects.
  • Renaming is whole-word textual substitution with keyword/builtin protection, not scope-aware alpha-renaming.
  • Under all_same, distinct variables collapse to one name, so exclusion-based roles (notably accumulator, which excludes loop and index variables) survive in far fewer programs; this mirrors the original experimental protocol, where labels are re-extracted after renaming.
Downloads last month
39

Paper for dhyuti-n/xlcost-variable-roles