dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define m  5
int countSubsquare ( int arr [ ] [ m ] , int n , int X ) { int dp [ n + 1 ] [ m + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { dp [ i + 1 ] [ j + 1 ] = arr [ i ] [ j ] ; } } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; } } int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { int lo = 1 ; int hi = min ( n - i , m - j ) + 1 ; bool found = false ; while ( lo <= hi ) { int mid = ( lo + hi ) / 2 ; int ni = i + mid - 1 ; int nj = j + mid - 1 ; int sum = dp [ ni ] [ nj ] - dp [ ni ] [ j - 1 ] - dp [ i - 1 ] [ nj ] + dp [ i - 1 ] [ j - 1 ] ; if ( sum >= X ) { if ( sum == X ) { found = true ; } hi = mid - 1 ; } else { lo = mid + 1 ; } } if ( found == true ) { cnt ++ ; } } } return cnt ; } int main ( ) { int N = 4 , X = 10 ; int arr [ N ] [ m ] = { { 2 , 4 , 3 , 2 , 10 } , { 3 , 1 , 1 , 1 , 5 } , { 1 , 1 , 2 , 1 , 4 } , { 2 , 1 , 1 , 1 , 3 } } ; cout << countSubsquare ( arr , N , X ) << endl ; return 0 ; }

