dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumCostToMergeK ( int arr [ ] , int K , int N ) { if ( ( N - 1 ) % ( K - 1 ) != 0 ) { return -1 ; } int prefixSum [ N + 1 ] = { 0 } ; for ( int i = 1 ; i < ( N + 1 ) ; i ++ ) { prefixSum [ i ] = ( prefixSum [ i - 1 ] + arr [ i - 1 ] ) ; } int dp [ N ] [ N ] ; memset ( dp , 0 , sizeof ( dp ) ) ; for ( int L = K ; L < ( N + 1 ) ; L ++ ) { for ( int i = 0 ; i < ( N - L + 1 ) ; i ++ ) { int j = i + L - 1 ; if ( L > K ) { int temp = INT_MAX ; for ( int x = i ; x < j ; x += K - 1 ) { temp = min ( temp , dp [ i ] [ x ] + dp [ x + 1 ] [ j ] ) ; } dp [ i ] [ j ] = temp ; } if ( ( L - 1 ) % ( K - 1 ) == 0 ) { dp [ i ] [ j ] += ( prefixSum [ j + 1 ] - prefixSum [ i ] ) ; } } } return dp [ 0 ] [ N - 1 ] ; } int main ( ) { int arr [ ] = { 3 , 5 , 1 , 2 , 6 } ; int K = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimumCostToMergeK ( arr , K , N ) ; }

