dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <algorithm>
#include <bits/stdc++.h>
#define limit  1000000000
using namespace std ; long long F ( long long N ) { string str = to_string ( N ) ; long long sum = 0 ; for ( long long i = 0 ; i < str . size ( ) ; i ++ ) { long long val = int ( str [ i ] - '0' ) ; sum += val * val * val ; } return sum ; } long long findDestination ( long long N ) { set < long long > s ; long long prev = N , next ; s . insert ( N ) ; while ( N <= limit ) { next = F ( N ) ; auto it = s . find ( next ) ; if ( it != s . end ( ) ) { return next ; } prev = next ; s . insert ( prev ) ; N = next ; } return next ; } void digitCubeLimit ( long long N ) { if ( N < 0 ) cout << " N ▁ cannot ▁ be ▁ negative STRNEWLINE " ; else { long long ans = findDestination ( N ) ; if ( ans > limit ) cout << " Limit ▁ exceeded STRNEWLINE " ; else if ( ans == F ( ans ) ) { cout << N ; cout << " ▁ reaches ▁ to ▁ a " << " ▁ fixed ▁ point : ▁ " ; cout << ans ; } else { cout << N ; cout << " ▁ reaches ▁ to ▁ a " << " ▁ limit ▁ cycle : ▁ " ; cout << ans ; } } } int main ( ) { long long N = 3 ; digitCubeLimit ( N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTuples ( int arr [ ] , int N ) { int ans = 0 , val = 0 ; unordered_map < int , int > freq ; for ( int j = 0 ; j < N - 2 ; j ++ ) { val = 0 ; for ( int l = j + 1 ; l < N ; l ++ ) { if ( arr [ j ] == arr [ l ] ) { ans += val ; } val += freq [ arr [ l ] ] ; } freq [ arr [ j ] ] ++ ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 1 , 2 , 2 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countTuples ( arr , N ) ; return 0 ; }

Index/key variables: j, l
Accumulator variables: ans, j, l, stdc, val
Iterator variables: j, l
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperation ( int arr [ ] , int N ) { int minOp = INT_MIN ; int minNeg = 0 , maxPos = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { if ( arr [ i ] < minNeg ) minNeg = arr [ i ] ; } else { if ( arr [ i ] > maxPos ) maxPos = arr [ i ] ; } } return abs ( minNeg ) + maxPos ; } int main ( ) { int arr [ ] = { 1 , 3 , 4 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minOperation ( arr , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int GCD ( int a , int b ) { if ( b == 0 ) { return a ; } return GCD ( b , a % b ) ; } void GcdPair ( vector < pair < int , int > > arr , int k ) { int lo = 0 , hi = arr . size ( ) - 1 , mid ; pair < int , int > ans ; ans = make_pair ( -1 , 0 ) ; while ( lo <= hi ) { mid = lo + ( hi - lo ) / 2 ; if ( GCD ( arr [ mid ] . first , arr [ mid ] . second ) > k ) { ans = arr [ mid ] ; hi = mid - 1 ; } else lo = mid + 1 ; } if ( ans . first == -1 ) cout << " - 1" ; else cout << " ( ▁ " << ans . first << " , ▁ " << ans . second << " ▁ ) " ; return ; } int main ( ) { vector < pair < int , int > > arr = { { 3 , 6 } , { 15 , 30 } , { 25 , 75 } , { 30 , 120 } } ; int K = 16 ; GcdPair ( arr , K ) ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void isPossible ( int arr [ ] , int N ) { int mn = INT_MAX ; int B [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { mn = min ( mn , arr [ i ] ) ; B [ i ] = arr [ i ] ; } sort ( arr , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != B [ i ] ) { if ( B [ i ] % mn != 0 ) { cout << " No " ; return ; } } } cout << " Yes " ; return ; } int main ( ) { int N = 6 ; int arr [ ] = { 4 , 3 , 6 , 6 , 2 , 9 } ; isPossible ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void addEdge ( vector < int > adj [ ] , int u , int v ) { adj [ u ] . push_back ( v ) ; adj [ v ] . push_back ( u ) ; } void DFSUtil ( int u , vector < int > adj [ ] , vector < bool > & visited , int & componentMin , int & componentMax ) { visited [ u ] = true ; componentMax = max ( componentMax , u ) ; componentMin = min ( componentMin , u ) ; for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) if ( visited [ adj [ u ] [ i ] ] == false ) DFSUtil ( adj [ u ] [ i ] , adj , visited , componentMin , componentMax ) ; } bool isValid ( vector < pair < int , int > > & v ) { int MAX = -1 ; bool ans = 0 ; for ( auto i : v ) { if ( i . first <= MAX ) { ans = 1 ; } MAX = max ( MAX , i . second ) ; } return ( ans == 0 ? 1 : 0 ) ; } void DFS ( vector < int > adj [ ] , int V ) { std :: vector < pair < int , int > > v ; vector < bool > visited ( V , false ) ; for ( int u = 1 ; u <= V ; u ++ ) { if ( visited [ u ] == false ) { int componentMax = u ; int componentMin = u ; DFSUtil ( u , adj , visited , componentMin , componentMax ) ; v . push_back ( { componentMin , componentMax } ) ; } } bool check = isValid ( v ) ; if ( check ) cout << " Yes " ; else cout << " No " ; return ; } int main ( ) { int N = 4 , K = 3 ; vector < int > adj [ N + 1 ] ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 2 , 3 ) ; addEdge ( adj , 3 , 4 ) ; DFS ( adj , N ) ; return 0 ; }

Index/key variables: i, u, v
Accumulator variables: i, stdc, u
Iterator variables: i, u
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkArrInStack ( stack < int > s , int arr [ ] , int n ) { map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; while ( ! s . empty ( ) ) { int poppedEle = s . top ( ) ; s . pop ( ) ; if ( freq [ poppedEle ] ) freq [ poppedEle ] -= 1 ; } if ( freq . size ( ) == 0 ) return 0 ; return 1 ; } int main ( ) { stack < int > s ; s . push ( 10 ) ; s . push ( 20 ) ; s . push ( 30 ) ; s . push ( 40 ) ; s . push ( 50 ) ; int arr [ ] = { 20 , 30 } ; int n = sizeof arr / sizeof arr [ 0 ] ; if ( checkArrInStack ( s , arr , n ) ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; }

Index/key variables: i, poppedEle
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longDelSub ( string str1 , string str2 ) { int N = str1 . size ( ) ; int M = str2 . size ( ) ; int prev_pos = 0 ; int pos [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { int index = prev_pos ; while ( index < N && str1 [ index ] != str2 [ i ] ) { index ++ ; } pos [ i ] = index ; prev_pos = index + 1 ; } int res = N - prev_pos ; prev_pos = N - 1 ; for ( int i = M - 1 ; i >= 0 ; i -- ) { int index = prev_pos ; while ( index >= 0 && str1 [ index ] != str2 [ i ] ) { index -- ; } if ( i != 0 ) { res = max ( res , index - pos [ i - 1 ] - 1 ) ; } prev_pos = index - 1 ; } res = max ( res , prev_pos + 1 ) ; return res ; } int main ( ) { string str1 = " GeeksforGeeks " ; string str2 = " forks " ; cout << longDelSub ( str1 , str2 ) ; return 0 ; }

Index/key variables: M, i, index
Accumulator variables: i, index, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void print_substring ( string s ) { int n = s . size ( ) ; string str = " " ; vector < int > ans ; if ( n == 0 ) { cout << " - 1" ; return ; } vector < int > last_pos ( 26 , -1 ) ; for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s [ i ] - ' a ' ] == -1 ) { last_pos [ s [ i ] - ' a ' ] = i ; } } int minp = -1 ; for ( int i = 0 ; i < n ; ++ i ) { int lp = last_pos [ s [ i ] - ' a ' ] ; minp = max ( minp , lp ) ; if ( i == minp ) { str += s [ i ] ; cout << str << ' ▁ ' ; minp = -1 ; str = " " ; } else { str += s [ i ] ; } } } int main ( ) { string S = " ababcbacadefegdehijhklij " ; print_substring ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc, str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void partitionString ( string s ) { int n = s . size ( ) ; vector < int > ans ; if ( n == 0 ) { cout << " - 1" ; return ; } vector < int > last_pos ( 26 , -1 ) ; for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s [ i ] - ' a ' ] == -1 ) { last_pos [ s [ i ] - ' a ' ] = i ; } } int minp = -1 , plen = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int lp = last_pos [ s [ i ] - ' a ' ] ; minp = max ( minp , lp ) ; ++ plen ; if ( i == minp ) { ans . push_back ( plen ) ; minp = -1 ; plen = 0 ; } } for ( int i = 0 ; i < ( int ) ans . size ( ) ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } int main ( ) { string str = " acbbcc " ; partitionString ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( string S ) { int count_0 = 0 , count_1 = 0 ; int prev = -1 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S [ i ] == '0' ) count_0 ++ ; else if ( S [ i ] == '1' ) count_1 ++ ; } for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S [ i ] == ' * ' ) continue ; else if ( S [ i ] == '0' && prev == -1 ) { count_0 = count_0 + i ; prev = i ; } else if ( S [ i ] == '1' && prev == -1 ) { prev = i ; } else if ( S [ prev ] == '1' && S [ i ] == '0' ) { count_0 = count_0 + ( i - prev - 1 ) / 2 ; count_1 = count_1 + ( i - prev - 1 ) / 2 ; prev = i ; } else if ( S [ prev ] == '1' && S [ i ] == '1' ) { count_1 = count_1 + ( i - prev - 1 ) ; prev = i ; } else if ( S [ prev ] == '0' && S [ i ] == '1' ) prev = i ; else if ( S [ prev ] == '0' && S [ i ] == '0' ) { count_0 = count_0 + ( i - prev - 1 ) ; prev = i ; } } if ( count_0 > count_1 ) cout << "0" ; else if ( count_1 > count_0 ) cout << "1" ; else { cout << -1 ; } } int main ( ) { string str = " * *0 * * 1 * * *0" ; solve ( str ) ; return 0 ; }

