dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSubsequnces ( string A , string B ) { vector < int > v [ 26 ] ; int minIndex = -1 , cnt = 1 , j = 0 ; int flag = 0 ; for ( int i = 0 ; i < A . length ( ) ; i ++ ) { int p = ( int ) A [ i ] - 97 ; v [ p ] . push_back ( i ) ; } while ( j < B . length ( ) ) { int p = ( int ) B [ j ] - 97 ; int k = upper_bound ( v [ p ] . begin ( ) , v [ p ] . end ( ) , minIndex ) - v [ p ] . begin ( ) ; if ( v [ p ] . size ( ) == 0 ) { flag = 1 ; break ; } if ( k != v [ p ] . size ( ) ) { minIndex = v [ p ] [ k ] ; j = j + 1 ; } else { cnt = cnt + 1 ; minIndex = -1 ; } } if ( flag == 1 ) { return -1 ; } return cnt ; } int main ( ) { string A1 = " abbace " ; string B1 = " acebbaae " ; cout << minSubsequnces ( A1 , B1 ) << endl ; return 0 ; }

Index/key variables: i, j, k, p
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 26 ; int maxLength ( string str , int len ) { int res = 0 ; int lastPos [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { lastPos [ i ] = -1 ; } for ( int i = 0 ; i < len ; i ++ ) { int C = str [ i ] - ' a ' ; if ( lastPos [ C ] != -1 ) { res = max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ; } lastPos [ C ] = i ; } return res ; } int main ( ) { string str = " geeksforgeeks " ; int len = str . length ( ) ; cout << maxLength ( str , len ) ; return 0 ; }

Index/key variables: C, MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxProfit ( vector < int > a , vector < int > b , int n ) { int maxP = -1 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { int sumA = 0 ; for ( int j = 0 ; j < min ( i , ( int ) a . size ( ) ) ; j ++ ) sumA += a [ j ] ; int sumB = 0 ; for ( int j = i ; j < b . size ( ) ; j ++ ) sumB += b [ j ] ; maxP = max ( maxP , sumA + sumB ) ; } return maxP ; } int main ( ) { vector < int > a = { 2 , 3 , 2 } ; vector < int > b = { 10 , 30 , 40 } ; cout << maxProfit ( a , b , 4 ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc, sumA, sumB
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPartitions ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int min_elem = * min_element ( A , A + N ) ; if ( min_elem == INT_MAX ) break ; count ++ ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] % min_elem == 0 ) A [ i ] = INT_MAX ; } } return count ; } int main ( ) { int arr [ ] = { 7 , 6 , 5 , 4 , 3 , 2 , 2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPartitions ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSwaps ( string & s1 , string & s2 ) { int c0 = 0 , c1 = 0 ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( s1 [ i ] == '0' && s2 [ i ] == '1' ) { c0 ++ ; } else if ( s1 [ i ] == '1' && s2 [ i ] == '0' ) { c1 ++ ; } } int ans = c0 / 2 + c1 / 2 ; if ( c0 % 2 == 0 && c1 % 2 == 0 ) { return ans ; } else if ( ( c0 + c1 ) % 2 == 0 ) { return ans + 2 ; } else { return -1 ; } } int main ( ) { string s1 = "0011" , s2 = "1111" ; int ans = minSwaps ( s1 , s2 ) ; cout << ans << ' ' ; return 0 ; }

Index/key variables: i
Accumulator variables: c0, c1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minChanges ( int arr [ ] , int n ) { unordered_map < int , int > umap ; for ( int i = 0 ; i < n ; i ++ ) { umap [ arr [ i ] ] ++ ; } int maxFreq = 0 ; for ( auto p : umap ) { maxFreq = max ( maxFreq , p . second ) ; } return n - maxFreq ; } int main ( ) { int arr [ ] = { 2 , 3 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minChanges ( arr , n ) << ' ' ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( int n , int m ) { int a = 0 , k = 1 ; int p = max ( n , m ) ; while ( n != m ) { float s = ( float ) ( p - n + p - m ) ; float q = ( -1 + sqrt ( 8 * s + 1 ) ) / 2 ; if ( q - floor ( q ) == 0 ) { a = q ; n = m ; } p = p + 1 ; } return a ; } int main ( ) { int n = 1 , m = 3 ; cout << minOperations ( n , m ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int k_sum ( int a [ ] , int n , int k ) { int r = 0 , sum = 0 ; int ans = 0 ; for ( int l = 0 ; l < n ; l ++ ) { while ( sum < k ) { if ( r == n ) break ; else { sum += a [ r ] ; r ++ ; } } if ( sum < k ) break ; ans += n - r + 1 ; sum -= a [ l ] ; } return ans ; } int main ( ) { int a [ ] = { 6 , 1 , 2 , 7 } , k = 10 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << k_sum ( a , n , k ) ; return 0 ; }

Index/key variables: l, r
Accumulator variables: ans, l, r, stdc, sum
Iterator variables: l
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool hasCrest ( int arr [ ] , int n , int L , int R ) { int present [ n ] = { 0 } ; for ( int i = 1 ; i <= n - 2 ; i ++ ) { if ( ( arr [ i ] <= arr [ i + 1 ] ) && ( arr [ i ] <= arr [ i - 1 ] ) ) { present [ i ] = 1 ; } } for ( int i = 1 ; i < n ; i ++ ) { present [ i ] += present [ i - 1 ] ; } if ( present [ L ] == present [ R - 1 ] ) return true ; return false ; } int main ( ) { int arr [ ] = { 2 , 1 , 3 , 5 , 12 , 11 , 7 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int L = 2 ; int R = 6 ; if ( hasCrest ( arr , N , L , R ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: L, i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int arr1 [ ] , int arr2 [ ] , int n ) { int initialParity = 0 , finalParity = 0 ; int sum = 0 , minPositive = INT_MAX , maxNegative = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { initialParity += arr2 [ i ] ; if ( arr1 [ i ] >= 0 ) { finalParity += 1 ; sum += arr1 [ i ] ; minPositive = min ( minPositive , arr1 [ i ] ) ; } else { maxNegative = max ( maxNegative , arr1 [ i ] ) ; } } if ( initialParity % 2 == finalParity % 2 ) { return sum ; } else { if ( minPositive + maxNegative >= 0 ) { return sum + maxNegative ; } else { return sum - minPositive ; } } } int main ( ) { int arr1 [ ] = { 2 , -4 , 5 , 3 } ; int arr2 [ ] = { 0 , 1 , 0 , 1 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << maxSum ( arr1 , arr2 , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: finalParity, i, initialParity, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool IsLarger ( int X [ ] , int Y [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( X [ i ] < Y [ i ] ) { return false ; } } return true ; } int solve ( int X [ ] , int Y [ ] , int n ) { int ans = 0 ; if ( IsLarger ( X , Y , n ) ) { ans = 0 ; } else { int d = Y [ 0 ] - X [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { X [ i ] += d ; } if ( IsLarger ( X , Y , n ) ) { ans = d ; } else { ans = d + 1 ; } } return ans ; } int main ( ) { int X [ ] = { 2 , 3 , 6 , 9 } ; int Y [ ] = { 3 , 4 , 8 , 1 } ; int n = sizeof ( X ) / sizeof ( X [ 0 ] ) ; cout << solve ( X , Y , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int max_bitwise_or ( long long int L , long long int R ) { vector < long long int > v1 , v2 , v3 ; long long int z = 0 , i , ans = 0 , cnt = 1 ; while ( L > 0 ) { v1 . push_back ( L % 2 ) ; L = L / 2 ; } while ( R > 0 ) { v2 . push_back ( R % 2 ) ; R = R / 2 ; } while ( v1 . size ( ) != v2 . size ( ) ) { v1 . push_back ( 0 ) ; } for ( i = v2 . size ( ) - 1 ; i >= 0 ; i -- ) { if ( v2 [ i ] == 1 && v1 [ i ] == 0 && z == 0 ) { z = 1 ; continue ; } if ( z == 1 ) { v1 [ i ] = 1 ; } } for ( i = 0 ; i < v2 . size ( ) ; i ++ ) { v3 . push_back ( v2 [ i ] v1 [ i ] ) ; } for ( i = 0 ; i < v2 . size ( ) ; i ++ ) { if ( v3 [ i ] == 1 ) { ans += cnt ; } cnt *= 2 ; } return ans ; } int main ( ) { long long int L = 10 , R = 20 ; cout << max_bitwise_or ( L , R ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int valueofX ( int ar [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ar [ i ] ; } if ( sum % n == 0 ) { return sum / n ; } else { int A = sum / n , B = sum / n + 1 ; int ValueA = 0 , ValueB = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ValueA += ( ar [ i ] - A ) * ( ar [ i ] - A ) ; ValueB += ( ar [ i ] - B ) * ( ar [ i ] - B ) ; } if ( ValueA < ValueB ) { return A ; } else { return B ; } } } int main ( ) { int n = 7 ; int arr [ 7 ] = { 6 , 9 , 1 , 6 , 1 , 3 , 7 } ; cout << valueofX ( arr , n ) << ' ' ; return 0 ; }

Index/key variables: i
Accumulator variables: ValueA, ValueB, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minLength ( int n ) { int ans = n / 26 ; if ( n % 26 != 0 ) ans ++ ; return ans ; } string minString ( int n ) { int ans = n / 26 ; string res = " " ; while ( ans -- ) { res = res + " z " ; } if ( n % 26 != 0 ) { res = res + ( char ) ( ( n % 26 ) + 96 ) ; } return res ; } int main ( ) { int n = 50 ; cout << minLength ( n ) << endl << minString ( n ) ; return 0 ; }

Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  100001
int minHalls ( int lectures [ ] [ 2 ] , int n ) { int prefix_sum [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { prefix_sum [ lectures [ i ] [ 0 ] ] ++ ; prefix_sum [ lectures [ i ] [ 1 ] + 1 ] -- ; } int ans = prefix_sum [ 0 ] ; for ( int i = 1 ; i < MAX ; i ++ ) { prefix_sum [ i ] += prefix_sum [ i - 1 ] ; ans = max ( ans , prefix_sum [ i ] ) ; } return ans ; } int main ( ) { int lectures [ ] [ 2 ] = { { 0 , 5 } , { 1 , 2 } , { 1 , 10 } } ; int n = sizeof ( lectures ) / sizeof ( lectures [ 0 ] ) ; cout << minHalls ( lectures , n ) ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCapacity ( int enter [ ] , int exit [ ] , int n ) { int minCap = 0 ; int currCap = 0 ; for ( int i = 0 ; i < n ; i ++ ) { currCap = currCap + enter [ i ] - exit [ i ] ; minCap = max ( minCap , currCap ) ; } return minCap ; } int main ( ) { int enter [ ] = { 3 , 5 , 2 , 0 } ; int exit [ ] = { 0 , 2 , 4 , 4 } ; int n = sizeof ( enter ) / sizeof ( enter [ 0 ] ) ; cout << minCapacity ( enter , exit , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  543210
vector < string > ans ; bool isValidNum ( string x ) { map < int , int > mp ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) { if ( mp . find ( x [ i ] - '0' ) != mp . end ( ) ) { return false ; } else if ( x [ i ] - '0' > 5 ) { return false ; } else { mp [ x [ i ] - '0' ] = 1 ; } } return true ; } void generate ( ) { queue < string > q ; q . push ( "1" ) ; q . push ( "2" ) ; q . push ( "3" ) ; q . push ( "4" ) ; q . push ( "5" ) ; bool flag = true ; ans . push_back ( "0" ) ; while ( ! q . empty ( ) ) { string x = q . front ( ) ; q . pop ( ) ; if ( isValidNum ( x ) ) { ans . push_back ( x ) ; } if ( x . length ( ) == 6 ) continue ; for ( int i = 0 ; i <= 5 ; i ++ ) { string z = to_string ( i ) ; string temp = x + z ; q . push ( temp ) ; } } } bool comp ( string a , string b ) { if ( a . size ( ) == b . size ( ) ) return a < b ; else return a . size ( ) < b . size ( ) ; } int findcount ( string l , string r ) { generate ( ) ; int count = 0 ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { string a = ans [ i ] ; if ( comp ( l , a ) && comp ( a , r ) ) { count ++ ; } else if ( a == l a == r ) { count ++ ; } } return count ; } int main ( ) { string l = "1" , r = "1000" ; cout << findcount ( l , r ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > Findpermutation ( int n ) { vector < int > a ( n + 1 ) ; a [ 1 ] = n ; for ( int i = 2 ; i <= n ; i ++ ) a [ i ] = i - 1 ; return a ; } int main ( ) { int n = 8 ; vector < int > v = Findpermutation ( n ) ; for ( int i = 1 ; i <= n ; i ++ ) cout << v [ i ] << ' ▁ ' ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string lexo_small ( int n , int k ) { string arr = " " ; for ( int i = 0 ; i < n ; i ++ ) arr += ' a ' ; for ( int i = n - 1 ; i >= 0 ; i -- ) { k -= i ; if ( k >= 0 ) { if ( k >= 26 ) { arr [ i ] = ' z ' ; k -= 26 ; } else { char c = ( char ) ( k + 97 - 1 ) ; arr [ i ] = c ; k -= arr [ i ] - ' a ' + 1 ; } } else break ; k += i ; } return arr ; } int main ( ) { int n = 5 , k = 42 ; string arr = lexo_small ( n , k ) ; cout << arr ; }

Index/key variables: i
Accumulator variables: arr, i, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool IsPossible ( string s ) { int n = s . length ( ) ; set < char > count ; map < char , int > map ; for ( int i = 0 ; i < n ; i ++ ) { count . insert ( s [ i ] ) ; map [ s [ i ] ] += 1 ; } if ( count . size ( ) == 1 ) { return true ; } if ( count . size ( ) > 2 ) { return false ; } auto it = count . begin ( ) ; int x = 0 , y = 0 ; x = map [ * it ] ; it ++ ; y = map [ * it ] ; if ( abs ( x - y ) <= 1 ) { return true ; } return false ; } int main ( ) { string s = " aaaddad " ; if ( IsPossible ( s ) ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, it, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMin ( int arr [ ] , int n ) { int minVal = * min_element ( arr , arr + n ) ; return minVal ; } int main ( ) { int arr [ ] = { 5 , 3 , 1 , 6 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << getMin ( arr , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Substring ( string s ) { int ans = 1 , temp = 1 ; for ( int i = 1 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { ++ temp ; } else { ans = max ( ans , temp ) ; temp = 1 ; } } ans = max ( ans , temp ) ; return ans ; } int main ( ) { string s = " abcdddddeff " ; cout << Substring ( s ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Balanced_Substring ( string str , int n ) { int ans = 0 ; vector < int > arr ( n / 2 + 1 , 0 ) ; int d = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ( ' ) d ++ ; else { if ( d == 1 ) { for ( int j = 2 ; j <= n / 2 + 1 && arr [ j ] != 0 ; j ++ ) arr [ j ] = 0 ; } ++ ans ; ans += arr [ d ] ; arr [ d ] ++ ; d -- ; } } return ans ; } int main ( ) { string str = " ( ) ( ) ( ) " ; int n = str . size ( ) ; cout << Balanced_Substring ( str , n ) ; return 0 ; }

Index/key variables: d, i, j
Accumulator variables: ans, d, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int power ( long long x , int y , int mod ) { long long res = 1 ; while ( y ) { if ( y & 1 ) res = ( res * x ) % mod ; x = ( x * x ) % mod ; y = ( y >> 1 ) ; } return ( int ) ( res % mod ) ; } int ncr ( int n , int r , int mod ) { long long res = 1 ; for ( int i = 1 ; i <= r ; i += 1 ) { res = ( res * ( n - i + 1 ) ) % mod ; int inv = power ( i , mod - 2 , mod ) ; res = ( res * inv ) % mod ; } return ( int ) ( res % mod ) ; } int NoOfChords ( int A ) { int mod = 1e9 + 7 ; long long ans = ncr ( 2 * A , A , mod ) ; int inv = power ( A + 1 , mod - 2 , mod ) ; ans = ( ans * inv ) % mod ; return ( int ) ( ans % mod ) ; } int main ( ) { int N = 2 ; cout << NoOfChords ( N ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int StrictlyPositiveXor ( int A [ ] , int N ) { int allxor = 0 ; bool checkallzero = true ; for ( int i = 0 ; i < N ; i += 1 ) { allxor ^= A [ i ] ; if ( A [ i ] > 0 ) checkallzero = false ; } if ( allxor != 0 ) return N ; if ( checkallzero ) return -1 ; int l = N , r = -1 ; for ( int i = 0 ; i < N ; i += 1 ) { if ( A [ i ] > 0 ) { l = i + 1 ; break ; } } for ( int i = N - 1 ; i >= 0 ; i -= 1 ) { if ( A [ i ] > 0 ) { r = i + 1 ; break ; } } return max ( N - l , r - 1 ) ; } int main ( ) { int A [ ] = { 1 , 0 , 0 , 1 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << StrictlyPositiveXor ( A , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: allxor, i, stdc
Iterator variables: i
Boolean variables: checkallzero
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_INT  1000000
int solve ( int Array [ ] , int N ) { vector < int > pos [ 5 ] ; int pref [ 5 ] = { 0 } ; if ( Array [ 0 ] == 0 ) { pref [ 0 ] = 1 ; pos [ 0 ] . push_back ( 0 ) ; } int ans = MAX_INT ; for ( int i = 1 ; i < N ; i ++ ) { if ( Array [ i ] == 0 ) { pref [ 0 ] ++ ; pos [ 0 ] . push_back ( i ) ; } else { if ( pref [ Array [ i ] - 1 ] > 0 ) { pref [ Array [ i ] ] ++ ; pos [ Array [ i ] ] . push_back ( i ) ; if ( Array [ i ] == 4 ) { int end = i ; int start = i ; for ( int j = 3 ; j >= 0 ; j -- ) { int s = 0 ; int e = pos [ j ] . size ( ) - 1 ; int temp = -1 ; while ( s <= e ) { int m = ( s + e ) / 2 ; if ( pos [ j ] [ m ] <= start ) { temp = pos [ j ] [ m ] ; s = m + 1 ; } else { e = m - 1 ; } } start = temp ; } ans = min ( ans , end - start + 1 ) ; } } } } return ans ; } int main ( ) { int Array [ ] = { 0 , 1 , 2 , 3 , 4 , 2 , 0 , 3 , 4 } ; int N = sizeof ( Array ) / sizeof ( Array [ 0 ] ) ; cout << solve ( Array , N ) ; return 0 ; }

Index/key variables: i, j, m
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findWeights ( int X ) { int sum = 0 ; int power = 0 ; while ( sum < X ) { sum = pow ( 3 , power + 1 ) - 1 ; sum /= 2 ; power ++ ; } int ans = 1 ; for ( int i = 1 ; i <= power ; i ++ ) { cout << ans << " ▁ " ; ans = ans * 3 ; } } int main ( ) { int X = 2 ; findWeights ( X ) ; return 0 ; }

Accumulator variables: i, power, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > solve ( int X , vector < int > & A ) { int min = INT_MAX ; int ind = -1 ; for ( int i = 0 ; i < A . size ( ) ; i ++ ) { if ( A [ i ] < min ) { min = A [ i ] ; ind = i ; } } int maxIndChosen = X / min ; vector < int > ans ; if ( maxIndChosen == 0 ) { return ans ; } for ( int i = 0 ; i < maxIndChosen ; i ++ ) { ans . push_back ( ind ) ; } int temp = maxIndChosen ; int sum = maxIndChosen * A [ ind ] ; for ( int i = 0 ; i < ind ; i ++ ) { if ( sum - X == 0 temp == 0 ) break ; while ( ( sum - A [ ind ] + A [ i ] ) <= X && temp != 0 ) { ans . erase ( ans . begin ( ) ) ; ans . push_back ( i ) ; temp -- ; sum += ( A [ i ] - A [ ind ] ) ; } } sort ( ans . begin ( ) , ans . end ( ) ) ; return ans ; } int main ( ) { vector < int > A = { 5 , 6 , 4 , 8 } ; int X = 18 ; vector < int > ans = solve ( X , A ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) cout << ans [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, ind
Accumulator variables: i, stdc, sum, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool matrix_exist ( int row [ ] , int column [ ] , int r , int c ) { int row_sum = 0 ; int column_sum = 0 ; int row_max = -1 ; int column_max = -1 ; int row_non_zero = 0 ; int column_non_zero = 0 ; for ( int i = 0 ; i < r ; i ++ ) { row_sum += row [ i ] ; row_max = max ( row_max , row [ i ] ) ; if ( row [ i ] ) row_non_zero ++ ; } for ( int i = 0 ; i < c ; i ++ ) { column_sum += column [ i ] ; column_max = max ( column_max , column [ i ] ) ; if ( column [ i ] ) column_non_zero ++ ; } if ( ( row_sum != column_sum ) || ( row_max > column_non_zero ) || ( column_max > row_non_zero ) ) return false ; return true ; } int main ( ) { int row [ ] = { 2 , 2 , 2 , 2 , 2 } ; int column [ ] = { 5 , 5 , 0 , 0 } ; int r = sizeof ( row ) / sizeof ( row [ 0 ] ) ; int c = sizeof ( column ) / sizeof ( column [ 0 ] ) ; if ( matrix_exist ( row , column , r , c ) ) cout << " YES STRNEWLINE " ; else cout << " NO STRNEWLINE " ; }

Index/key variables: i
Accumulator variables: column_non_zero, column_sum, i, row_non_zero, row_sum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubarray ( int arr [ ] , int n ) { int maxMean = 0 ; for ( int i = 1 ; i < n ; i ++ ) maxMean = max ( maxMean , ( arr [ i ] + arr [ i - 1 ] ) / 2 ) ; int ans = 0 ; int subarrayLength = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] >= maxMean ) ans = max ( ans , ++ subarrayLength ) ; else subarrayLength = 0 ; return ans ; } int main ( ) { int arr [ ] = { 4 , 3 , 3 , 2 , 1 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << longestSubarray ( 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 maxDistance ( int arr [ ] , int n ) { if ( arr [ 0 ] != arr [ n - 1 ] ) return ( n - 1 ) ; int i = n - 1 ; while ( i > 0 ) { if ( arr [ i ] != arr [ 0 ] ) break ; i -- ; } int distFirst = ( i == 0 ) ? -1 : i ; i = 0 ; while ( i < n - 1 ) { if ( arr [ i ] != arr [ n - 1 ] ) break ; i ++ ; } int distLast = ( i == n - 1 ) ? -1 : ( n - 1 - i ) ; int maxDist = max ( distFirst , distLast ) ; return maxDist ; } int main ( ) { int arr [ ] = { 4 , 4 , 1 , 2 , 1 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxDistance ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkPath ( char a , char b , map < char , vector < char > > & G ) { map < char , bool > visited ; deque < char > queue ; queue . push_back ( a ) ; visited [ a ] = true ; while ( ! queue . empty ( ) ) { int n = queue . front ( ) ; queue . pop_front ( ) ; if ( n == b ) return true ; for ( auto i : G [ n ] ) { if ( visited [ i ] == false ) { queue . push_back ( i ) ; visited [ i ] = true ; } } } return false ; } int countPairs ( string s1 , string s2 , map < char , vector < char > > & G , int x ) { int count = 0 ; for ( int i = 0 ; i < x ; i ++ ) { char a = s1 [ i ] ; char b = s2 [ i ] ; if ( G . find ( a ) != G . end ( ) and G . find ( b ) == G . end ( ) and a != b ) { G [ a ] . push_back ( b ) ; G [ b ] . push_back ( a ) ; count ++ ; } else if ( G . find ( b ) != G . end ( ) and G . find ( a ) == G . end ( ) and a != b ) { G [ b ] . push_back ( a ) ; G [ a ] . push_back ( b ) ; count ++ ; } else if ( G . find ( a ) == G . end ( ) and G . find ( b ) == G . end ( ) and a != b ) { G [ a ] . push_back ( b ) ; G [ b ] . push_back ( a ) ; count ++ ; } else { if ( ! checkPath ( a , b , G ) and a != b ) { G [ a ] . push_back ( b ) ; G [ b ] . push_back ( a ) ; count ++ ; } } } return count ; } int main ( ) { string s1 = " abb " , s2 = " dad " ; int x = s1 . length ( ) ; map < char , vector < char > > G ; cout << countPairs ( s1 , s2 , G , x ) << endl ; return 0 ; }

Index/key variables: a, b, i, n
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void solve ( int n , int k ) { int mini = 0 ; int x1 = 1 ; int a [ k ] ; for ( int i = 1 ; i <= k ; i ++ ) { mini += x1 ; a [ i - 1 ] = x1 ; x1 += 1 ; } if ( n < mini ) { cout << " - 1" ; return ; } int rem = n - mini ; int cnt = rem / k ; rem = rem % k ; for ( int i = 0 ; i < k ; i ++ ) a [ i ] += cnt ; for ( int i = k - 1 ; i > 0 && rem > 0 ; i -- ) { int xx = a [ i - 1 ] * 2 ; int left = xx - a [ i ] ; if ( rem >= left ) { a [ i ] = xx ; rem -= left ; } else { a [ i ] += rem ; rem = 0 ; } } int sum = a [ 0 ] ; for ( int i = 1 ; i < k ; i ++ ) { if ( a [ i ] > 2 * a [ i - 1 ] ) { cout << " - 1" ; return ; } sum += a [ i ] ; } if ( sum != n ) { cout << " - 1" ; return ; } for ( int i = 0 ; i < k ; i ++ ) cout << a [ i ] << " ▁ " ; } int main ( ) { int n = 26 , k = 6 ; solve ( n , k ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: i, mini, rem, stdc, sum, x1
Iterator variables: i