Index/key variables: N, i, j, x
Accumulator variables: L, i, stdc, x
Iterator variables: L, i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  8
int check ( int memo [ ] [ N ] , int i , int j , int * A ) { if ( i == N - 1 ) return 1 ; if ( memo [ i ] [ j ] != -1 ) return memo [ i ] [ j ] ; int flag = 0 , k ; for ( k = i + 1 ; k < N ; k ++ ) { if ( A [ k ] - A [ i ] > j + 1 ) break ; if ( A [ k ] - A [ i ] >= j - 1 && A [ k ] - A [ i ] <= j + 1 ) flag = check ( memo , k , A [ k ] - A [ i ] , A ) ; if ( flag ) break ; } memo [ i ] [ j ] = flag ; return memo [ i ] [ j ] ; } void checkEndReach ( int A [ ] , int K ) { int memo [ N ] [ N ] ; memset ( memo , -1 , sizeof ( memo ) ) ; int startIndex = 1 ; if ( check ( memo , startIndex , K , A ) ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int A [ ] = { 0 , 1 , 3 , 5 , 6 , 8 , 12 , 17 } ; int K = 1 ; checkEndReach ( A , K ) ; return 0 ; }

Index/key variables: N, i, j, k
Accumulator variables: k, stdc
Iterator variables: k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Max_Sum ( int arr [ ] , int K , int N ) { int dp [ N + 1 ] ; memset ( dp , 0 , sizeof ( dp ) ) ; int prefix [ N + 1 ] ; prefix [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ] ; } dp [ 0 ] = 0 ; for ( int i = 1 ; i < K ; i ++ ) { dp [ i ] = prefix [ i ] ; } for ( int i = K ; i <= N ; ++ i ) { for ( int j = i ; j >= ( i - K + 1 ) ; j -- ) { dp [ i ] = max ( dp [ i ] , dp [ j - 1 ] + prefix [ i ] - prefix [ j ] ) ; } } return dp [ N ] ; } int main ( ) { int arr [ ] = { 4 , 12 , 22 , 18 , 34 , 12 , 25 } ; int N = sizeof ( arr ) / sizeof ( int ) ; int K = 5 ; cout << Max_Sum ( arr , K , N ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binomialCoeff ( int n , int k ) { int C [ n + 1 ] [ k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } int waysToSplitN ( int k , int n , int P ) { int new_N = n - k * P ; return binomialCoeff ( new_N + k - 1 , new_N ) ; } int main ( ) { int K = 3 , N = 8 , P = 2 ; cout << waysToSplitN ( K , N , P ) ; return 0 ; }

Index/key variables: i, j, k, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( vector < int > & a ) { int n = a . size ( ) ; vector < int > dp ( n + 1 , 0 ) , val ( n + 1 , 0 ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { long long sum = a [ i ] ; int j = i ; while ( j + 1 < n and sum < val [ j + 1 ] ) { j ++ ; sum += a [ j ] ; } dp [ i ] = ( j - i ) + dp [ j + 1 ] ; val [ i ] = sum ; } return dp [ 0 ] ; } int main ( ) { vector < int > arr = { 1 , 5 , 3 , 9 , 1 } ; cout << solve ( arr ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; unsigned int getfullCount ( struct Node * node ) { if ( ! node ) return 0 ; queue < Node * > q ; q . push ( node ) ; int count = 0 ; while ( ! q . empty ( ) ) { struct Node * temp = q . front ( ) ; q . pop ( ) ; if ( temp -> left && temp -> right ) count ++ ; if ( temp -> left != NULL ) q . push ( temp -> left ) ; if ( temp -> right != NULL ) q . push ( temp -> right ) ; } return count ; } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( void ) { struct Node * root = newNode ( 2 ) ; root -> left = newNode ( 7 ) ; root -> right = newNode ( 5 ) ; root -> left -> right = newNode ( 6 ) ; root -> left -> right -> left = newNode ( 1 ) ; root -> left -> right -> right = newNode ( 11 ) ; root -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 4 ) ; cout << getfullCount ( root ) ; return 0 ; }

Accumulator variables: count, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int distinctSimilarSubstrings ( string str ) { int n = str . size ( ) ; if ( n <= 1 ) { return 0 ; } vector < vector < int > > dp ( n + 1 , vector < int > ( n + 1 , 0 ) ) ; unordered_set < string > substrings ; for ( int j = n - 1 ; j >= 0 ; j -- ) { for ( int i = j - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == str [ j ] ) { dp [ i ] [ j ] = dp [ i + 1 ] [ j + 1 ] + 1 ; } else { dp [ i ] [ j ] = 0 ; } if ( dp [ i ] [ j ] >= j - i ) { substrings . insert ( str . substr ( i , j - i ) ) ; } } } return substrings . size ( ) ; } int main ( ) { string str = " geeksgeeksforgeeks " ; cout << distinctSimilarSubstrings ( str ) ; 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 ; #define MAXN  100
const int INF = 1e7 ; int dis [ MAXN ] [ MAXN ] ; int Next [ MAXN ] [ MAXN ] ; void initialise ( int V , vector < vector < int > > & graph ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { dis [ i ] [ j ] = graph [ i ] [ j ] ; if ( graph [ i ] [ j ] == INF ) Next [ i ] [ j ] = -1 ; else Next [ i ] [ j ] = j ; } } } vector < int > constructPath ( int u , int v ) { if ( Next [ u ] [ v ] == -1 ) return { } ; vector < int > path = { u } ; while ( u != v ) { u = Next [ u ] [ v ] ; path . push_back ( u ) ; } return path ; } void floydWarshall ( int V ) { for ( int k = 0 ; k < V ; k ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( dis [ i ] [ k ] == INF dis [ k ] [ j ] == INF ) continue ; if ( dis [ i ] [ j ] > dis [ i ] [ k ] + dis [ k ] [ j ] ) { dis [ i ] [ j ] = dis [ i ] [ k ] + dis [ k ] [ j ] ; Next [ i ] [ j ] = Next [ i ] [ k ] ; } } } } } void printPath ( vector < int > & path ) { int n = path . size ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) cout << path [ i ] << " ▁ - > ▁ " ; cout << path [ n - 1 ] << endl ; } int main ( ) { int V = 4 ; vector < vector < int > > graph = { { 0 , 3 , INF , 7 } , { 8 , 0 , 2 , INF } , { 5 , INF , 0 , 1 } , { 2 , INF , INF , 0 } } ; initialise ( V , graph ) ; floydWarshall ( V ) ; vector < int > path ; cout << " Shortest ▁ path ▁ from ▁ 1 ▁ to ▁ 3 : ▁ " ; path = constructPath ( 1 , 3 ) ; printPath ( path ) ; cout << " Shortest ▁ path ▁ from ▁ 0 ▁ to ▁ 2 : ▁ " ; path = constructPath ( 0 , 2 ) ; printPath ( path ) ; cout << " Shortest ▁ path ▁ from ▁ 3 ▁ to ▁ 2 : ▁ " ; path = constructPath ( 3 , 2 ) ; printPath ( path ) ; return 0 ; }

Index/key variables: MAXN, i, j, k, u, v
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long
vector < ll int > vp [ 2009 ] ; void finding_factors ( ll int n ) { ll int i , a ; for ( i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i == n ) { vp [ n ] . push_back ( i ) ; } else { vp [ n ] . push_back ( i ) ; vp [ n ] . push_back ( n / i ) ; } } } } ll int countSeq ( ll int N , ll int K ) { ll int i , j , k ; ll int dp [ 109 ] [ 109 ] = { 0 } ; for ( i = 1 ; i <= N ; i ++ ) { finding_factors ( i ) ; dp [ 0 ] [ i ] = 0 ; dp [ 1 ] [ i ] = 1 ; } for ( i = 2 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { ll int sum = 0 ; for ( k = 0 ; k < vp [ j ] . size ( ) ; k ++ ) { sum = ( sum + dp [ i - 1 ] [ vp [ j ] [ k ] ] ) ; } dp [ i ] [ j ] = sum ; } } ll int ans = 0 ; for ( j = 1 ; j <= N ; j ++ ) { ans = ( ans + dp [ K ] [ j ] ) ; } return ans ; } int main ( ) { ll int N , K ; N = 3 ; K = 2 ; cout << countSeq ( N , K ) << endl ; return 0 ; }