Index/key variables: i, prev
Accumulator variables: count_0, count_1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minFirstTerm ( int X , int diff , int N ) { int first_term ; int low = 0 , high = N ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( X - mid * diff > 0 ) { first_term = X - mid * diff ; low = mid + 1 ; } else high = mid - 1 ; } return first_term ; } void printAP ( int N , int X , int Y ) { if ( X > Y ) swap ( X , Y ) ; int maxDiff = Y - X ; int first_term = INT_MAX , diff ; for ( int i = 1 ; i * i <= maxDiff ; i ++ ) { if ( maxDiff % i == 0 ) { int diff1 = i ; int diff2 = maxDiff / diff1 ; int terms1 = diff2 + 1 ; int terms2 = diff1 + 1 ; int first_term1 = minFirstTerm ( X , diff1 , N - terms1 ) ; int first_term2 = minFirstTerm ( X , diff2 , N - terms2 ) ; if ( first_term1 < first_term ) { first_term = first_term1 ; diff = diff1 ; } if ( first_term2 < first_term ) { first_term = first_term2 ; diff = diff2 ; } } } for ( int i = 0 ; i < N ; i ++ ) { cout << first_term << " ▁ " ; first_term += diff ; } } int main ( ) { int N = 5 , X = 10 , Y = 15 ; printAP ( N , X , Y ) ; return 0 ; }

