dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define db  double
void findVolume ( db u , db v , db w , db U , db V , db W , db b ) { db uPow = pow ( u , 2 ) ; db vPow = pow ( v , 2 ) ; db wPow = pow ( w , 2 ) ; db UPow = pow ( U , 2 ) ; db VPow = pow ( V , 2 ) ; db WPow = pow ( W , 2 ) ; db a = 4 * ( uPow * vPow * wPow ) - uPow * pow ( ( vPow + wPow - UPow ) , 2 ) - vPow * pow ( ( wPow + uPow - VPow ) , 2 ) - wPow * pow ( ( uPow + vPow - WPow ) , 2 ) + ( vPow + wPow - UPow ) * ( wPow + uPow - VPow ) * ( uPow + vPow - WPow ) ; db vol = sqrt ( a ) ; vol /= b ; cout << fixed << setprecision ( 4 ) << vol ; } int main ( ) { db u = 1000 , v = 1000 , w = 1000 ; db U = 3 , V = 4 , W = 5 ; db b = 12 ; findVolume ( u , v , w , U , V , W , b ) ; return 0 ; }

Accumulator variables: stdc, vol
C++ program:
#include <bits/stdc++.h>
using namespace std ; void makePolygon ( float a ) { float n = 360 / ( 180 - a ) ; if ( n == ( int ) n ) cout << " YES " ; else cout << " NO " ; } int main ( ) { float a = 90 ; makePolygon ( a ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getQuadrant ( int X , int Y , int R , int PX , int PY ) { if ( PX == X && PY == Y ) return 0 ; int val = pow ( ( PX - X ) , 2 ) + pow ( ( PY - Y ) , 2 ) ; if ( val > pow ( R , 2 ) ) return -1 ; if ( PX > X && PY >= Y ) return 1 ; if ( PX <= X && PY > Y ) return 2 ; if ( PX < X && PY <= Y ) return 3 ; if ( PX >= X && PY < Y ) return 4 ; } int main ( ) { int X = 0 , Y = 3 ; int R = 2 ; int PX = 1 , PY = 4 ; int ans = getQuadrant ( X , Y , R , PX , PY ) ; if ( ans == -1 ) cout << " Lies ▁ Outside ▁ the ▁ circle " << endl ; else if ( ans == 0 ) cout << " Coincides ▁ with ▁ centre " << endl ; else cout << ans << " ▁ Quadrant " << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int hexadecagonalNum ( long int n ) { return ( ( 14 * n * n ) - 12 * n ) / 2 ; } int main ( ) { long int n = 5 ; cout << n << " th ▁ Hexadecagonal ▁ number ▁ : ▁ " ; cout << hexadecagonalNum ( n ) ; cout << endl ; n = 9 ; cout << n << " th ▁ Hexadecagonal ▁ number ▁ : ▁ " ; cout << hexadecagonalNum ( n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int x ) { Node * temp = new Node ; temp -> data = x ; temp -> left = temp -> right = NULL ; return temp ; } bool isLeaf ( Node * t ) { return ( ( t -> left == NULL ) && ( t -> right == NULL ) ) ; } void findFirstUnmatch ( Node * root1 , Node * root2 ) { if ( root1 == NULL root2 == NULL ) return ; stack < Node * > s1 , s2 ; s1 . push ( root1 ) ; s2 . push ( root2 ) ; while ( ! s1 . empty ( ) || ! s2 . empty ( ) ) { if ( s1 . empty ( ) || s2 . empty ( ) ) return ; Node * temp1 = s1 . top ( ) ; s1 . pop ( ) ; while ( temp1 && ! isLeaf ( temp1 ) ) { s1 . push ( temp1 -> right ) ; s1 . push ( temp1 -> left ) ; temp1 = s1 . top ( ) ; s1 . pop ( ) ; } Node * temp2 = s2 . top ( ) ; s2 . pop ( ) ; while ( temp2 && ! isLeaf ( temp2 ) ) { s2 . push ( temp2 -> right ) ; s2 . push ( temp2 -> left ) ; temp2 = s2 . top ( ) ; s2 . pop ( ) ; } if ( temp1 != NULL && temp2 != NULL ) { if ( temp1 -> data != temp2 -> data ) { cout << " First ▁ non ▁ matching ▁ leaves ▁ : ▁ " << temp1 -> data << " ▁ " << temp2 -> data << endl ; return ; } } } } int main ( ) { struct Node * root1 = newNode ( 5 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 7 ) ; root1 -> left -> left = newNode ( 10 ) ; root1 -> left -> right = newNode ( 11 ) ; struct Node * root2 = newNode ( 6 ) ; root2 -> left = newNode ( 10 ) ; root2 -> right = newNode ( 15 ) ; findFirstUnmatch ( root1 , root2 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int intersection ( int n ) { return n * ( n - 1 ) ; } int main ( ) { cout << intersection ( 3 ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int main ( ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; cout << ax + bx - cx << " , ▁ " << ay + by - cy << endl ; cout << ax + cx - bx << " , ▁ " << ay + cy - by << endl ; cout << cx + bx - ax << " , ▁ " << cy + by - ax << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; float area ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { return abs ( ( x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ) / 2.0 ) ; } bool check ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 , int x , int y ) { float A = area ( x1 , y1 , x2 , y2 , x3 , y3 ) + area ( x1 , y1 , x4 , y4 , x3 , y3 ) ; float A1 = area ( x , y , x1 , y1 , x2 , y2 ) ; float A2 = area ( x , y , x2 , y2 , x3 , y3 ) ; float A3 = area ( x , y , x3 , y3 , x4 , y4 ) ; float A4 = area ( x , y , x1 , y1 , x4 , y4 ) ; return ( A == A1 + A2 + A3 + A4 ) ; } int main ( ) { if ( check ( 0 , 10 , 10 , 0 , 0 , -10 , -10 , 0 , 10 , 15 ) ) cout << " yes " ; else cout << " no " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; int maxOfLeftElement ( Node * root ) { int res = INT_MIN ; if ( root == NULL ) return res ; if ( root -> left != NULL ) res = root -> left -> data ; return max ( { maxOfLeftElement ( root -> left ) , res , maxOfLeftElement ( root -> right ) } ) ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { Node * root = newNode ( 7 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 2 ) ; root -> right -> right = newNode ( 1 ) ; cout << maxOfLeftElement ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaximumPieces ( int n ) { return 1 + n * ( n + 1 ) / 2 ; } int main ( ) { cout << findMaximumPieces ( 3 ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define sq ( x )  ((x) * (x))
#define EPS  1e-6
#define N  5
struct point { int x , y ; point ( ) { } point ( int x , int y ) : x ( x ) , y ( y ) { } } ; struct line { int a , b , c ; line ( int a , int b , int c ) : a ( a ) , b ( b ) , c ( c ) { } } ; double dist ( double x , double y , point p ) { return sqrt ( sq ( x - p . x ) + sq ( y - p . y ) ) ; } double compute ( point p [ ] , int n , line l , double X ) { double res = 0 ; double Y = -1 * ( l . c + l . a * X ) / l . b ; for ( int i = 0 ; i < n ; i ++ ) res += dist ( X , Y , p [ i ] ) ; return res ; } double findOptimumCostUtil ( point p [ ] , int n , line l ) { double low = -1e6 ; double high = 1e6 ; while ( ( high - low ) > EPS ) { double mid1 = low + ( high - low ) / 3 ; double mid2 = high - ( high - low ) / 3 ; double dist1 = compute ( p , n , l , mid1 ) ; double dist2 = compute ( p , n , l , mid2 ) ; if ( dist1 < dist2 ) high = mid2 ; else low = mid1 ; } return compute ( p , n , l , ( low + high ) / 2 ) ; } double findOptimumCost ( int points [ N ] [ 2 ] , line l ) { point p [ N ] ; for ( int i = 0 ; i < N ; i ++ ) p [ i ] = point ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ; return findOptimumCostUtil ( p , N , l ) ; } int main ( ) { line l ( 1 , -1 , -3 ) ; int points [ N ] [ 2 ] = { { -3 , -2 } , { -1 , 0 } , { -1 , 2 } , { 1 , 2 } , { 3 , 4 } } ; cout << findOptimumCost ( points , l ) << endl ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, res, stdc
Iterator variables: i
Class/struct names: line, point
C++ program:
#include <bits/stdc++.h>
using namespace std ; int segmentUnionLength ( const vector < pair < int , int > > & seg ) { int n = seg . size ( ) ; vector < pair < int , bool > > points ( n * 2 ) ; for ( int i = 0 ; i < n ; i ++ ) { points [ i * 2 ] = make_pair ( seg [ i ] . first , false ) ; points [ i * 2 + 1 ] = make_pair ( seg [ i ] . second , true ) ; } sort ( points . begin ( ) , points . end ( ) ) ; int result = 0 ; int Counter = 0 ; for ( unsigned i = 0 ; i < n * 2 ; i ++ ) { if ( Counter ) result += ( points [ i ] . first - points [ i - 1 ] . first ) ; ( points [ i ] . second ) ? Counter -- : Counter ++ ; } return result ; } int main ( ) { vector < pair < int , int > > segments ; segments . push_back ( make_pair ( 2 , 5 ) ) ; segments . push_back ( make_pair ( 4 , 8 ) ) ; segments . push_back ( make_pair ( 9 , 12 ) ) ; cout << segmentUnionLength ( segments ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: Counter, i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findElements ( int arr [ ] , int N ) { int i = 0 ; vector < int > missing ; set < int > duplicate ; set < int > :: iterator it ; while ( i != N ) { cout << i << " ▁ # ▁ " ; if ( arr [ i ] != arr [ arr [ i ] - 1 ] ) { swap ( arr [ i ] , arr [ arr [ i ] - 1 ] ) ; } else { i ++ ; } } for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != i + 1 ) { missing . push_back ( i + 1 ) ; duplicate . insert ( arr [ i ] ) ; } } cout << " Missing ▁ Numbers : ▁ " ; for ( auto & it : missing ) cout << it << ' ▁ ' ; cout << " Duplicate Numbers : " for ( auto & it : duplicate ) cout << it << ' ▁ ' ; } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 2 , 4 , 5 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findElements ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossible ( multiset < int > A , multiset < int > B , set < int > C , int N ) { if ( A . size ( ) == 0 || B . size ( ) == 0 ) { if ( C . size ( ) == N ) { return true ; } else { return false ; } } bool ans = false ; for ( auto x : A ) { for ( auto y : B ) { multiset < int > _A = A ; _A . erase ( _A . find ( x ) ) ; multiset < int > _B = B ; _B . erase ( _B . find ( y ) ) ; set < int > _C = C ; _C . insert ( ( x + y ) % N ) ; ans = ( ans || isPossible ( _A , _B , _C , N ) ) ; } } return ans ; } void rearrangeArray ( int arr [ ] , int N , int K ) { multiset < int > A ; for ( int i = 0 ; i < N ; i ++ ) { A . insert ( arr [ i ] % N ) ; } multiset < int > B ; for ( int i = 0 ; i < N ; i ++ ) { B . insert ( ( i * K ) % N ) ; } set < int > C ; if ( isPossible ( A , B , C , N ) ) { cout << " YES " ; } else { cout << " NO " ; } } int main ( ) { int arr [ ] = { 1 , 2 , 0 } ; int K = 5 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrangeArray ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x, y
Boolean variables: ans
C++ program:
#include <bits/stdc++.h>
using namespace std ; int factorTree ( int N ) { int height = 0 ; while ( N > 1 ) { bool flag = false ; for ( int i = 2 ; i <= sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { N = N / i ; flag = true ; break ; } } height ++ ; if ( ! flag ) { break ; } } return height ; } int main ( ) { int N = 48 ; cout << factorTree ( N ) ; return 0 ; }

Accumulator variables: height, i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMaxK ( int N ) { int p = log2 ( N ) ; return pow ( 2 , p ) ; } int main ( ) { int N = 5 ; cout << findMaxK ( N ) - 1 << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void build_tree ( vector < int > & a , vector < int > & seg_tree , int v , int tl , int tr ) { if ( tl == tr ) { if ( a [ tl ] == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; build_tree ( a , seg_tree , v * 2 , tl , tm ) ; build_tree ( a , seg_tree , v * 2 + 1 , tm + 1 , tr ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } int frequency_zero ( int v , int tl , int tr , int l , int r , vector < int > & seg_tree ) { if ( l > r ) return 0 ; if ( l == tl && r == tr ) { return seg_tree [ v ] ; } int tm = ( tl + tr ) / 2 ; return frequency_zero ( v * 2 , tl , tm , l , min ( r , tm ) , seg_tree ) + frequency_zero ( v * 2 + 1 , tm + 1 , tr , max ( l , tm + 1 ) , r , seg_tree ) ; } void update ( int v , int tl , int tr , int pos , int new_val , vector < int > & seg_tree ) { if ( tl == tr ) { if ( new_val == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; if ( pos <= tm ) update ( v * 2 , tl , tm , pos , new_val , seg_tree ) ; else update ( v * 2 + 1 , tm + 1 , tr , pos , new_val , seg_tree ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } void solve ( int n , int q , vector < int > & arr , vector < vector < int > > & query ) { vector < int > seg_tree ( 4 * n + 1 , 0 ) ; build_tree ( arr , seg_tree , 1 , 0 , n - 1 ) ; for ( int i = 1 ; i <= q ; i ++ ) { if ( query [ i - 1 ] [ 0 ] == 1 ) { int l = query [ i - 1 ] [ 1 ] ; int r = query [ i - 1 ] [ 2 ] ; cout << frequency_zero ( 1 , 0 , n - 1 , l , r , seg_tree ) << ' ' ; } else { arr [ query [ i - 1 ] [ 1 ] ] = query [ i - 1 ] [ 2 ] ; int pos = query [ i - 1 ] [ 1 ] ; int new_val = query [ i - 1 ] [ 2 ] ; update ( 1 , 0 , n - 1 , pos , new_val , seg_tree ) ; } } } int main ( ) { vector < int > arr = { 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 } ; int Q = 5 ; vector < vector < int > > query = { { 1 , 5 , 14 } , { 2 , 6 , 1 } , { 1 , 0 , 8 } , { 2 , 13 , 0 } , { 1 , 6 , 18 } } ; int N = arr . size ( ) ; solve ( N , Q , arr , query ) ; return 0 ; }

Index/key variables: tl, v
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define InF  99999
struct number { int no ; int level ; public : number ( ) { } number ( int n , int l ) : no ( n ) , level ( l ) { } } ; void findnthnumber ( int n ) { queue < number > q ; struct number r ( 0 , 1 ) ; q . push ( r ) ; while ( ! q . empty ( ) ) { struct number temp = q . front ( ) ; q . pop ( ) ; if ( temp . no >= InF temp . no <= - InF ) break ; if ( temp . no == n ) { cout << " Found ▁ number ▁ n ▁ at ▁ level ▁ " << temp . level - 1 ; break ; } q . push ( number ( temp . no + temp . level , temp . level + 1 ) ) ; q . push ( number ( temp . no - temp . level , temp . level + 1 ) ) ; } } int main ( ) { findnthnumber ( 13 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: number
C++ program:
#include <bits/stdc++.h>
using namespace std ; int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) { int mat [ 2 ] [ W + 1 ] ; memset ( mat , 0 , sizeof ( mat ) ) ; int i = 0 ; while ( i < n ) { int j = 0 ; if ( i % 2 != 0 ) { while ( ++ j <= W ) { if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ; else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ; } } else { while ( ++ j <= W ) { if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ; else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ; } } i ++ ; } return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ; } int main ( ) { int val [ ] = { 7 + D2 : N7 , 8 , 4 } , wt [ ] = { 3 , 8 , 6 } , W = 10 , n = 3 ; cout << KnapSack ( val , wt , n , W ) << endl ; return 0 ; }

Index/key variables: W, i, j
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; bool can_empty ( ll a , ll b , ll c ) { if ( ( a + b + c ) % 4 != 0 ) return false ; else { int m = min ( a , min ( b , c ) ) ; if ( m < ( ( a + b + c ) / 4 ) ) return false ; } return true ; } int main ( ) { ll a = 4 , b = 2 , c = 2 ; cout << ( can_empty ( a , b , c ) ? " true " : " false " ) << endl ; a = 3 , b = 4 , c = 2 ; cout << ( can_empty ( a , b , c ) ? " true " : " false " ) << endl ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; double Avgdifference ( double arr [ ] , int N , int K ) { double min = 1000000 , max = -1 ; for ( int i = 0 ; i <= N - K ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < K ; j ++ ) { sum += arr [ i + j ] ; } if ( min > sum ) min = sum ; if ( max < sum ) max = sum ; } return ( max - min ) / K ; } int main ( ) { double arr [ ] = { 3 , 8 , 9 , 15 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; cout << Avgdifference ( arr , N , K ) ; return 0 ; }

Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > find ( int n ) { vector < int > ans ; int sum = 0 ; int i ; int sign = ( n >= 0 ? 1 : -1 ) ; n = abs ( n ) ; for ( i = 1 ; sum < n ; i ++ ) { ans . push_back ( sign * i ) ; sum += i ; } if ( sum > sign * n ) { if ( i % 2 ) { sum -= n ; if ( sum % 2 ) { ans . push_back ( sign * i ) ; sum += i ++ ; } ans [ ( sum / 2 ) - 1 ] *= -1 ; } else { sum -= n ; if ( sum % 2 ) { sum -- ; ans . push_back ( sign * i ) ; ans . push_back ( sign * -1 * ( i + 1 ) ) ; } ans [ ( sum / 2 ) - 1 ] *= -1 ; } } return ans ; } int main ( ) { int n = 20 ; if ( n == 0 ) cout << " Minimum ▁ number ▁ of ▁ Steps : ▁ 0 STRNEWLINE Step ▁ sequence : STRNEWLINE 0" ; else { vector < int > a = find ( n ) ; cout << " Minimum ▁ number ▁ of ▁ Steps : ▁ " << a . size ( ) << " Step sequence : " for ( int i : a ) cout << i << " ▁ " ; } return 0 ; }

Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MaxRange ( vector < int > A , int n ) { vector < int > left ( n ) , right ( n ) ; stack < pair < int , int > > s ; s . push ( { INT_MAX , -1 } ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( s . top ( ) . first < A [ i ] ) s . pop ( ) ; left [ i ] = s . top ( ) . second ; s . push ( { A [ i ] , i } ) ; } while ( ! s . empty ( ) ) s . pop ( ) ; s . push ( make_pair ( INT_MAX , n ) ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( s . top ( ) . first < A [ i ] ) s . pop ( ) ; right [ i ] = s . top ( ) . second ; s . push ( { A [ i ] , i } ) ; } for ( int i = 0 ; i < n ; i ++ ) { cout << left [ i ] + 1 << ' ▁ ' << right [ i ] - 1 << " STRNEWLINE " ; } } int main ( ) { vector < int > arr { 1 , 3 , 2 } ; int n = arr . size ( ) ; MaxRange ( 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 nthNumber ( int n ) { int divs [ 1000000 ] ; bool vis [ 1000000 ] ; int cnt = 0 ; for ( int i = 2 ; cnt < n ; i ++ ) { if ( divs [ i ] == 0 ) { for ( int j = 2 * i ; j < 1000000 ; j += i ) { if ( vis [ j ] ) { continue ; } vis [ j ] = 1 ; int currNum = j ; int count = 0 ; while ( currNum % i == 0 ) { divs [ j ] ++ ; currNum = currNum / i ; count ++ ; } if ( currNum == 1 && count == 3 && divs [ j ] == 3 ) { cnt ++ ; } else if ( currNum != 1 && divs [ currNum ] == 0 && count == 1 && divs [ j ] == 1 ) { cnt ++ ; } if ( cnt == n ) { return j ; } } } } return -1 ; } int main ( ) { int N = 24 ; cout << nthNumber ( N ) << endl ; return 0 ; }

Index/key variables: currNum, i, j
Accumulator variables: cnt, count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findkey ( int A , int B , int C ) { int ans = 0 ; int cur = 1 ; while ( A > 0 ) { int a = A % 10 ; int b = B % 10 ; int c = C % 10 ; A = A / 10 ; B = B / 10 ; C = C / 10 ; int m = max ( a , max ( c , b ) ) ; ans += cur * m ; cur = cur * 10 ; } return ans ; } int main ( ) { int A = 3521 , B = 2452 , C = 1352 ; cout << findkey ( A , B , C ) ; return 0 ; }

Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int distinctGCDs ( int arr [ ] , int N ) { int M = -1 , ans = 0 ; map < int , int > Mp ; for ( int i = 0 ; i < N ; i ++ ) { M = max ( M , arr [ i ] ) ; Mp [ arr [ i ] ] = 1 ; } for ( int i = 1 ; i <= M ; i ++ ) { int currGcd = 0 ; for ( int j = i ; j <= M ; j += i ) { if ( Mp [ j ] ) { currGcd = __gcd ( currGcd , j ) ; if ( currGcd == i ) { ans ++ ; break ; } } } } return ans ; } int main ( ) { int arr [ ] = { 3 , 11 , 14 , 6 , 12 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << distinctGCDs ( arr , N ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TreeNode { int val ; TreeNode * left , * right ; TreeNode ( int v ) { val = v ; left = NULL ; right = NULL ; } } ; int findCompressValue ( vector < int > arr ) { int ans = 0 ; int getBit = 1 ; for ( int i = 0 ; i < 32 ; i ++ ) { int S = 0 ; int NS = 0 ; for ( int j : arr ) { if ( getBit & j ) S += 1 ; else NS += 1 ; } if ( S > NS ) ans += pow ( 2 , i ) ; getBit <<= 1 ; } return ans ; } void diagonalOrder ( TreeNode * root , int d , map < int , vector < int > > & mp ) { if ( ! root ) return ; mp [ d ] . push_back ( root -> val ) ; diagonalOrder ( root -> left , d + 1 , mp ) ; diagonalOrder ( root -> right , d , mp ) ; } int findInteger ( TreeNode * root ) { map < int , vector < int > > mp ; diagonalOrder ( root , 0 , mp ) ; vector < int > arr ; for ( auto i : mp ) arr . push_back ( findCompressValue ( i . second ) ) ; return findCompressValue ( arr ) ; } int main ( ) { TreeNode * root = new TreeNode ( 6 ) ; root -> left = new TreeNode ( 5 ) ; root -> right = new TreeNode ( 3 ) ; root -> left -> left = new TreeNode ( 3 ) ; root -> left -> right = new TreeNode ( 5 ) ; root -> right -> left = new TreeNode ( 3 ) ; root -> right -> right = new TreeNode ( 4 ) ; cout << findInteger ( root ) ; return 0 ; }

Index/key variables: d
Accumulator variables: NS, S, ans, i, stdc
Iterator variables: i, j
Class/struct names: TreeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max ( int a , int b ) { return ( a > b ) ? a : b ; } int eggDrop ( int n , int k ) { if ( k == 1 k == 0 ) return k ; if ( n == 1 ) return k ; int min = INT_MAX , x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } int main ( ) { int n = 2 , k = 10 ; cout << " Minimum ▁ number ▁ of ▁ trials ▁ " " in ▁ worst ▁ case ▁ with ▁ " << n << " ▁ eggs ▁ and ▁ " << k << " ▁ floors ▁ is ▁ " << eggDrop ( n , k ) << endl ; return 0 ; }

Accumulator variables: stdc, x
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void kthDigitFromLast ( int n , int k ) { if ( k <= 0 ) { cout << -1 << endl ; return ; } while ( ( k - 1 ) > 0 && n > 0 ) { n = n / 10 ; k -- ; } if ( n == 0 ) { cout << -1 << endl ; } else { cout << n % 10 << endl ; } } int main ( ) { int n = 2354 ; int k = 2 ; kthDigitFromLast ( n , k ) ; }

Accumulator variables: k, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void EditDistDP ( string str1 , string str2 ) { int len1 = str1 . length ( ) ; int len2 = str2 . length ( ) ; int DP [ 2 ] [ len1 + 1 ] ; memset ( DP , 0 , sizeof DP ) ; for ( int i = 0 ; i <= len1 ; i ++ ) DP [ 0 ] [ i ] = i ; for ( int i = 1 ; i <= len2 ; i ++ ) { for ( int j = 0 ; j <= len1 ; j ++ ) { if ( j == 0 ) DP [ i % 2 ] [ j ] = i ; else if ( str1 [ j - 1 ] == str2 [ i - 1 ] ) { DP [ i % 2 ] [ j ] = DP [ ( i - 1 ) % 2 ] [ j - 1 ] ; } else { DP [ i % 2 ] [ j ] = 1 + min ( DP [ ( i - 1 ) % 2 ] [ j ] , min ( DP [ i % 2 ] [ j - 1 ] , DP [ ( i - 1 ) % 2 ] [ j - 1 ] ) ) ; } } } cout << DP [ len2 % 2 ] [ len1 ] << endl ; } int main ( ) { string str1 = " food " ; string str2 = " money " ; EditDistDP ( str1 , str2 ) ; return 0 ; }

Index/key variables: i, j, len1
Accumulator variables: i, j, stdc
Iterator variables: i, j