dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumReverse ( string s , int n ) { int k = 0 , l = 0 ; int sum1 = 0 , sum0 = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == '1' ) sum1 ++ ; else sum0 ++ ; if ( s [ i ] == s [ i - 1 ] && s [ i ] == '0' ) k ++ ; else if ( s [ i ] == s [ i - 1 ] && s [ i ] == '1' ) l ++ ; } if ( s [ 0 ] == '1' ) sum1 ++ ; sum0 ++ ; if ( abs ( sum1 - sum0 ) > 1 ) return -1 ; return max ( k , l ) ; } int main ( ) { string S = "10001" ; int N = S . size ( ) ; cout << minimumReverse ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k, l, stdc, sum0, sum1
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cntPairsInTwoArray ( int arr [ ] , int brr [ ] , int N , int M ) { int cntOddArr = 0 ; int cntOddBrr = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) { cntOddArr += 1 ; } } for ( int i = 0 ; i < M ; i ++ ) { if ( brr [ i ] & 1 ) { cntOddBrr += 1 ; } } return ( N * M ) - ( cntOddArr * cntOddBrr ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int brr [ ] = { 1 , 2 } ; int M = sizeof ( brr ) / sizeof ( brr [ 0 ] ) ; cout << cntPairsInTwoArray ( arr , brr , N , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cntOddArr, cntOddBrr, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMaxPersons ( int * A , int n , int * B , int m , int x ) { int count = 0 ; sort ( A , A + n ) ; sort ( B , B + m ) ; multiset < int > s ; for ( int i = 0 ; i < m ; i ++ ) s . insert ( B [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) { int val = A [ i ] - x ; auto it = s . lower_bound ( val ) ; if ( it != s . end ( ) && * it <= A [ i ] + x ) { count ++ ; s . erase ( it ) ; } } return count ; } int main ( ) { int A [ ] = { 90 , 49 , 20 , 39 , 49 } ; int B [ ] = { 14 , 24 , 82 } ; int X = 15 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int M = sizeof ( B ) / sizeof ( B [ 0 ] ) ; cout << countMaxPersons ( A , N , B , M , X ) ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void max_freq ( int arr [ ] , int N ) { int Max = * max_element ( arr , arr + N ) ; int Min = * min_element ( arr , arr + N ) ; int freq [ Max - Min + 1 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { freq [ arr [ i ] - Min ] ++ ; } int maxSum = 0 ; for ( int i = 0 ; i < ( Max - Min - 1 ) ; i ++ ) { int val = freq [ i ] + freq [ i + 1 ] + freq [ i + 2 ] ; maxSum = max ( maxSum , val ) ; } cout << maxSum << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 3 , 1 , 4 , 1 , 5 , 9 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; max_freq ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaxLength ( int N , vector < int > arr ) { vector < int > dp ( N + 1 , 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 2 * i ; j <= N ; j += i ) { if ( arr [ i - 1 ] < arr [ j - 1 ] ) { dp [ j ] = max ( dp [ j ] , dp [ i ] + 1 ) ; } } } return * max_element ( dp . begin ( ) , dp . end ( ) ) ; } int main ( ) { vector < int > arr { 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int N = arr . size ( ) ; cout << findMaxLength ( N , arr ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binary_search ( vector < pair < int , int > > vec , int n , int a ) { int low , high , mid ; low = 0 ; high = n - 1 ; while ( low < high ) { mid = low + ( high - low + 1 ) / 2 ; if ( vec [ mid ] . first > a ) { high = mid - 1 ; } else if ( vec [ mid ] . first <= a ) { low = mid ; } } return low ; } void modify_vec ( vector < pair < int , int > > & v , int n ) { for ( int i = 1 ; i < n ; i ++ ) { v [ i ] . second = min ( v [ i ] . second , v [ i - 1 ] . second ) ; } } int evaluate_query ( vector < pair < int , int > > v , int n , int m1 , int m2 ) { int temp = binary_search ( v , n , m1 ) ; if ( ( v [ temp ] . first <= m1 ) && ( v [ temp ] . second <= m2 ) ) { return 1 ; } return 0 ; } void checkPairs ( vector < pair < int , int > > & v , vector < pair < int , int > > & queries ) { int n = v . size ( ) ; sort ( v . begin ( ) , v . end ( ) ) ; modify_vec ( v , n ) ; int k = queries . size ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int m1 = queries [ i ] . first ; int m2 = queries [ i ] . second ; int result = evaluate_query ( v , n , m1 , m2 ) ; if ( result > 0 ) cout << " Yes STRNEWLINE " ; else cout << " No STRNEWLINE " ; } } int main ( ) { vector < pair < int , int > > arr = { { 3 , 5 } , { 2 , 7 } , { 2 , 3 } , { 4 , 9 } } ; vector < pair < int , int > > queries = { { 3 , 4 } , { 3 , 2 } , { 4 , 1 } , { 3 , 7 } } ; checkPairs ( arr , queries ) ; return 0 ; }

Index/key variables: i, mid, temp
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Sort ( vector < int > & ans , int num ) { int pos = -1 ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { if ( ans [ i ] >= num ) { pos = i ; break ; } } if ( pos == -1 ) ans . push_back ( num ) ; else ans . insert ( ans . begin ( ) + pos , num ) ; } void sortStream ( int arr [ ] , int N ) { vector < int > ans ; for ( int i = 0 ; i < N ; i ++ ) { Sort ( ans , arr [ i ] ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { cout << ans [ i ] << " ▁ " ; } cout << endl ; } } int main ( ) { int arr [ ] = { 4 , 1 , 7 , 6 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortStream ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubArraySignChange ( int arr [ ] , int N ) { unordered_map < int , int > prefixCount ; unordered_map < int , int > suffixCount ; int total = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { total += arr [ i ] ; suffixCount [ arr [ i ] ] ++ ; } int prefixSum = 0 ; int suffixSum = 0 ; int count = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { prefixSum += arr [ i ] ; prefixCount [ arr [ i ] ] ++ ; suffixSum = total - prefixSum ; suffixCount [ arr [ i ] ] -- ; int diff = prefixSum - suffixSum ; if ( diff % 2 == 0 ) { int x = prefixCount + suffixCount [ - diff / 2 ] ; count = count + x ; } } return count ; } int main ( ) { int arr [ ] = { 2 , 2 , -3 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSubArraySignChange ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, prefixSum, stdc, total
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countCommonChar ( int ind , string & S ) { int cnt = 0 ; set < char > ls ; set < char > rs ; for ( int i = 0 ; i < ind ; ++ i ) { ls . insert ( S [ i ] ) ; } for ( int i = ind ; i < S . length ( ) ; ++ i ) { rs . insert ( S [ i ] ) ; } for ( auto v : ls ) { if ( rs . count ( v ) ) { ++ cnt ; } } return cnt ; } void partitionStringWithMaxCom ( string & S ) { int ans = 0 ; for ( int i = 1 ; i < S . length ( ) ; ++ i ) { ans = max ( ans , countCommonChar ( i , S ) ) ; } cout << ans << " STRNEWLINE " ; } int main ( ) { string str = " aabbca " ; partitionStringWithMaxCom ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i, v
C++ program:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std ; using namespace __gnu_cxx ; using namespace __gnu_pbds ; template < typename T > using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update > ; int countMaxCommonChar ( string & S ) { ordered_set < char > Q ; int res = 0 ; map < char , int > freq ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { freq [ S [ i ] ] ++ ; } for ( int i = 0 ; i < S . length ( ) ; i ++ ) { freq [ S [ i ] ] -- ; if ( ! freq [ S [ i ] ] ) { Q . erase ( S [ i ] ) ; } else { Q . insert ( S [ i ] ) ; } int curr = Q . size ( ) ; res = max ( res , curr ) ; } cout << res << " STRNEWLINE " ; } int main ( ) { string str = " aabbca " ; countMaxCommonChar ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubarray ( string s ) { s += '0' ; int i ; int res = 0 ; int prev_one = 0 ; int curr_one = 0 ; int numberOfZeros = 0 ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] == '1' ) { curr_one += 1 ; } else { numberOfZeros += 1 ; prev_one += curr_one ; res = max ( res , prev_one ) ; prev_one = curr_one ; curr_one = 0 ; } } if ( numberOfZeros == 1 ) { res -= 1 ; } return res ; } int main ( ) { string S = "1101" ; cout << longestSubarray ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr_one, i, numberOfZeros, prev_one, res, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubarray ( string s ) { int i = 0 , j = 0 , k = 1 ; for ( j = 0 ; j < s . size ( ) ; ++ j ) { if ( s [ j ] == '0' ) k -- ; if ( k < 0 && s [ i ++ ] == '0' ) k ++ ; } return j - i - 1 ; } int main ( ) { string S = "011101101" ; cout << longestSubarray ( S ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, k, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string SmallestString ( string s , char c ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] > c ) { s . insert ( i , 1 , c ) ; return s ; } } s += c ; return s ; } int main ( ) { string S = " acd " ; char C = ' b ' ; cout << SmallestString ( S , C ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void LarUnEl ( int arr [ ] , int N ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { mp [ arr [ i ] ] ++ ; } int LNRElem = INT_MIN ; int ind = -1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp [ arr [ i ] ] == 1 && arr [ i ] > LNRElem ) { ind = i ; LNRElem = arr [ i ] ; } } if ( ind == -1 ) { cout << ind ; return ; } cout << arr [ ind ] ; } int main ( ) { int arr [ ] = { 3 , 1 , 8 , 8 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; LarUnEl ( arr , N ) ; }

Index/key variables: i, ind
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countShifts ( string str ) { int firstOne = -1 ; int lastOne = -1 ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == '1' ) { if ( firstOne == -1 ) firstOne = i ; lastOne = i ; } } if ( ( firstOne == -1 ) || ( firstOne == lastOne ) ) { cout << 0 ; return ; } for ( int i = firstOne ; i <= lastOne ; i ++ ) { if ( str [ i ] == '0' ) { count ++ ; } } cout << count << endl ; } int main ( ) { string str = "00110111011" ; countShifts ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkSubsequenceUtil ( int arr [ ] , int L , int R , int N ) { for ( int i = 0 ; i < L ; i ++ ) if ( arr [ i ] == arr [ L ] ) return true ; for ( int i = R + 1 ; i < N ; i ++ ) if ( arr [ i ] == arr [ R ] ) return true ; return false ; } void checkSubsequence ( int arr [ ] , int L , int R , int N ) { if ( checkSubsequenceUtil ( arr , L , R , N ) ) { cout << " YES STRNEWLINE " ; } else { cout << " NO STRNEWLINE " ; } } int main ( ) { int arr [ ] = { 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int L = 3 , R = 6 ; checkSubsequence ( arr , L , R , N ) ; }

Index/key variables: L, R, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * next ; Node * prev ; } ; void push ( Node * * head_ref , int new_data ) { Node * new_node = ( Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> prev = NULL ; new_node -> next = ( * head_ref ) ; if ( ( * head_ref ) != NULL ) { ( * head_ref ) -> prev = new_node ; } ( * head_ref ) = new_node ; } int search ( Node * * head_ref , int x ) { Node * temp = * head_ref ; int pos = 0 ; while ( temp -> data != x && temp -> next != NULL ) { pos ++ ; temp = temp -> next ; } if ( temp -> data != x ) return -1 ; return ( pos + 1 ) ; } int main ( ) { Node * head = NULL ; int X = 8 ; push ( & head , 14 ) ; push ( & head , 9 ) ; push ( & head , 8 ) ; push ( & head , 15 ) ; push ( & head , 18 ) ; cout << search ( & head , X ) ; return 0 ; }

Accumulator variables: pos, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestSubarray ( int arr [ ] , int N , int K ) { int count = 0 ; int len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < K ) { count += 1 ; } else { len = max ( len , count ) ; count = 0 ; } } if ( count ) { len = max ( len , count ) ; } cout << len ; } int main ( ) { int arr [ ] = { 1 , 8 , 3 , 5 , 2 , 2 , 1 , 13 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 6 ; largestSubarray ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, 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 findPair ( int A [ ] , int N ) { int right_prod [ N ] ; int flag = 0 ; right_prod [ N - 1 ] = A [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) right_prod [ i ] = right_prod [ i + 1 ] * A [ i ] ; int total_prod = right_prod [ 0 ] ; int product ; for ( int i = 1 ; i < N - 1 ; i ++ ) { product = 1 ; for ( int j = i ; j < N - 1 ; j ++ ) { product *= A [ j ] ; if ( gcd ( product , right_prod [ j + 1 ] ) == 1 || gcd ( product , total_prod / right_prod [ i ] ) == 1 ) { flag = 1 ; cout << " ( " << i - 1 << " , ▁ " << j + 1 << " ) " ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) cout << -1 ; } int main ( ) { int arr [ ] = { 2 , 4 , 1 , 3 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findPair ( arr , N ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, product, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countString ( string S ) { long long count = 0 ; for ( auto it : S ) { if ( it == '0' and count > 0 ) { count -- ; } else { count ++ ; } } cout << ( ( 1 << count ) - 1 ) << " STRNEWLINE " ; } int main ( ) { string S = "1001" ; countString ( S ) ; return 0 ; }

Accumulator variables: count, stdc
Iterator variables: it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void replaceDuplicates ( vector < string > & names ) { unordered_map < string , int > hash ; for ( int i = 0 ; i < names . size ( ) ; i ++ ) { if ( hash . count ( names [ i ] ) == 0 ) hash [ names [ i ] ] ++ ; else { int count = hash [ names [ i ] ] ++ ; names [ i ] += to_string ( count ) ; } } for ( int i = 0 ; i < names . size ( ) ; i ++ ) { cout << names [ i ] << " ▁ " ; } } int main ( ) { vector < string > str = { " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " } ; replaceDuplicates ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void convert_to_allzeroes ( string str , int a , int b ) { int len = str . length ( ) ; int left_1 , i = 0 ; while ( i < len && str [ i ] == '0' ) i ++ ; left_1 = i ; int right_1 ; i = len - 1 ; while ( i >= 0 && str [ i ] == '0' ) i -- ; right_1 = i ; if ( left_1 == len && right_1 == -1 ) { cout << 0 ; return ; } int cost = a , zeroes ; for ( i = left_1 ; i <= right_1 ; i ++ ) { zeroes = 0 ; while ( i < len && str [ i ] == '0' ) { zeroes ++ ; i ++ ; } if ( zeroes ) cost += min ( zeroes * b , a ) ; } cout << cost ; } int main ( ) { string str = "01101110" ; int A = 5 , B = 1 ; convert_to_allzeroes ( str , A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cost, i, zeroes
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MinDistK ( int arr [ ] , int N , int K ) { int res = INT_MAX ; int dist = 0 ; for ( int i = 0 ; i <= ( N - K ) ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i + K - 1 ] >= 0 ) { dist = max ( arr [ i ] , arr [ i + K - 1 ] ) ; } else { dist = abs ( arr [ i ] ) + abs ( arr [ i + K - 1 ] ) + min ( abs ( arr [ i ] ) , abs ( arr [ i + K - 1 ] ) ) ; } res = min ( res , dist ) ; } return res ; } int main ( ) { int K = 3 ; int arr [ ] = { -30 , -10 , 10 , 20 , 50 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << MinDistK ( arr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min ( int a [ ] , int n ) { int minIndex = 0 , minValue = a [ 0 ] , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < minValue ) { minValue = a [ i ] ; minIndex = i ; } } return minIndex ; } int maximizeMin ( int A [ ] , int N , int S , int M ) { int minIndex , left , right , i , j ; for ( i = 0 ; i < M ; i ++ ) { minIndex = min ( A , N ) ; A [ minIndex ] ++ ; left = minIndex - 1 ; right = minIndex + 1 ; for ( j = 0 ; j < S - 1 ; j ++ ) { if ( left == -1 ) A [ right ++ ] ++ ; else if ( right == N ) A [ left -- ] ++ ; else { if ( A [ left ] < A [ right ] ) A [ left -- ] ++ ; else A [ right ++ ] ++ ; } } } minIndex = min ( A , N ) ; return A [ minIndex ] ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int S = 2 , M = 3 ; cout << maximizeMin ( arr , N , S , M ) ; return 0 ; }

Index/key variables: i, left, minIndex, right
Accumulator variables: i, j, left, right, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; typedef long long ll ; ll sumOfPathNodes ( ll N ) { if ( N == 1 ) { return 1 ; } else if ( N == 2 N == 3 ) { return N + 1 ; } vector < ll > arr ; arr . push_back ( 1 ) ; ll k = 1 ; bool flag = true ; while ( k < N ) { if ( flag == true ) { k *= 2 ; flag = false ; } else { k *= 4 ; flag = true ; } if ( k > N ) { break ; } arr . push_back ( k ) ; } ll len = arr . size ( ) ; vector < ll > prefix ( len ) ; prefix [ 0 ] = 1 ; for ( ll i = 1 ; i < len ; ++ i ) { prefix [ i ] = arr [ i ] + prefix [ i - 1 ] ; } vector < ll > :: iterator it = lower_bound ( prefix . begin ( ) , prefix . end ( ) , N ) ; ll ind = it - prefix . begin ( ) ; ll final_ans = 0 ; ll temp = N ; while ( ind > 1 ) { ll val = temp - prefix [ ind - 1 ] ; if ( ind % 2 != 0 ) { temp = prefix [ ind - 2 ] + ( val + 1 ) / 2 ; } else { temp = prefix [ ind - 2 ] + ( val + 3 ) / 4 ; } -- ind ; final_ans += temp ; } final_ans += ( N + 1 ) ; return final_ans ; } int main ( ) { ll N = 13 ; cout << sumOfPathNodes ( N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: final_ans, k, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPointRange ( int arr [ ] [ 3 ] , int X , int Y , int N ) { for ( int i = 0 ; i < N ; i ++ ) { double dist = sqrt ( ( arr [ i ] [ 0 ] - X ) * ( arr [ i ] [ 0 ] - X ) + ( arr [ i ] [ 1 ] - Y ) * ( arr [ i ] [ 1 ] - Y ) ) ; if ( dist <= arr [ i ] [ 2 ] ) { return true ; } } return false ; } int main ( ) { int arr [ ] [ 3 ] = { { 1 , 1 , 3 } , { 10 , 10 , 3 } , { 15 , 15 , 15 } } ; int X = 5 , Y = 5 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkPointRange ( arr , X , Y , N ) ) { cout << " True " ; } else { cout << " False " ; } }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findWinner ( int arr [ ] , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { cout << " Player ▁ 2" << endl ; } else if ( odd % 2 == 1 ) { cout << " Player ▁ 1" << endl ; } } else if ( even == 1 && odd % 2 == 1 ) { cout << " Player ▁ 1" << endl ; } else { cout << -1 << endl ; } } int main ( ) { int arr [ ] = { 3 , 1 , 9 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findWinner ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: even, i, odd, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void rearrangeArrMaxcntMinima ( int arr [ ] , int N ) { sort ( arr , arr + N ) ; int left = 0 ; int right = N / 2 ; while ( left < N / 2 right < N ) { if ( right < N ) { cout << arr [ right ] << " ▁ " ; right ++ ; } if ( left < N / 2 ) { cout << arr [ left ] << " ▁ " ; left ++ ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrangeArrMaxcntMinima ( arr , N ) ; return 0 ; }

Index/key variables: left, right
Accumulator variables: left, right, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int MOD = 1e9 + 7 ; int minJumps ( string seats ) { vector < int > position ; int count = 0 ; int len = seats . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( seats [ i ] == ' x ' ) { position . push_back ( i - count ) ; count ++ ; } } if ( count == len count == 0 ) return 0 ; int med_index = ( count - 1 ) / 2 ; int med_val = position [ med_index ] ; int ans = 0 ; for ( int i = 0 ; i < position . size ( ) ; i ++ ) { ans = ( ans % MOD + abs ( position [ i ] - med_val ) % MOD ) % MOD ; } return ans % MOD ; } int main ( ) { string S = " . . . . x . . xx . . . x . . " ; cout << minJumps ( S ) ; return 0 ; }

Index/key variables: i, med_index
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int singlePrimeFactor ( int N ) { unordered_set < int > disPrimeFact ; for ( int i = 2 ; i * i <= N ; ++ i ) { while ( N % i == 0 ) { disPrimeFact . insert ( i ) ; N /= i ; } } if ( N != 1 ) { disPrimeFact . insert ( N ) ; } if ( disPrimeFact . size ( ) == 1 ) { return * disPrimeFact . begin ( ) ; } return -1 ; } int cntsingleFactorPair ( int arr [ ] , int N ) { int countOf1 = 0 ; unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { countOf1 ++ ; continue ; } int factorValue = singlePrimeFactor ( arr [ i ] ) ; if ( factorValue == -1 ) { continue ; } else { mp [ factorValue ] ++ ; } } int res = 0 ; for ( auto it : mp ) { int X = it . second ; res += countOf1 * X + ( X * ( X - 1 ) ) / 2 ; } return res ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << cntsingleFactorPair ( arr , N ) ; return 0 ; }

Index/key variables: factorValue, i
Accumulator variables: N, countOf1, i, res, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MincntBothPalin ( string str1 , string str2 , int N ) { int i = 0 ; int j = N - 1 ; int cntOp = 0 ; while ( i < j ) { if ( str1 [ i ] == str1 [ j ] && str2 [ i ] != str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] != str1 [ j ] && str2 [ i ] == str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] != str1 [ j ] && str2 [ i ] != str2 [ j ] ) { if ( str1 [ i ] == str2 [ j ] && str2 [ i ] == str1 [ j ] ) { cntOp += 1 ; } else { cntOp += 2 ; } } i += 1 ; j -= 1 ; } return cntOp ; } int main ( ) { string str1 = " dbba " ; string str2 = " abcd " ; int N = str1 . length ( ) ; cout << MincntBothPalin ( str1 , str2 , N ) ; }

Index/key variables: i, j
Accumulator variables: cntOp, i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long power ( long long x , long long N ) { long long res = 1 ; while ( N > 0 ) { if ( N & 1 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } void findValX_Y ( long long N ) { if ( N <= 1 ) { cout << -1 << endl ; return ; } int xMax ; xMax = log2 ( N ) ; int yMax ; yMax = ( log2 ( N ) / log2 ( 5.0 ) ) ; for ( long long i = 1 ; i <= xMax ; i ++ ) { for ( long long j = 1 ; j <= yMax ; j ++ ) { long long a = power ( 2 , i ) ; long long b = power ( 5 , j ) ; if ( a + b == N ) { cout << i << " ▁ " << j << endl ; return ; } } } cout << -1 << endl ; } int main ( ) { long long N = 129 ; findValX_Y ( N ) ; return 0 ; }

Accumulator variables: i, j, stdc
Iterator variables: i, j