dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findPeak ( vector < int > arr ) { int left = 0 ; int right = arr . size ( ) - 1 ; while ( left < right ) { int mid = left + ( right - left ) / 2 ; if ( arr [ mid ] < arr [ mid + 1 ] ) { left = mid + 1 ; } else { right = mid ; } } return left ; } int BS ( int X , int left , int right , vector < int > arr ) { while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( arr [ mid ] == X ) { return mid ; } else if ( X > arr [ mid ] ) { left = mid + 1 ; } else { right = mid - 1 ; } } return -1 ; } int reverseBS ( int X , int left , int right , vector < int > arr ) { while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( arr [ mid ] == X ) { return mid ; } else if ( X > arr [ mid ] ) { right = mid - 1 ; } else { left = mid + 1 ; } } return -1 ; } void findInMA ( int X , vector < int > mountainArr ) { int peakIndex = findPeak ( mountainArr ) ; int res = -1 ; if ( X >= mountainArr [ 0 ] && X <= mountainArr [ peakIndex ] ) { res = BS ( X , 0 , peakIndex , mountainArr ) ; } if ( res == -1 ) { res = reverseBS ( X , peakIndex + 1 , mountainArr . size ( ) - 1 , mountainArr ) ; } cout << res << endl ; } int main ( ) { int X = 3 ; vector < int > list { 1 , 2 , 3 , 4 , 5 , 3 , 1 } ; findInMA ( X , list ) ; }