Index/key variables: K, i, j, k, n
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MAX_value ( vector < vector < int > > arr ) { int row = arr . size ( ) ; int col = arr [ 0 ] . size ( ) ; int dp [ row ] [ col ] ; memset ( dp , sizeof ( dp ) , 0 ) ; int i = 0 , j = 0 ; int c = arr [ 0 ] [ 0 ] , p = 0 ; int d = row ; for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( c < arr [ i ] [ j ] ) { c = arr [ i ] [ j ] ; } if ( i == 0 j == 0 ) { dp [ i ] [ j ] = 1 ; } else { if ( arr [ i - 1 ] [ j - 1 ] == arr [ i ] [ j ] && arr [ i - 1 ] [ j ] == arr [ i ] [ j ] && arr [ i ] [ j - 1 ] == arr [ i ] [ j ] ) { dp [ i ] [ j ] = min ( dp [ i - 1 ] [ j - 1 ] , min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ) + 1 ; } else { dp [ i ] [ j ] = 1 ; } } } } for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( arr [ i ] [ j ] == c ) { if ( p < dp [ i ] [ j ] ) { p = dp [ i ] [ j ] ; } } } } return p * p ; } int main ( ) { vector < vector < int > > arr = { { 9 , 9 , 3 , 3 , 4 , 4 } , { 9 , 9 , 7 , 7 , 7 , 4 } , { 1 , 2 , 7 , 7 , 7 , 4 } , { 4 , 4 , 7 , 7 , 7 , 4 } , { 5 , 5 , 1 , 1 , 2 , 7 } , { 2 , 7 , 1 , 1 , 4 , 4 } } ; cout << MAX_value ( arr ) << endl ; return 0 ; }