Accumulator variables: first_term, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isCubeSum ( int n ) { for ( int i = 1 ; i * i * i <= n ; i ++ ) { if ( i * i * i + ( i + 1 ) * ( i + 1 ) * ( i + 1 ) == n ) return true ; } return false ; } int main ( ) { int n = 35 ; if ( isCubeSum ( n ) ) cout << " Yes " ; else cout << " No " ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isSumCube ( int N ) { int a = cbrt ( N ) ; int b = a - 1 ; return ( ( a * a * a + b * b * b ) == N ) ; } int main ( ) { int i = 35 ; if ( isSumCube ( i ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxweight ( int s , int e , unordered_map < int , int > & pre ) { if ( s == e ) return 0 ; int ans = 0 ; for ( int i = s ; i < e ; i ++ ) { int left = pre [ i ] - pre [ s - 1 ] ; int right = pre [ e ] - pre [ i ] ; if ( left < right ) ans = max ( ans , left + maxweight ( s , i , pre ) ) ; if ( left == right ) { ans = max ( { ans , left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) } ) ; } if ( left > right ) ans = max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; } return ans ; } void maxSum ( vector < int > arr ) { unordered_map < int , int > pre ; pre [ -1 ] = 0 ; pre [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < arr . size ( ) ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } cout << maxweight ( 0 , arr . size ( ) - 1 , pre ) ; } int main ( ) { vector < int > arr = { 6 , 2 , 3 , 4 , 5 , 5 } ; maxSum ( arr ) ; return 0 ; }

Index/key variables: e, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string largestTimeFromDigits ( vector < int > & A ) { map < int , int > mp1 , mp2 ; for ( auto x : A ) { mp1 [ x ] ++ ; } mp2 = mp1 ; int hr = 23 , m = 59 , s = 59 ; while ( hr >= 0 ) { int h0 = hr / 10 , h1 = hr % 10 ; int m0 = m / 10 , m1 = m % 10 ; int s0 = s / 10 , s1 = s % 10 ; int p = 0 ; vector < int > arr { h0 , h1 , m0 , m1 , s0 , s1 } ; for ( auto & it : arr ) { if ( mp1 [ it ] > 0 ) { mp1 [ it ] -- ; } else { p = 1 ; } } if ( p == 0 ) { string s = " " ; s = to_string ( h0 ) + to_string ( h1 ) ; s += ' : ' + to_string ( m0 ) + to_string ( m1 ) ; s += ' : ' + to_string ( s0 ) + to_string ( s1 ) ; return s ; } mp1 = mp2 ; if ( s == 0 ) { s = 59 ; m -- ; } else if ( m < 0 ) { m = 59 ; hr -- ; } if ( s > 0 ) { s -- ; } } return " - 1" ; } int main ( ) { vector < int > v = { 0 , 2 , 1 , 9 , 3 , 2 } ; cout << largestTimeFromDigits ( v ) ; }

Index/key variables: it, x
Accumulator variables: hr, m, s, stdc
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; string palindromePrefix ( string S ) { int n = S . size ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { string curr = S . substr ( 0 , i + 1 ) ; int l = 0 , r = curr . size ( ) - 1 ; bool is_palindrome = 1 ; while ( l < r ) { if ( curr [ l ] != curr [ r ] ) { is_palindrome = 0 ; break ; } l ++ ; r -- ; } if ( is_palindrome ) return curr ; } return " " ; } string maxPalindrome ( string S ) { int n = S . size ( ) ; if ( n <= 1 ) { return S ; } string pre = " " , suff = " " ; int i = 0 , j = n - 1 ; while ( S [ i ] == S [ j ] && i < j ) { i ++ ; j -- ; } i -- ; j ++ ; pre = S . substr ( 0 , i + 1 ) ; suff = S . substr ( j ) ; if ( j - i == 1 ) { return pre + suff ; } if ( j - i == 2 ) { string mid_char = S . substr ( i + 1 , 1 ) ; return pre + mid_char + suff ; } string rem_str = S . substr ( i + 1 , j - i - 1 ) ; string pre_of_rem_str = palindromePrefix ( rem_str ) ; reverse ( rem_str . begin ( ) , rem_str . end ( ) ) ; string suff_of_rem_str = palindromePrefix ( rem_str ) ; if ( pre_of_rem_str . size ( ) >= suff_of_rem_str . size ( ) ) { return pre + pre_of_rem_str + suff ; } else { return pre + suff_of_rem_str + suff ; } } int main ( ) { string S = " geeksforskeeg " ; cout << maxPalindrome ( S ) ; return 0 ; }

Index/key variables: i, j, l, r
Accumulator variables: i, j, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countNumEnds ( int A , int L , int R ) { int temp , count = 0 , digits ; int cycle ; digits = log10 ( A ) + 1 ; temp = pow ( 10 , digits ) ; cycle = temp ; while ( temp <= R ) { if ( temp >= L ) count ++ ; temp += cycle ; } cout << count ; } int main ( ) { int A = 2 , L = 2 , R = 20 ; countNumEnds ( A , L , R ) ; }

Accumulator variables: count, stdc, temp
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( string s ) { int len = s . length ( ) ; int result = 0 ; for ( int i = 0 ; i < len / 2 ; i ++ ) { int D1 = max ( s [ i ] , s [ len - 1 - i ] ) - min ( s [ i ] , s [ len - 1 - i ] ) ; int D2 = 26 - D1 ; result += min ( D1 , D2 ) ; } return result ; } int main ( ) { string s = " abccdb " ; cout << minOperations ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool findFactor ( int value , unordered_set < int > & factors ) { factors . insert ( value ) ; for ( int i = 2 ; i * i <= value ; i ++ ) { if ( value % i == 0 ) { if ( value / i == i ) { if ( factors . find ( i ) != factors . end ( ) ) { return true ; } else { factors . insert ( i ) ; } } else { if ( factors . find ( i ) != factors . end ( ) || factors . find ( value / i ) != factors . end ( ) ) { return true ; } else { factors . insert ( i ) ; factors . insert ( value / i ) ; } } } } return false ; } bool allCoprime ( int A [ ] , int n ) { bool all_coprime = true ; unordered_set < int > factors ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] == 1 ) continue ; if ( findFactor ( A [ i ] , factors ) ) { all_coprime = false ; break ; } } return all_coprime ; } int main ( ) { int A [ ] = { 3 , 5 , 11 , 7 , 19 } ; int arr_size = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( allCoprime ( A , arr_size ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: all_coprime
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count ( int arr [ ] , int n , int value ) ; double countSubSequence ( int arr [ ] , int n ) { int maximum = * max_element ( arr , arr + n ) ; int minimum = * min_element ( arr , arr + n ) ; if ( maximum == minimum ) return pow ( 2 , n ) - 1 ; int i = count ( arr , n , maximum ) ; int j = count ( arr , n , minimum ) ; double res = ( pow ( 2 , i ) - 1 ) * ( pow ( 2 , j ) - 1 ) * pow ( 2 , n - i - j ) ; return res ; } int count ( int arr [ ] , int n , int value ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == value ) sum ++ ; return sum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSubSequence ( arr , n ) << endl ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int transformSubsequence ( int n , int m , vector < int > A , vector < int > B ) { if ( B . size ( ) == 0 ) return n ; vector < vector < int > > dp ( n + 1 , vector < int > ( m + 1 , 0 ) ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < m + 1 ; j ++ ) { if ( i == 0 or j == 0 ) dp [ i ] [ j ] = 0 ; else if ( A [ i - 1 ] == B [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return n - dp [ n ] [ m ] ; } int main ( ) { int N = 5 ; int M = 6 ; vector < int > A = { 1 , 2 , 3 , 4 , 5 } ; vector < int > B = { 2 , 5 , 6 , 4 , 9 , 12 } ; cout << transformSubsequence ( N , M , A , B ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int checkForPerfectSquare ( vector < int > arr , int i , int j ) { int mid , sum = 0 ; for ( int m = i ; m <= j ; m ++ ) { sum += arr [ m ] ; } int low = 0 , high = sum / 2 ; while ( low <= high ) { mid = low + ( high - low ) / 2 ; if ( mid * mid == sum ) { return mid ; } else if ( mid * mid > sum ) { high = mid - 1 ; } else { low = mid + 1 ; } } return -1 ; } int main ( ) { vector < int > arr ; arr = { 2 , 19 , 33 , 48 , 90 , 100 } ; int L = 1 , R = 3 ; cout << checkForPerfectSquare ( arr , L , R ) ; return 0 ; }

Index/key variables: m
Accumulator variables: m, stdc, sum
Iterator variables: m
C++ program:
#include <iostream>
using namespace std ; int calcSubarray ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { bool flag = true ; int comm_diff = A [ i + 1 ] - A [ i ] ; for ( int k = i ; k < j ; k ++ ) { if ( A [ k + 1 ] - A [ k ] == comm_diff ) { continue ; } else { flag = false ; break ; } } if ( flag ) { count ++ ; } } } return count ; } int main ( ) { int A [ 5 ] = { 8 , 7 , 4 , 1 , 0 } ; int N = sizeof ( A ) / sizeof ( int ) ; cout << calcSubarray ( A , N ) ; }

Index/key variables: i, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSumSubarray ( int arr [ ] , int n ) { int i = 0 , j = 1 ; set < int > set ; set . insert ( arr [ 0 ] ) ; int sum = arr [ 0 ] ; int maxsum = sum ; while ( i < n - 1 && j < n ) { const bool is_in = set . find ( arr [ j ] ) != set . end ( ) ; if ( ! is_in ) { sum = sum + arr [ j ] ; maxsum = max ( sum , maxsum ) ; set . insert ( arr [ j ++ ] ) ; } else { sum -= arr [ i ] ; set . erase ( arr [ i ++ ] ) ; } } return maxsum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 , 5 } ; int ans = maxSumSubarray ( arr , 5 ) ; cout << ( ans ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_numbers ( int L , int R ) { int ans = 0 ; for ( int n = L ; n <= R ; n ++ ) { int no_of_bits = log2 ( n ) + 1 ; int no_of_set_bits = __builtin_popcount ( n ) ; if ( no_of_bits - no_of_set_bits == 1 ) { ans ++ ; } } return ans ; } int main ( ) { int L = 4 , R = 9 ; cout << count_numbers ( L , R ) ; return 0 ; }

Accumulator variables: ans, n, stdc
Iterator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_numbers ( int L , int R ) { int ans = 0 ; int LogR = log2 ( R ) + 1 ; for ( int zero_bit = 0 ; zero_bit < LogR ; zero_bit ++ ) { int cur = 0 ; for ( int j = 0 ; j < zero_bit ; j ++ ) { cur |= ( 1LL << j ) ; } for ( int j = zero_bit + 1 ; j < LogR ; j ++ ) { cur |= ( 1LL << j ) ; if ( cur >= L && cur <= R ) { ans ++ ; } } } return ans ; } int main ( ) { long long L = 4 , R = 9 ; cout << count_numbers ( L , R ) ; return 0 ; }

Accumulator variables: ans, cur, j, stdc, zero_bit
Iterator variables: j, zero_bit
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( string s ) { int sum = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < s . size ( ) ; j ++ ) { if ( s [ i ] == s [ j ] ) { sum += ( j - i ) ; } } } return sum ; } int main ( ) { string s = " ttt " ; cout << findSum ( s ) << endl ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countElements ( int a [ ] , int n ) { int cnt [ n + 1 ] = { 0 } ; memset ( cnt , 0 , sizeof ( cnt ) ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ++ cnt [ a [ i ] ] ; } for ( int l = 0 ; l < n ; ++ l ) { int sum = 0 ; for ( int r = l ; r < n ; ++ r ) { sum += a [ r ] ; if ( l == r ) continue ; if ( sum <= n ) { ans += cnt [ sum ] ; cnt [ sum ] = 0 ; } } } return ans ; } int main ( ) { int a [ ] = { 1 , 1 , 1 , 1 , 1 } ; int N = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << countElements ( a , N ) ; }

Index/key variables: i, r, sum
Accumulator variables: ans, i, stdc, sum
Iterator variables: i, l, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxGCD ( int n ) { int maxHcf = INT_MIN ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { maxHcf = max ( maxHcf , __gcd ( i , j ) ) ; } } return maxHcf ; } int main ( ) { int n = 4 ; cout << maxGCD ( n ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxGCD ( int n ) { return ( n / 2 ) ; } int main ( ) { int n = 4 ; cout << maxGCD ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printSequence ( vector < int > & A , int n , int k ) { unordered_map < int , set < int > > mp ; vector < int > sol ; for ( int x : A ) sol . push_back ( x ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . find ( sol [ i ] ) == mp . end ( ) || mp [ sol [ i ] ] . size ( ) == 0 ) { mp [ sol [ i ] ] . insert ( i ) ; } else { auto idxx = mp [ sol [ i ] ] . begin ( ) ; int idx = * idxx ; mp [ sol [ i ] ] . erase ( idxx ) ; sol [ idx ] += k ; mp [ sol [ idx ] ] . insert ( idx ) ; mp [ sol [ i ] ] . insert ( i ) ; } } for ( int x : sol ) { cout << x << " ▁ " ; } } int main ( ) { int N = 5 ; int K = 6 ; vector < int > A = { 1 , 4 , 1 , 1 , 4 } ; printSequence ( A , N , K ) ; }

Index/key variables: i, idx
Accumulator variables: i, stdc
Iterator variables: i, x