Index/key variables: mid, peakIndex
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void rearrange ( int * a , int n , int x ) { for ( int i = 0 ; i < n ; i ++ ) a [ i ] = abs ( a [ i ] ) ; sort ( a , a + n ) ; x = n - x ; int z = count ( a , a + n , 0 ) ; if ( x > n - z ) { cout << " - 1 STRNEWLINE " ; return ; } for ( int i = 0 ; i < n && x > 0 ; i += 2 ) { a [ i ] = - a [ i ] ; x -- ; } for ( int i = n - 1 ; i >= 0 && x > 0 ; i -- ) { if ( a [ i ] > 0 ) { a [ i ] = - a [ i ] ; x -- ; } } for ( int i = 0 ; i < n ; i ++ ) { cout << a [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 0 , -2 , 4 , 5 , -3 } ; int K = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; rearrange ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSubarrayProduct ( vector < int > arr , int n ) { int max_ending_here = 1 ; int min_ending_here = 1 ; int max_so_far = 0 ; int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) { max_ending_here = max_ending_here * arr [ i ] ; min_ending_here = min ( min_ending_here * arr [ i ] , 1 ) ; flag = 1 ; } else if ( arr [ i ] == 0 ) { max_ending_here = 1 ; min_ending_here = 1 ; } else { int temp = max_ending_here ; max_ending_here = max ( min_ending_here * arr [ i ] , 1 ) ; min_ending_here = temp * arr [ i ] ; } if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } if ( flag == 0 && max_so_far == 0 ) return 0 ; return max_so_far ; } int findMaxProduct ( int * a , int n ) { int i = 0 ; int maxProd = -1e9 ; while ( i < n ) { vector < int > v ; v . push_back ( a [ i ] ) ; if ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { v . push_back ( a [ i + 1 ] ) ; i += 1 ; } } else if ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { v . push_back ( a [ i + 1 ] ) ; i += 1 ; } } int prod = maxSubarrayProduct ( v , v . size ( ) ) ; maxProd = max ( maxProd , prod ) ; i ++ ; } return maxProd ; } int main ( ) { int arr [ ] = { 1 , 2 , 10 , 8 , 1 , 100 , 101 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxProduct ( 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 parent [ 1000000 ] ; int root ( int a ) { if ( a == parent [ a ] ) { return a ; } return parent [ a ] = root ( parent [ a ] ) ; } void connect ( int a , int b ) { a = root ( a ) ; b = root ( b ) ; if ( a != b ) { parent [ b ] = a ; } } void connectedComponents ( int n ) { set < int > s ; for ( int i = 0 ; i < n ; i ++ ) { s . insert ( root ( parent [ i ] ) ) ; } cout << s . size ( ) << ' ' ; } void printAnswer ( int N , vector < vector < int > > edges ) { for ( int i = 0 ; i <= N ; i ++ ) { parent [ i ] = i ; } for ( int i = 0 ; i < edges . size ( ) ; i ++ ) { connect ( edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; } connectedComponents ( N ) ; } int main ( ) { int N = 8 ; vector < vector < int > > edges = { { 1 , 0 } , { 0 , 2 } , { 5 , 3 } , { 3 , 4 } , { 6 , 7 } } ; printAnswer ( N , edges ) ; return 0 ; }

Index/key variables: a, b, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void removeZeroRowCol ( vector < vector < int > > & arr ) { int n = arr . size ( ) ; int col [ n + 1 ] = { 0 } ; int row [ n + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < n ; ++ j ) { col [ j ] += ( arr [ i ] [ j ] == 1 ) ; count += ( arr [ i ] [ j ] == 1 ) ; } row [ i ] = count ; } for ( int i = 0 ; i < n ; ++ i ) { if ( row [ i ] == 0 ) { continue ; } for ( int j = 0 ; j < n ; ++ j ) { if ( col [ j ] != 0 ) cout << arr [ i ] [ j ] ; } cout << " STRNEWLINE " ; } } int main ( ) { vector < vector < int > > arr = { { 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 } } ; removeZeroRowCol ( arr ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findOverlapSegement ( int N , int a [ ] , int b [ ] ) { vector < pair < pair < int , int > , int > > tup ; for ( int i = 0 ; i < N ; i ++ ) { int x , y ; x = a [ i ] ; y = b [ i ] ; tup . push_back ( pair < pair < int , int > , int > ( pair < int , int > ( x , y ) , i ) ) ; } sort ( tup . begin ( ) , tup . end ( ) ) ; int curr = tup [ 0 ] . first . second ; int currPos = tup [ 0 ] . second ; for ( int i = 1 ; i < N ; i ++ ) { int Q = tup [ i - 1 ] . first . first ; int R = tup [ i ] . first . first ; if ( Q == R ) { if ( tup [ i - 1 ] . first . second < tup [ i ] . first . second ) cout << tup [ i - 1 ] . second << ' ▁ ' << tup [ i ] . second ; else cout << tup [ i ] . second << ' ▁ ' << tup [ i - 1 ] . second ; return ; } int T = tup [ i ] . first . second ; if ( T <= curr ) { cout << tup [ i ] . second << ' ▁ ' << currPos ; return ; } else { curr = T ; currPos = tup [ i ] . second ; } } cout << " - 1 ▁ - 1" ; } int main ( ) { int a [ ] = { 1 , 2 , 3 , 2 , 2 } ; int b [ ] = { 5 , 10 , 10 , 2 , 15 } ; int N = sizeof ( a ) / sizeof ( int ) ; findOverlapSegement ( N , a , b ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TreeNode { int val ; struct TreeNode * left , * right ; TreeNode ( int x ) { val = x ; left = NULL ; right = NULL ; } } ; void replaceDiag ( TreeNode * root , int d , unordered_map < int , int > & diagMap ) { if ( ! root ) return ; root -> val = diagMap [ d ] ; replaceDiag ( root -> left , d + 1 , diagMap ) ; replaceDiag ( root -> right , d , diagMap ) ; } void getDiagSum ( TreeNode * root , int d , unordered_map < int , int > & diagMap ) { if ( ! root ) return ; if ( diagMap [ d ] > 0 ) diagMap [ d ] += root -> val ; else diagMap [ d ] = root -> val ; getDiagSum ( root -> left , d + 1 , diagMap ) ; getDiagSum ( root -> right , d , diagMap ) ; } void levelOrder ( TreeNode * root ) { queue < TreeNode * > q ; q . push ( root ) ; while ( true ) { int length = q . size ( ) ; if ( ! length ) break ; while ( length ) { auto temp = q . front ( ) ; q . pop ( ) ; cout << temp -> val << " ▁ " ; if ( temp -> left ) q . push ( temp -> left ) ; if ( temp -> right ) q . push ( temp -> right ) ; length -= 1 ; } } } int main ( ) { TreeNode * root = new TreeNode ( 5 ) ; root -> left = new TreeNode ( 6 ) ; root -> right = new TreeNode ( 3 ) ; root -> left -> left = new TreeNode ( 4 ) ; root -> left -> right = new TreeNode ( 9 ) ; root -> right -> right = new TreeNode ( 2 ) ; unordered_map < int , int > diagMap ; getDiagSum ( root , 0 , diagMap ) ; replaceDiag ( root , 0 , diagMap ) ; levelOrder ( root ) ; return 0 ; }

Index/key variables: d
Accumulator variables: length, stdc
Class/struct names: TreeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDivBy3InArray ( int arr [ ] , int N ) { int ans = 0 ; bool taken [ N ] ; memset ( taken , false , sizeof ( taken ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( taken [ i ] == true ) { continue ; } for ( int j = i + 1 ; j < N ; j ++ ) { if ( taken [ j ] == true ) { continue ; } if ( stoi ( to_string ( arr [ i ] ) + to_string ( arr [ j ] ) ) % 3 == 0 || stoi ( to_string ( arr [ j ] ) + to_string ( arr [ i ] ) ) % 3 == 0 ) { ans += 1 ; taken [ i ] = true ; taken [ j ] = true ; } } } return ans ; } int main ( ) { int arr [ ] = { 5 , 3 , 2 , 8 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countDivBy3InArray ( arr , N ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <vector>
using namespace std ; void findMaxLengthSequence ( int N , int arr [ 4 ] ) { int rightmost_element = -1 ; int i = 0 ; int j = N - 1 ; vector < int > sequence ; while ( i <= j ) { if ( arr [ i ] > arr [ j ] ) { if ( arr [ j ] > rightmost_element ) { sequence . push_back ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else if ( arr [ i ] > rightmost_element ) { sequence . push_back ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else break ; } else if ( arr [ i ] < arr [ j ] ) { if ( arr [ i ] > rightmost_element ) { sequence . push_back ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else if ( arr [ j ] > rightmost_element ) { sequence . push_back ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else break ; } else if ( arr [ i ] == arr [ j ] ) { if ( i == j ) { if ( arr [ i ] > rightmost_element ) { sequence . push_back ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } break ; } else { sequence . push_back ( arr [ i ] ) ; int k = i + 1 ; vector < int > max_left ; while ( k < j && arr [ k ] > arr [ k - 1 ] ) { max_left . push_back ( arr [ k ] ) ; k ++ ; } int l = j - 1 ; vector < int > max_right ; while ( l > i && arr [ l ] > arr [ l + 1 ] ) { max_right . push_back ( arr [ l ] ) ; l -- ; } if ( max_left . size ( ) > max_right . size ( ) ) for ( int element : max_left ) sequence . push_back ( element ) ; else for ( int element : max_right ) sequence . push_back ( element ) ; break ; } } } for ( int element : sequence ) printf ( " % d ▁ " , element ) ; } int main ( ) { int N = 4 ; int arr [ ] = { 1 , 3 , 2 , 1 } ; findMaxLengthSequence ( N , arr ) ; }

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: element
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TreeNode { int val ; vector < TreeNode * > children ; TreeNode ( int v ) { val = v ; } } ; double ans = 0.0 ; vector < int > MaxAverage ( TreeNode * root ) { if ( root != NULL && root -> children . size ( ) == 0 ) { ans = max ( ans , ( root -> val ) * ( 1.0 ) ) ; return { root -> val , 1 } ; } vector < int > childResult ( 2 ) ; for ( TreeNode * child : root -> children ) { vector < int > childTotal = MaxAverage ( child ) ; childResult [ 0 ] = childResult [ 0 ] + childTotal [ 0 ] ; childResult [ 1 ] = childResult [ 1 ] + childTotal [ 1 ] ; } int sum = childResult [ 0 ] + root -> val ; int count = childResult [ 1 ] + 1 ; ans = max ( ans , sum / count * 1.0 ) ; return { sum , count } ; } int main ( ) { TreeNode * root = new TreeNode ( 20 ) ; TreeNode * left = new TreeNode ( 12 ) ; TreeNode * right = new TreeNode ( 18 ) ; root -> children . push_back ( left ) ; root -> children . push_back ( right ) ; left -> children . push_back ( new TreeNode ( 11 ) ) ; left -> children . push_back ( new TreeNode ( 3 ) ) ; right -> children . push_back ( new TreeNode ( 15 ) ) ; right -> children . push_back ( new TreeNode ( 8 ) ) ; MaxAverage ( root ) ; printf ( " % 0.1f STRNEWLINE " , ans ) ; }

Accumulator variables: stdc
Class/struct names: TreeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; void canTransformStrings ( string A , string B ) { int n1 = A . size ( ) ; int n2 = B . size ( ) ; int count1A = 0 , count1B = 0 ; int odd1A = 0 , odd1B = 0 ; int even1A = 0 , even1B = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) { if ( A [ i ] == '1' ) count1A ++ ; else { if ( count1A & 1 ) odd1A ++ ; else even1A ++ ; } } for ( int i = 0 ; i < n2 ; i ++ ) { if ( B [ i ] == '1' ) count1B ++ ; else { if ( count1B & 1 ) odd1B ++ ; else even1B ++ ; } } if ( count1A == count1B && odd1A == odd1B && even1A == even1B ) { cout << " Yes " ; } else cout << " No " ; } int main ( ) { string A = "10011" , B = "11100" ; canTransformStrings ( A , B ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count1A, count1B, even1A, even1B, i, odd1A, odd1B, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printAnswer ( int answer [ ] , int N ) { for ( int i = 1 ; i <= N ; i ++ ) { cout << answer [ i ] << " ▁ " ; } } void updateAnswerArray ( int answer [ ] , int N ) { int i = 0 ; while ( answer [ i ] == -1 ) i ++ ; int minimum = answer [ i ] ; while ( i <= N ) { if ( answer [ i ] == -1 ) answer [ i ] = minimum ; else answer [ i ] = min ( minimum , answer [ i ] ) ; minimum = min ( minimum , answer [ i ] ) ; i ++ ; } } void lengthOfSubarray ( vector < int > indices [ ] , set < int > st , int N ) { int answer [ N + 1 ] ; memset ( answer , -1 , sizeof ( answer ) ) ; for ( auto itr : st ) { int start = -1 ; int gap = -1 ; indices [ itr ] . push_back ( N ) ; for ( int i = 0 ; i < indices [ itr ] . size ( ) ; i ++ ) { gap = max ( gap , indices [ itr ] [ i ] - start ) ; start = indices [ itr ] [ i ] ; } if ( answer [ gap ] == -1 ) answer [ gap ] = itr ; } updateAnswerArray ( answer , N ) ; printAnswer ( answer , N ) ; } void smallestPresentNumber ( int arr [ ] , int N ) { vector < int > indices [ N + 1 ] ; set < int > elements ; for ( int i = 0 ; i < N ; i ++ ) { indices [ arr [ i ] ] . push_back ( i ) ; elements . insert ( arr [ i ] ) ; } lengthOfSubarray ( indices , elements , N ) ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 3 , 2 , 3 , 1 , 3 , 2 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; smallestPresentNumber ( arr , N ) ; return ( 0 ) ; }

Index/key variables: gap, i, itr
Accumulator variables: i, stdc
Iterator variables: i, itr
C++ program:
#include <bits/stdc++.h>
using namespace std ; int smallestLeft ( int arr [ ] , int total , int sum , int i , vector < vector < int > > & dp ) { if ( i == 0 ) { return abs ( total - 2 * sum ) ; } if ( dp [ i ] [ sum ] != -1 ) return dp [ i ] [ sum ] ; int X = smallestLeft ( arr , total , sum + arr [ i - 1 ] , i - 1 , dp ) ; int Y = smallestLeft ( arr , total , sum , i - 1 , dp ) ; return dp [ i ] [ sum ] = min ( X , Y ) ; } int UtilSmallestElement ( int arr [ ] , int N ) { int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total += arr [ i ] ; } vector < vector < int > > dp ( N + 1 , vector < int > ( total , -1 ) ) ; cout << smallestLeft ( arr , total , 0 , N , dp ) ; } int main ( ) { int arr [ ] = { 2 , 7 , 4 , 1 , 8 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; UtilSmallestElement ( arr , N ) ; return 0 ; }

Index/key variables: i, sum
Accumulator variables: i, stdc, total
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int SmallestElementLeft ( int arr [ ] , int N ) { int totalSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } int req = totalSum / 2 ; bool dp [ req + 1 ] ; memset ( dp , false , sizeof ( dp ) ) ; dp [ 0 ] = true ; int reach = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = req ; j - arr [ i ] >= 0 ; j -- ) { dp [ j ] = dp [ j ] || dp [ j - arr [ i ] ] ; if ( dp [ j ] ) { reach = max ( reach , j ) ; } } } return totalSum - ( 2 * reach ) ; } int main ( ) { int arr [ ] = { 2 , 2 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << SmallestElementLeft ( arr , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, totalSum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperationsReq ( string str1 , string str2 ) { int N = str1 . length ( ) ; int cntOp = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str1 [ i ] == str2 [ i ] ) { continue ; } int ptr = i ; while ( ptr < N && str1 [ ptr ] != str2 [ ptr ] ) { str1 [ ptr ] = str2 [ ptr ] ; ptr += 2 ; } cntOp ++ ; } return cntOp ; } int main ( ) { string str1 = " abcdef " ; string str2 = " ffffff " ; cout << minOperationsReq ( str1 , str2 ) ; return 0 ; }

Index/key variables: i, ptr
Accumulator variables: cntOp, i, ptr, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isComposite ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } bool isPerfectSquare ( int x ) { int s = sqrt ( x ) ; return ( s * s == x ) ; } bool isFibonacci ( int n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } void ifgcdFibonacci ( int a [ ] , int n , int k ) { vector < int > compositeset ; for ( int i = 0 ; i < n ; i ++ ) { if ( isComposite ( a [ i ] ) && a [ i ] % k == 0 ) { compositeset . push_back ( a [ i ] ) ; } } int gcd = compositeset [ 0 ] ; for ( int i = 1 ; i < compositeset . size ( ) ; i ++ ) { gcd = __gcd ( gcd , compositeset [ i ] ) ; if ( gcd == 1 ) { break ; } } if ( isFibonacci ( gcd ) ) { cout << " Yes " ; return ; } cout << " No " ; return ; } int main ( ) { int arr [ ] = { 34 , 2 , 4 , 8 , 5 , 7 , 11 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; ifgcdFibonacci ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_longest_subarray ( int A [ ] , int N , int K ) { int MaxLen = 0 ; int Len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( K % A [ i ] == 0 ) { Len ++ ; MaxLen = max ( MaxLen , Len ) ; } else { Len = 0 ; } } return MaxLen ; } int main ( ) { int A [ ] = { 2 , 8 , 3 , 10 , 6 , 7 , 4 , 9 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; ; int K = 60 ; cout << find_longest_subarray ( A , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: Len, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minTime ( int meeting [ ] [ 2 ] , int n , vector < int > entrance , int m , vector < int > & exit , int p ) { int ans = INT_MAX ; sort ( entrance . begin ( ) , entrance . end ( ) ) ; sort ( exit . begin ( ) , exit . end ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int u = meeting [ i ] [ 0 ] ; int v = meeting [ i ] [ 1 ] ; auto it1 = upper_bound ( entrance . begin ( ) , entrance . end ( ) , u ) ; auto it2 = lower_bound ( exit . begin ( ) , exit . end ( ) , v ) ; int start = it1 - entrance . begin ( ) - 1 ; int end = it2 - exit . begin ( ) ; if ( start >= 0 && start < m && end >= 0 && end < p ) ans = min ( ans , exit [ end ] - entrance [ start ] ) ; } return ans >= INT_MAX ? -1 : ans ; } int main ( ) { int meeting [ ] [ 2 ] = { { 15 , 19 } , { 5 , 10 } , { 7 , 25 } } ; vector < int > entrance = { 4 , 13 , 25 , 2 } ; vector < int > exit = { 10 , 25 } ; int n = ( sizeof ( meeting ) ) / sizeof ( meeting [ 0 ] ) ; int m = entrance . size ( ) ; int p = exit . size ( ) ; cout << minTime ( meeting , n , entrance , m , exit , p ) << endl ; return 0 ; }

Index/key variables: end, i, start
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void splitArray ( int a [ ] , int n , int k ) { vector < int > first , second ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= k / 2 ) first . push_back ( a [ i ] ) ; else second . push_back ( a [ i ] ) ; } for ( int i = 0 ; i < first . size ( ) ; i ++ ) { cout << first [ i ] << " ▁ " ; } cout << " STRNEWLINE " ; for ( int i = 0 ; i < second . size ( ) ; i ++ ) { cout << second [ i ] << " ▁ " ; } } int main ( ) { int k = 5 ; int a [ ] = { 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = sizeof ( a ) / sizeof ( int ) ; splitArray ( a , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dis ( vector < int > ans , vector < int > attacker ) { return abs ( ans [ 0 ] - attacker [ 0 ] ) + abs ( ans [ 1 ] - attacker [ 1 ] ) ; } vector < vector < int > > findQueens ( vector < vector < int > > & queens , vector < int > & king ) { vector < vector < int > > sol ; vector < vector < int > > attackers ( 8 ) ; for ( int i = 0 ; i < queens . size ( ) ; i ++ ) { if ( king [ 0 ] == queens [ i ] [ 0 ] && king [ 1 ] > queens [ i ] [ 1 ] ) { if ( ( attackers [ 3 ] . size ( ) == 0 ) || ( dis ( attackers [ 3 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 3 ] = queens [ i ] ; } if ( king [ 0 ] == queens [ i ] [ 0 ] && king [ 1 ] < queens [ i ] [ 1 ] ) { if ( ( attackers [ 4 ] . size ( ) == 0 ) || ( dis ( attackers [ 4 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 4 ] = queens [ i ] ; } if ( king [ 0 ] - queens [ i ] [ 0 ] == king [ 1 ] - queens [ i ] [ 1 ] && king [ 0 ] > queens [ i ] [ 0 ] ) { if ( ( attackers [ 0 ] . size ( ) == 0 ) || ( dis ( attackers [ 0 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 0 ] = queens [ i ] ; } if ( king [ 0 ] - queens [ i ] [ 0 ] == king [ 1 ] - queens [ i ] [ 1 ] && king [ 0 ] < queens [ i ] [ 0 ] ) { if ( ( attackers [ 7 ] . size ( ) == 0 ) || ( dis ( attackers [ 7 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 7 ] = queens [ i ] ; } if ( king [ 1 ] - queens [ i ] [ 1 ] == 0 && king [ 0 ] > queens [ i ] [ 0 ] ) { if ( ( attackers [ 1 ] . size ( ) == 0 ) || ( dis ( attackers [ 1 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 1 ] = queens [ i ] ; } if ( king [ 1 ] - queens [ i ] [ 1 ] == 0 && king [ 0 ] < queens [ i ] [ 0 ] ) { if ( ( attackers [ 6 ] . size ( ) == 0 ) || ( dis ( attackers [ 6 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 6 ] = queens [ i ] ; } if ( king [ 0 ] - queens [ i ] [ 0 ] == - ( king [ 1 ] - queens [ i ] [ 1 ] ) && king [ 0 ] > queens [ i ] [ 0 ] ) { if ( ( attackers [ 2 ] . size ( ) == 0 ) || ( dis ( attackers [ 2 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 2 ] = queens [ i ] ; } if ( king [ 0 ] - queens [ i ] [ 0 ] == - ( king [ 1 ] - queens [ i ] [ 1 ] ) && king [ 0 ] < queens [ i ] [ 0 ] ) { if ( ( attackers [ 5 ] . size ( ) == 0 ) || ( dis ( attackers [ 5 ] , king ) > dis ( queens [ i ] , king ) ) ) attackers [ 5 ] = queens [ i ] ; } } for ( int i = 0 ; i < 8 ; i ++ ) if ( attackers [ i ] . size ( ) ) sol . push_back ( attackers [ i ] ) ; return sol ; } void print ( vector < vector < int > > ans ) { for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) cout << ans [ i ] [ j ] << " ▁ " ; cout << " STRNEWLINE " ; } } int main ( ) { vector < int > king = { 2 , 3 } ; vector < vector < int > > queens = { { 0 , 1 } , { 1 , 0 } , { 4 , 0 } , { 0 , 4 } , { 3 , 3 } , { 2 , 4 } } ; vector < vector < int > > ans = findQueens ( queens , king ) ; print ( ans ) ; }

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