Index/key variables: N, i, j, m, ni, nj
Accumulator variables: cnt, i, j, stdc
Iterator variables: i, j
Boolean variables: found
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkArray ( int A [ ] , int B [ ] , int N ) { int start = 0 ; int end = N - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] != B [ i ] ) { start = i ; break ; } } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( A [ i ] != B [ i ] ) { end = i ; break ; } } reverse ( A + start , A + end + 1 ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] != B [ i ] ) { cout << " No " << endl ; return ; } } cout << " Yes " << endl ; } int main ( ) { int A [ ] = { 1 , 3 , 2 , 4 } ; int B [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; checkArray ( A , B , 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 countSub ( string str ) { int n = ( int ) str . size ( ) ; long long int ans = 0 ; int cnt [ 26 ] ; memset ( cnt , 0 , sizeof ( cnt ) ) ; int i = 0 , j = 0 ; while ( i < n ) { if ( j < n && ( cnt [ str [ j ] - ' a ' ] == 0 ) ) { cnt [ str [ j ] - ' a ' ] ++ ; ans += ( j - i + 1 ) ; j ++ ; } else { cnt [ str [ i ] - ' a ' ] -- ; i ++ ; } } return ans ; } int main ( ) { string str = " gffg " ; cout << countSub ( str ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
C++ program:
#include <iostream>
using namespace std ; int solve ( int n , int k ) { int ans = 0 ; for ( int j = 1 ; j * j <= n ; j ++ ) { if ( n % j == 0 ) { if ( j <= k ) { ans = max ( ans , j ) ; } if ( n / j <= k ) { ans = max ( ans , n / j ) ; } } } return ans ; } int main ( ) { int N = 8 , K = 7 ; cout << ( N / solve ( N , K ) ) ; return 0 ; }

Accumulator variables: j
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void max_sum_subarray ( vector < int > arr , int L , int R ) { int n = arr . size ( ) ; int pre [ n ] = { 0 } ; pre [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } multiset < int > s1 ; s1 . insert ( 0 ) ; int ans = INT_MIN ; ans = max ( ans , pre [ L - 1 ] ) ; int flag = 0 ; for ( int i = L ; i < n ; i ++ ) { if ( i - R >= 0 ) { if ( flag == 0 ) { auto it = s1 . find ( 0 ) ; s1 . erase ( it ) ; flag = 1 ; } } if ( i - L >= 0 ) s1 . insert ( pre [ i - L ] ) ; ans = max ( ans , pre [ i ] - * s1 . begin ( ) ) ; if ( i - R >= 0 ) { auto it = s1 . find ( pre [ i - R ] ) ; s1 . erase ( it ) ; } } cout << ans << endl ; } int main ( ) { int L , R ; L = 1 ; R = 3 ; vector < int > arr = { 1 , 2 , 2 , 1 } ; max_sum_subarray ( arr , L , R ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int rowWise ( char * v , int n , int m , int k ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int countcons = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( * ( v + i * m + j ) == '1' ) { countcons = 0 ; } else { countcons ++ ; } if ( countcons >= k ) { ans ++ ; } } } return ans ; } int colWise ( char * v , int n , int m , int k ) { int ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int countcons = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( * ( v + j * n + i ) == '1' ) { countcons = 0 ; } else { countcons ++ ; } if ( countcons >= k ) { ans ++ ; } } } return ans ; } int main ( ) { int n = 3 , m = 3 , k = 1 ; char v [ n ] [ m ] = { '0' , '0' , '0' , '0' , '0' , '0' , '0' , '0' , '0' } ; if ( k == 1 ) { cout << rowWise ( v [ 0 ] , n , m , k ) ; } else { cout << colWise ( v [ 0 ] , n , m , k ) + rowWise ( v [ 0 ] , n , m , k ) ; } return 0 ; }

Index/key variables: m, n
Accumulator variables: ans, countcons, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool solve ( int a [ ] , int n ) { int mx = INT_MIN ; for ( int j = 1 ; j < n ; j ++ ) { if ( mx > a [ j ] ) return false ; mx = max ( mx , a [ j - 1 ] ) ; } return true ; } int main ( ) { int a [ ] = { 1 , 0 , 2 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; bool possible = solve ( a , n ) ; if ( possible ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: j, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; string Validate_It ( string IP ) { regex ipv4 ( " ( ( [ 0-9 ] ▁ [ 1-9 ] [ 0-9 ] ▁ 1[0-9 ] [ 0-9 ] ▁ 2[0-4 ] [ 0-9 ] ▁ 25[0-5 ] ) \\ . ) { 3 } ( [0-9 ] ▁ [ 1-9 ] [ 0-9 ] ▁ 1[0-9 ] [ 0-9 ] ▁ 2[0-4 ] [ 0-9 ] ▁ 25[0-5 ] ) " ) ; regex ipv6 ( " ( ( ( [0-9a - fA - F ] ) { 1,4 } ) \\ : ) { 7 } ( [0-9a - fA - F ] ) { 1,4 } " ) ; if ( regex_match ( IP , ipv4 ) ) return " Valid ▁ IPv4" ; else if ( regex_match ( IP , ipv6 ) ) return " Valid ▁ IPv6" ; return " Invalid ▁ IP " ; } int main ( ) { string IP = "203.120.223.13" ; cout << Validate_It ( IP ) << endl ; IP = " fffe : 3465 : efab : 23fe : 2235:6565 : aaab : 0001" ; cout << Validate_It ( IP ) << endl ; IP = "2F33:12a0:3Ea0:0302" ; cout << Validate_It ( IP ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int spf [ 100009 ] ; void sieve ( ) { memset ( spf , -1 , 100005 ) ; for ( int i = 2 ; i * i <= 100005 ; i ++ ) { for ( int j = i ; j <= 100005 ; j += i ) { if ( spf [ j ] == -1 ) { spf [ j ] = i ; } } } } set < int > findPrimeFactors ( set < int > s , int n ) { while ( n > 1 ) { s . insert ( spf [ n ] ) ; n /= spf [ n ] ; } return s ; } int MinimumSteps ( int n , int m ) { queue < pair < int , int > > q ; set < int > s ; q . push ( { n , 0 } ) ; while ( ! q . empty ( ) ) { int newNum = q . front ( ) . first ; int distance = q . front ( ) . second ; q . pop ( ) ; set < int > k = findPrimeFactors ( s , newNum ) ; for ( auto i : k ) { if ( newNum == m ) { return distance ; } else if ( newNum > m ) { break ; } else { q . push ( { newNum + i , distance + 1 } ) ; } } } return -1 ; } int main ( ) { int N = 7 , M = 16 ; sieve ( ) ; cout << MinimumSteps ( N , M ) ; }

Index/key variables: j, n
Accumulator variables: i, j, n, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > v [ 100000 ] ; void div ( int n ) { for ( int i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v [ n ] . push_back ( i ) ; } } } int prodof2elements ( int arr [ ] , int n ) { int arr2 [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr2 [ i ] = arr [ i ] ; } sort ( arr2 , arr2 + n ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( v [ arr [ i ] ] . size ( ) == 0 ) div ( arr [ i ] ) ; for ( auto j : v [ arr [ i ] ] ) { if ( binary_search ( arr2 , arr2 + n , j ) and binary_search ( arr2 , arr2 + n , arr [ i ] / j ) ) { ans ++ ; break ; } } } return ans ; } int main ( ) { int arr [ ] = { 2 , 1 , 8 , 4 , 32 , 18 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << prodof2elements ( arr , N ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: ans, i, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <unordered_map>
using namespace std ; int max_subarray_size ( int N , int arr [ ] ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { unordered_map < int , int > map1 ; unordered_map < int , int > map2 ; for ( int j = i ; j < N ; j ++ ) { int ele_count ; if ( map1 . find ( arr [ j ] ) == map1 . end ( ) ) { ele_count = 0 ; } else { ele_count = map1 [ arr [ j ] ] ; } map1 [ arr [ j ] ] ++ ; if ( map2 . find ( ele_count ) != map2 . end ( ) ) { if ( map2 [ ele_count ] == 1 ) { map2 . erase ( ele_count ) ; } else { map2 [ ele_count ] -- ; } } map2 [ ele_count + 1 ] ++ ; if ( map2 . size ( ) == 1 ) ans = max ( ans , j - i + 1 ) ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 5 , 6 , 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << max_subarray_size ( N , arr ) ; return 0 ; }

Index/key variables: ele_count, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool vowel ( int vo ) { if ( vo == 0 vo == 4 vo == 8 vo == 14 vo == 20 ) return true ; else return false ; } bool check ( string s , int k ) { vector < int > cnt ( 26 , 0 ) ; for ( int i = 0 ; i < k - 1 ; i ++ ) { cnt [ s [ i ] - ' a ' ] ++ ; } for ( int i = k - 1 ; i < s . size ( ) ; i ++ ) { cnt [ s [ i ] - ' a ' ] ++ ; int flag1 = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( vowel ( j ) == false && cnt [ j ] > 0 ) { flag1 = 1 ; break ; } } if ( flag1 == 0 ) return true ; cnt [ s [ i - k + 1 ] - ' a ' ] -- ; } return false ; } int longestSubstring ( string s ) { int l = 1 , r = s . size ( ) ; int maxi = 0 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( check ( s , mid ) ) { l = mid + 1 ; maxi = max ( maxi , mid ) ; } else r = mid - 1 ; } return maxi ; } int main ( ) { string s = " sedrewaefhoiu " ; cout << longestSubstring ( s ) ; 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 countPairs ( int X [ ] , int Y [ ] , int m , int n ) { vector < int > suffix ( 1005 ) ; long long total_pairs = 0 ; for ( int i = 0 ; i < n ; i ++ ) suffix [ Y [ i ] ] ++ ; for ( int i = 1e3 ; i >= 3 ; i -- ) suffix [ i ] += suffix [ i + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { if ( X [ i ] == 0 ) continue ; else if ( X [ i ] == 1 ) { total_pairs += suffix [ 0 ] ; continue ; } else if ( X [ i ] == 2 ) total_pairs += suffix [ 5 ] ; else if ( X [ i ] == 3 ) total_pairs += suffix [ 2 ] + suffix [ 4 ] ; else total_pairs += suffix [ X [ i ] + 1 ] ; total_pairs += suffix [ 0 ] + suffix [ 1 ] ; } return total_pairs ; } int main ( ) { int X [ ] = { 10 , 19 , 18 } ; int Y [ ] = { 11 , 15 , 9 } ; int m = sizeof ( X ) / sizeof ( X [ 0 ] ) ; int n = sizeof ( Y ) / sizeof ( Y [ 0 ] ) ; cout << countPairs ( X , Y , m , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, total_pairs
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( int A [ ] [ 10 ] , int N , int M ) { int B [ N ] [ M ] ; int c = 1 ; set < int > s ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) B [ i ] [ j ] = c ++ ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i != 0 ) { if ( A [ i - 1 ] [ j ] == A [ i ] [ j ] ) B [ i - 1 ] [ j ] = B [ i ] [ j ] ; } if ( i != N - 1 ) { if ( A [ i + 1 ] [ j ] == A [ i ] [ j ] ) B [ i + 1 ] [ j ] = B [ i ] [ j ] ; } if ( j != 0 ) { if ( A [ i ] [ j - 1 ] == A [ i ] [ j ] ) B [ i ] [ j - 1 ] = B [ i ] [ j ] ; } if ( j != M - 1 ) { if ( A [ i ] [ j + 1 ] == A [ i ] [ j ] ) B [ i ] [ j + 1 ] = B [ i ] [ j ] ; } } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) s . insert ( B [ i ] [ j ] ) ; } return s . size ( ) ; } int main ( ) { int N = 2 , M = 3 ; int A [ ] [ 10 ] = { { 2 , 1 , 3 } , { 1 , 1 , 2 } } ; cout << solve ( A , N , M ) ; }

Index/key variables: M, N, i, j
Accumulator variables: c, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int splitArray ( int start , int end , int * arr , int * prefix_sum ) { if ( start >= end ) return 0 ; for ( int k = start ; k < end ; ++ k ) { if ( ( prefix_sum [ k ] - prefix_sum [ start - 1 ] ) == ( prefix_sum [ end ] - prefix_sum [ k ] ) ) { return 1 + splitArray ( start , k , arr , prefix_sum ) + splitArray ( k + 1 , end , arr , prefix_sum ) ; } } return 0 ; } void solve ( int arr [ ] , int n ) { int prefix_sum [ n + 1 ] ; prefix_sum [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i - 1 ] ; } cout << splitArray ( 1 , n , arr , prefix_sum ) ; } int main ( ) { int arr [ ] = { 12 , 3 , 3 , 0 , 3 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; solve ( arr , N ) ; return 0 ; }

Index/key variables: end, i, k
Accumulator variables: stdc
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDays ( vector < int > & arr , int n , int k ) { int l = arr . size ( ) , left = 1 , right = 1e9 ; if ( n * k > l ) return -1 ; while ( left < right ) { int mid = ( left + right ) / 2 , cnt = 0 , product = 0 ; for ( int j = 0 ; j < l ; ++ j ) { if ( arr [ j ] > mid ) { cnt = 0 ; } else if ( ++ cnt >= k ) { product ++ ; cnt = 0 ; } } if ( product < n ) { left = mid + 1 ; } else { right = mid ; } } return left ; } int main ( ) { vector < int > arr { 1 , 10 , 3 , 10 , 2 } ; int n = 3 , k = 1 ; cout << minDays ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: j
Accumulator variables: product, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countFac ( int n ) { int m = n ; int count = 0 ; for ( int i = 2 ; ( i * i ) <= m ; ++ i ) { int total = 0 ; while ( n % i == 0 ) { n /= i ; ++ total ; } int temp = 0 ; for ( int j = 1 ; ( temp + j ) <= total ; ++ j ) { temp += j ; ++ count ; } } if ( n != 1 ) ++ count ; return count ; } int main ( ) { int N = 24 ; cout << countFac ( N ) ; return 0 ; }

Accumulator variables: n, stdc, temp
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumSum ( int a [ ] , int b [ ] , int c , int n ) { vector < vector < int > > dp ( n , vector < int > ( 2 , 1e6 ) ) ; dp [ 0 ] [ 0 ] = a [ 0 ] ; dp [ 0 ] [ 1 ] = b [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 0 ] + a [ i ] ) ; dp [ i ] [ 0 ] = min ( dp [ i ] [ 0 ] , dp [ i - 1 ] [ 1 ] + a [ i ] + c ) ; dp [ i ] [ 1 ] = min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 0 ] + b [ i ] + c ) ; dp [ i ] [ 1 ] = min ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + b [ i ] ) ; } cout << min ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) << " STRNEWLINE " ; } int main ( ) { int arr1 [ ] = { 7 , 6 , 18 , 6 , 16 , 18 , 1 , 17 , 17 } ; int arr2 [ ] = { 6 , 9 , 3 , 10 , 9 , 1 , 10 , 1 , 5 } ; int C = 2 ; int N = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; minimumSum ( arr1 , arr2 , C , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumMoves ( string S , int K ) { int N = S . length ( ) ; int ops = 0 ; int last_idx = -1 ; for ( int i = 0 ; i < K ; i ++ ) { if ( S [ i ] == '1' ) last_idx = i ; } if ( last_idx == -1 ) { ++ ops ; S [ K - 1 ] = '1' ; last_idx = K - 1 ; } for ( int i = 1 ; i < N - K + 1 ; i ++ ) { if ( last_idx < i ) last_idx = -1 ; if ( S [ i + K - 1 ] == '1' ) last_idx = i + K - 1 ; if ( last_idx == -1 ) { ++ ops ; S [ i + K - 1 ] = '1' ; last_idx = i + K - 1 ; } } return ops ; } int main ( ) { string S = "001010000" ; int K = 3 ; cout << minimumMoves ( S , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; char arr [ ] = { ' a ' , ' b ' , ' c ' } ; void findString ( int n , int k , string s1 , string s2 ) { string s3 = s2 ; int d = 0 ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) d ++ ; } if ( ( d + 1 ) / 2 > k ) { cout << " - 1" << endl ; return ; } else { if ( k <= d ) { int X = d - k ; int T = 2 * k - d ; for ( int i = 0 ; i < s3 . size ( ) ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( T > 0 ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s2 [ i ] ) { s3 [ i ] = arr [ j ] ; T -- ; break ; } } } else if ( X > 0 ) { s3 [ i ] = s1 [ i ] ; X -- ; } } } cout << s3 << endl ; } else { for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( s1 [ i ] != s3 [ i ] ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( s1 [ i ] == s3 [ i ] && k ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( arr [ j ] != s1 [ i ] && arr [ j ] != s3 [ i ] ) { s3 [ i ] = arr [ j ] ; k -- ; break ; } } } } cout << s3 << endl ; } } } int main ( ) { int N = 4 , k = 2 ; string S1 = " zzyy " ; string S2 = " zxxy " ; findString ( N , k , S1 , S2 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: T, X, d, i, j, k, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSolutions ( int N ) { int count = 0 ; for ( int i = 1 ; i <= sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( ( i + N / i ) % 2 == 0 ) { count ++ ; } } } cout << 4 * count << endl ; } int main ( ) { int N = 80 ; findSolutions ( N ) ; return 0 ; }

Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int check ( int A , int B , int C , int D , long long int x ) { long long int ans ; ans = ( A * x * x * x + B * x * x + C * x + D ) ; return ans ; } void findSolution ( int A , int B , int C , int D , int E ) { int start = 0 , end = 100000 ; long long int mid , ans ; while ( start <= end ) { mid = start + ( end - start ) / 2 ; ans = check ( A , B , C , D , mid ) ; if ( ans == E ) { cout << mid << endl ; return ; } if ( ans < E ) start = mid + 1 ; else end = mid - 1 ; } cout << " NA " ; } int main ( ) { int A = 1 , B = 0 , C = 0 ; int D = 0 , E = 27 ; findSolution ( A , B , C , D , E ) ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTriplets ( string color ) { int result = 0 , Blue_Count = 0 ; int Red_Count = 0 ; for ( char c : color ) { if ( c == ' B ' ) Blue_Count ++ ; } for ( char c : color ) { if ( c == ' B ' ) Blue_Count -- ; if ( c == ' R ' ) Red_Count ++ ; if ( c == ' G ' ) result += Red_Count * Blue_Count ; } return result ; } int main ( ) { string color = " RRGGBBRGGBB " ; cout << countTriplets ( color ) ; return 0 ; }

Accumulator variables: Blue_Count, Red_Count, result, stdc
Iterator variables: c
C++ program:
#include <bits/stdc++.h>
using namespace std ; int naive_find_x ( int N ) { int c = 0 , i ; for ( i = 1 ; i < N ; i ++ ) { c += i * i * i ; if ( c >= N ) break ; } return i ; } int main ( ) { int N = 100 ; cout << naive_find_x ( N ) ; return 0 ; }

Accumulator variables: c, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binary_searched_find_x ( int k ) { int l = 0 ; int r = k ; int ans = 0 ; while ( l <= r ) { int mid = l + ( r - l ) / 2 ; if ( pow ( ( ( mid * ( mid + 1 ) ) / 2 ) , 2 ) >= k ) { ans = mid ; r = mid - 1 ; } else { l = mid + 1 ; } } return ans ; } int main ( ) { int N = 100 ; cout << binary_searched_find_x ( N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lenOfLongZigZagArr ( int a [ ] , int n ) { int max = 1 , len = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( i % 2 == 0 && ( a [ i ] < a [ i + 1 ] ) ) len ++ ; else if ( i % 2 == 1 && ( a [ i ] > a [ i + 1 ] ) ) len ++ ; else { if ( max < len ) max = len ; len = 1 ; } } if ( max < len ) max = len ; return max ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << lenOfLongZigZagArr ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, len, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minpoint ( int arr [ ] , int n , int k ) { int min_point = 0 ; for ( int i = 1 ; i < k - 1 ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) min_point += 1 ; } int final_point = min_point ; for ( int i = k ; i < n ; i ++ ) { if ( arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) + 1 ] && arr [ i - ( k - 1 ) ] < arr [ i - ( k - 1 ) - 1 ] ) min_point -= 1 ; if ( arr [ i - 1 ] < arr [ i ] && arr [ i - 1 ] < arr [ i - 2 ] ) min_point += 1 ; if ( min_point > final_point ) final_point = min_point ; } cout << ( final_point ) ; } int main ( ) { int arr [ ] = { 2 , 1 , 4 , 2 , 3 , 4 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 4 ; minpoint ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, min_point, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CountStrings ( vector < string > & str ) { int size = str . size ( ) ; vector < int > count ( 26 , 0 ) ; vector < bool > visited ( 26 , false ) ; for ( int i = 0 ; i < size ; ++ i ) { for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { if ( visited [ str [ i ] [ j ] ] == false ) count [ str [ i ] [ j ] - ' a ' ] ++ ; visited [ str [ i ] [ j ] ] = true ; } for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { visited [ str [ i ] [ j ] ] = false ; } } for ( int i = 0 ; i < 26 ; ++ i ) { cout << count [ i ] << " ▁ " ; } } int main ( ) { vector < string > str = { " i " , " will " , " practice " , " everyday " } ; CountStrings ( str ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSubArray ( int * a , int n , int k ) { int pref [ n ] ; pref [ 0 ] = 0 ; for ( int i = 1 ; i < n - 1 ; ++ i ) { pref [ i ] = pref [ i - 1 ] ; if ( a [ i ] > a [ i - 1 ] && a [ i ] > a [ i + 1 ] ) pref [ i ] ++ ; } int peak = 0 , left = 0 ; for ( int i = 0 ; i + k - 1 < n ; ++ i ) if ( pref [ i + k - 2 ] - pref [ i ] > peak ) { peak = pref [ i + k - 2 ] - pref [ i ] ; left = i ; } cout << " Left ▁ = ▁ " << left + 1 << endl ; cout << " Right ▁ = ▁ " << left + k << endl ; cout << " Peak ▁ = ▁ " << peak << endl ; } int main ( ) { int arr [ ] = { 3 , 2 , 3 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; findSubArray ( arr , n , k ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void distanceSort ( int arr [ ] , int K , int n ) { vector < int > vd [ n ] ; int pos ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == K ) { pos = i ; break ; } } int i = pos - 1 , j = pos + 1 ; vd [ 0 ] . push_back ( arr [ pos ] ) ; while ( i >= 0 ) { vd [ pos - i ] . push_back ( arr [ i ] ) ; -- i ; } while ( j < n ) { vd [ j - pos ] . push_back ( arr [ j ] ) ; ++ j ; } for ( int i = 0 ; i <= max ( pos , n - pos - 1 ) ; ++ i ) { sort ( begin ( vd [ i ] ) , end ( vd [ i ] ) ) ; for ( auto element : vd [ i ] ) cout << element << " ▁ " ; } } int main ( ) { int arr [ ] = { 14 , 1101 , 10 , 35 , 0 } , K = 35 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; distanceSort ( arr , K , n ) ; return 0 ; }

Index/key variables: i, j, n, pos
Accumulator variables: i, stdc
Iterator variables: element, i