Index/key variables: col, i, j, row
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestNum ( int n ) { int res = 1 ; for ( int i = 2 ; ; i *= 2 ) { int length = log10 ( i ) + 1 ; if ( length == n ) return log ( i ) / log ( 2 ) ; } } int main ( ) { int n = 4 ; cout << smallestNum ( n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 100005 ; vector < int > level ( N ) ; const int LG = 20 ; vector < vector < int > > dp ( LG , vector < int > ( N ) ) ; vector < vector < int > > mx ( LG , vector < int > ( N ) ) ; vector < vector < pair < int , int > > > v ( N ) ; int n ; void dfs_lca ( int a , int par , int lev ) { dp [ 0 ] [ a ] = par ; level [ a ] = lev ; for ( auto i : v [ a ] ) { if ( i . first == par ) continue ; mx [ 0 ] [ i . first ] = i . second ; dfs_lca ( i . first , a , lev + 1 ) ; } } void find_ancestor ( ) { for ( int i = 1 ; i < LG ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ; mx [ i ] [ j ] = max ( mx [ i - 1 ] [ j ] , mx [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ) ; } } } int getMax ( int a , int b ) { if ( level [ b ] < level [ a ] ) swap ( a , b ) ; int ans = 0 ; int diff = level [ b ] - level [ a ] ; while ( diff > 0 ) { int log = log2 ( diff ) ; ans = max ( ans , mx [ log ] [ b ] ) ; b = dp [ log ] [ b ] ; diff -= ( 1 << log ) ; } while ( a != b ) { int i = log2 ( level [ a ] ) ; while ( i > 0 && dp [ i ] [ a ] == dp [ i ] [ b ] ) i -- ; ans = max ( ans , mx [ i ] [ a ] ) ; ans = max ( ans , mx [ i ] [ b ] ) ; a = dp [ i ] [ a ] ; b = dp [ i ] [ b ] ; } return ans ; } void compute_lca ( ) { dfs_lca ( 1 , 0 , 0 ) ; find_ancestor ( ) ; } int main ( ) { n = 5 ; v [ 1 ] . push_back ( make_pair ( 2 , 2 ) ) ; v [ 2 ] . push_back ( make_pair ( 1 , 2 ) ) ; v [ 1 ] . push_back ( make_pair ( 3 , 5 ) ) ; v [ 3 ] . push_back ( make_pair ( 1 , 5 ) ) ; v [ 3 ] . push_back ( make_pair ( 4 , 3 ) ) ; v [ 4 ] . push_back ( make_pair ( 3 , 4 ) ) ; v [ 3 ] . push_back ( make_pair ( 5 , 1 ) ) ; v [ 5 ] . push_back ( make_pair ( 3 , 1 ) ) ; compute_lca ( ) ; int queries [ ] [ 2 ] = { { 3 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = 3 ; for ( int i = 0 ; i < q ; i ++ ) { int max_edge = getMax ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ; cout << max_edge << endl ; } return 0 ; }

Index/key variables: a, b, i, j, log
Accumulator variables: diff, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; unsigned int getfullCount ( struct Node * root ) { if ( root == NULL ) return 0 ; int res = 0 ; if ( root -> left && root -> right ) res ++ ; res += ( getfullCount ( root -> left ) + getfullCount ( root -> right ) ) ; return res ; } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( void ) { struct Node * root = newNode ( 2 ) ; root -> left = newNode ( 7 ) ; root -> right = newNode ( 5 ) ; root -> left -> right = newNode ( 6 ) ; root -> left -> right -> left = newNode ( 1 ) ; root -> left -> right -> right = newNode ( 11 ) ; root -> right -> right = newNode ( 9 ) ; root -> right -> right -> left = newNode ( 4 ) ; cout << getfullCount ( root ) ; return 0 ; }

Accumulator variables: res, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDecodingDP ( string digits , int n ) { if ( digits [ 0 ] == '0' ) return 0 ; int count0 = 1 , count1 = 1 , count2 ; for ( int i = 2 ; i <= n ; i ++ ) { count2 = ( ( int ) ( digits [ i - 1 ] != '0' ) * count1 ) + ( int ) ( ( digits [ i - 2 ] == '1' ) or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) * count0 ; count0 = count1 ; count1 = count2 ; } return count1 ; } int main ( ) { string digits = "1234" ; int n = digits . size ( ) ; cout << countDecodingDP ( digits , n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDistance ( vector < vector < int > > & grid ) { if ( ! grid . size ( ) ) return -1 ; int N = grid . size ( ) ; int INF = 1000000 ; vector < vector < int > > dp ( N , vector < int > ( N , 0 ) ) ; grid [ 0 ] [ 0 ] = grid [ 0 ] [ 0 ] == 1 ? 0 : INF ; for ( int i = 1 ; i < N ; i ++ ) grid [ 0 ] [ i ] = grid [ 0 ] [ i ] == 1 ? 0 : grid [ 0 ] [ i - 1 ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) grid [ i ] [ 0 ] = grid [ i ] [ 0 ] == 1 ? 0 : grid [ i - 1 ] [ 0 ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < N ; j ++ ) { grid [ i ] [ j ] = grid [ i ] [ j ] == 1 ? 0 : min ( grid [ i - 1 ] [ j ] , grid [ i ] [ j - 1 ] ) + 1 ; } } if ( grid [ N - 1 ] [ N - 1 ] >= INF ) return -1 ; int maxi = grid [ N - 1 ] [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { grid [ N - 1 ] [ i ] = min ( grid [ N - 1 ] [ i ] , grid [ N - 1 ] [ i + 1 ] + 1 ) ; maxi = max ( grid [ N - 1 ] [ i ] , maxi ) ; } for ( int i = N - 2 ; i >= 0 ; i -- ) { grid [ i ] [ N - 1 ] = min ( grid [ i ] [ N - 1 ] , grid [ i + 1 ] [ N - 1 ] + 1 ) ; maxi = max ( grid [ i ] [ N - 1 ] , maxi ) ; } for ( int i = N - 2 ; i >= 0 ; i -- ) { for ( int j = N - 2 ; j >= 0 ; j -- ) { grid [ i ] [ j ] = min ( grid [ i ] [ j ] , min ( grid [ i + 1 ] [ j ] + 1 , grid [ i ] [ j + 1 ] + 1 ) ) ; maxi = max ( grid [ i ] [ j ] , maxi ) ; } } return ! maxi ? -1 : maxi ; } int main ( ) { vector < vector < int > > arr = { { 0 , 0 , 1 } , { 0 , 0 , 0 } , { 0 , 0 , 0 } } ; cout << maxDistance ( arr ) << endl ; 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 findCost ( vector < vector < int > > cost_mat , int N , int M ) { vector < vector < int > > dp ( N , vector < int > ( M , 0 ) ) ; for ( int i = 0 ; i < M ; i ++ ) dp [ 0 ] [ i ] = cost_mat [ 0 ] [ i ] ; for ( int row = 1 ; row < N ; row ++ ) { for ( int curr_col = 0 ; curr_col < M ; curr_col ++ ) { int val = 999999999 ; for ( int prev_col = 0 ; prev_col < M ; prev_col ++ ) { if ( curr_col != prev_col ) val = min ( val , dp [ row - 1 ] [ prev_col ] ) ; } dp [ row ] [ curr_col ] = val + cost_mat [ row ] [ curr_col ] ; } } int ans = INT_MAX ; for ( int i = 0 ; i < M ; i ++ ) ans = min ( ans , dp [ N - 1 ] [ i ] ) ; return ans ; } int main ( ) { int N = 4 ; int M = 4 ; vector < vector < int > > cost_mat ; cost_mat = { { 4 , 5 , 3 , 2 } , { 6 , 2 , 8 , 1 } , { 6 , 2 , 2 , 1 } , { 0 , 5 , 5 , 1 } } ; cout << findCost ( cost_mat , N , M ) ; return 0 ; }

Index/key variables: curr_col, i, prev_col, row
Accumulator variables: curr_col, i, prev_col, row, stdc
Iterator variables: curr_col, i, prev_col, row
C++ program:
#include <bits/stdc++.h>
using namespace std ; void getPrimesFromSeive ( set < string > & primes ) { bool prime [ 1000001 ] ; memset ( prime , true , sizeof ( prime ) ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * i ; j <= 1000000 ; j += i ) prime [ j ] = false ; } } for ( int i = 2 ; i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) primes . insert ( to_string ( i ) ) ; } } int splitIntoPrimes ( string number ) { int numLen = number . length ( ) ; int splitDP [ numLen + 1 ] ; memset ( splitDP , -1 , sizeof ( splitDP ) ) ; set < string > primes ; getPrimesFromSeive ( primes ) ; for ( int i = 1 ; i <= numLen ; i ++ ) { if ( i <= 6 && ( primes . find ( number . substr ( 0 , i ) ) != primes . end ( ) ) ) splitDP [ i ] = 1 ; if ( splitDP [ i ] != -1 ) { for ( int j = 1 ; j <= 6 && i + j <= numLen ; j ++ ) { if ( primes . find ( number . substr ( i , j ) ) != primes . end ( ) ) { if ( splitDP [ i + j ] == -1 ) splitDP [ i + j ] = 1 + splitDP [ i ] ; else splitDP [ i + j ] = min ( splitDP [ i + j ] , 1 + splitDP [ i ] ) ; } } } } return splitDP [ numLen ] ; } int main ( ) { cout << splitIntoPrimes ( "13499315" ) << " STRNEWLINE " ; cout << splitIntoPrimes ( "43" ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i, j, numLen
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right , * nextRight ; } ; void connect ( struct Node * root ) { queue < Node * > q ; q . push ( root ) ; q . push ( NULL ) ; while ( ! q . empty ( ) ) { Node * p = q . front ( ) ; q . pop ( ) ; if ( p != NULL ) { p -> nextRight = q . front ( ) ; if ( p -> left ) q . push ( p -> left ) ; if ( p -> right ) q . push ( p -> right ) ; } else if ( ! q . empty ( ) ) q . push ( NULL ) ; } } struct Node * newnode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = node -> right = node -> nextRight = NULL ; return ( node ) ; } int main ( ) { struct Node * root = newnode ( 10 ) ; root -> left = newnode ( 8 ) ; root -> right = newnode ( 2 ) ; root -> left -> left = newnode ( 3 ) ; root -> right -> right = newnode ( 90 ) ; connect ( root ) ; printf ( " Following ▁ are ▁ populated ▁ nextRight ▁ pointers ▁ in ▁ STRNEWLINE " " the ▁ tree ▁ ( -1 ▁ is ▁ printed ▁ if ▁ there ▁ is ▁ no ▁ nextRight ) ▁ STRNEWLINE " ) ; printf ( " nextRight ▁ of ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , root -> data , root -> nextRight ? root -> nextRight -> data : -1 ) ; printf ( " nextRight ▁ of ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , root -> left -> data , root -> left -> nextRight ? root -> left -> nextRight -> data : -1 ) ; printf ( " nextRight ▁ of ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , root -> right -> data , root -> right -> nextRight ? root -> right -> nextRight -> data : -1 ) ; printf ( " nextRight ▁ of ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , root -> left -> left -> data , root -> left -> left -> nextRight ? root -> left -> left -> nextRight -> data : -1 ) ; printf ( " nextRight ▁ of ▁ % d ▁ is ▁ % d ▁ STRNEWLINE " , root -> right -> right -> data , root -> right -> right -> nextRight ? root -> right -> right -> nextRight -> data : -1 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MOD = 1000000007 ; long long modInv ( long long a , long long p = MOD - 2 ) { long long s = 1 ; while ( p != 1 ) { if ( p % 2 ) s = ( s * a ) % MOD ; a = ( a * a ) % MOD ; p /= 2 ; } return ( a * s ) % MOD ; } long long findCnt ( char x , string y ) { long long ans = 0 ; long long fact [ y . size ( ) + 1 ] = { 1 } ; for ( long long i = 1 ; i <= y . size ( ) ; i ++ ) fact [ i ] = ( fact [ i - 1 ] * i ) % MOD ; for ( long long i = 0 ; i < y . size ( ) ; i ++ ) { if ( y [ i ] == x ) { ans += ( modInv ( fact [ i ] ) * modInv ( fact [ y . size ( ) - i - 1 ] ) ) % MOD ; ans %= MOD ; } } ans *= fact [ ( y . size ( ) - 1 ) ] ; ans %= MOD ; return ans ; } int main ( ) { char x = ' a ' ; string y = " xxayy " ; cout << findCnt ( x , y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, p, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSubSeq ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int count [ n ] = { 1 } ; int prev [ n ] = { -1 } ; memset ( count , 1 , sizeof ( count ) ) ; memset ( prev , -1 , sizeof ( prev ) ) ; int max = 0 ; int maxprev = -1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] % arr [ j ] == 0 && count [ j ] + 1 > count [ i ] ) { count [ i ] = count [ j ] + 1 ; prev [ i ] = j ; } } if ( max < count [ i ] ) { max = count [ i ] ; maxprev = i ; } } int i = maxprev ; while ( i >= 0 ) { if ( arr [ i ] != -1 ) cout << arr [ i ] << " ▁ " ; i = prev [ i ] ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( int ) ; findSubSeq ( arr , n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sortcol ( const pair < int , int > p1 , const pair < int , int > p2 ) { return p1 . second < p2 . second ; } void minPoints ( pair < int , int > points [ ] , int n ) { sort ( points , points + n , sortcol ) ; vector < int > coordinates ; int i = 0 ; while ( i < n ) { int seg = points [ i ] . second ; coordinates . push_back ( seg ) ; int p = i + 1 ; if ( p >= n ) break ; int arrived = points [ p ] . first ; while ( seg >= arrived ) { p += 1 ; if ( p >= n ) break ; arrived = points [ p ] . first ; } i = p ; } for ( auto point : coordinates ) cout << point << " ▁ " ; } int main ( ) { int n = 4 ; int start [ ] = { 4 , 1 , 2 , 5 } ; int end [ ] = { 7 , 3 , 5 , 6 } ; pair < int , int > points [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { points [ i ] = { start [ i ] , end [ i ] } ; } minPoints ( points , n ) ; return 0 ; }

Index/key variables: i, n, p
Accumulator variables: i, p, stdc
Iterator variables: i, point
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( string str , int K ) { int n = str . length ( ) ; long long dp [ K ] [ n ] ; memset ( dp , 0 , sizeof dp ) ; if ( n < K ) return -1 ; else if ( n == K ) return 0 ; long long zeroes = 0 , ones = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '0' ) zeroes ++ ; else ones ++ ; dp [ 0 ] [ i ] = ones * zeroes ; } for ( int s = 1 ; s < K ; s ++ ) { for ( int i = 0 ; i < n ; i ++ ) { dp [ s ] [ i ] = INT_MAX ; ones = 0 ; zeroes = 0 ; for ( int k = i ; k >= 0 ; k -- ) { if ( str [ k ] == '0' ) zeroes ++ ; else ones ++ ; dp [ s ] [ i ] = min ( dp [ s ] [ i ] , + ( ( k - 1 >= 0 ) ? ones * zeroes + dp [ s - 1 ] [ k - 1 ] : INT_MAX ) ) ; } } } return ( dp [ K - 1 ] [ n - 1 ] == INT_MAX ) ? -1 : dp [ K - 1 ] [ n - 1 ] ; } int main ( ) { string S = "0101" ; int K = 2 ; cout << solve ( S , K ) << endl ; return 0 ; }

Index/key variables: K, i, k, n, s
Accumulator variables: i, k, ones, s, stdc, zeroes
Iterator variables: i, k, s