akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	q := sc.ReadInt()
	abcds := make([]ABCD, q)
	for i := 0; i < q; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		c := sc.ReadInt()
		d := sc.ReadInt()
		abcds[i] = ABCD{a, b, c, d}
	}

	maxScore := 0
	update := func(combi SeqA) {
		score := computeScore(abcds, combi)
		if score > maxScore {
			maxScore = score
		}
	}

	eachCombination(update, 1, m, n)

	fmt.Println(maxScore)
}

func eachCombination(callback func(SeqA), min, max, n int) {
	edits := make([]editSeqA, 0, 92378) // 19! / (10! * 9!) = 92378
	for a := max; a >= min; a-- {
		edits = append(edits, editSeqA{0, a})
	}

	cur := make([]int, n)
	for len(edits) > 0 {
		// pop
		edit := edits[len(edits)-1]
		edits = edits[:len(edits)-1]

		// edit
		cur[edit.pos] = edit.value

		// call
		if edit.pos == n-1 {
			callback(cur)
		} else {
			for v := max; v >= edit.value; v-- {
				edits = append(edits, editSeqA{edit.pos + 1, v})
			}
		}
	}
}

func computeScore(abcds []ABCD, seqA SeqA) int {
	totalD := 0
	for _, abcd := range abcds {
		if seqA[abcd.B-1]-seqA[abcd.A-1] == abcd.C {
			totalD += abcd.D
		}
	}
	return totalD
}

type editSeqA struct {
	pos   int
	value int
}

type SeqA []int

type ABCD struct {
	A int
	B int
	C int
	D int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1828
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

bool isKaibun(string S)
{
	rep(i, S.size())
	{
		if (S[i] != S[S.size() - 1 - i])
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int L;
	cin >> L;

	cout << setprecision(10) << (double)L / 3 * (double)L / 3 * (double)L / 3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,pos;
vector<int>pre,in,post;

void rec(int l,int r){
  if(l>=r) return;
  int root=pre[pos++];
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void slove(){
  pos=0;
  rec(0,pre.size());
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<post[i];
  }
  cout<<endl;
}
int main(){
  int k;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>k;
    pre.push_back(k);
  }
  for(int i=0;i<n;i++){
    cin>>k;
    in.push_back(k);
  }
  slove();
  return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll N;
    cin>>N;

    vector <pair<ll,ll>> XL(N);
    rep(i,0,N)cin>>XL[i].first>>XL[i].second;//??

    sort(XL.begin(),XL.end());
    ll r=-100100100100;

    ll sum=0;
    rep(i,0,N){
        if(XL[i].first-XL[i].second >= r){
            sum++;
            r = XL[i].first+XL[i].second;
        }
        else if(XL[i].first+XL[i].second <= r){
            r = XL[i].first+XL[i].second;
        }
    }

    cout<<sum;



    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int ans = 1;
  if(b==1){
    cout<<"0"<<endl;
    return 0;
  }
  while(a*ans-ans+1<b){
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
from bisect import bisect_left as bl
A, B, Q = map(int, input().split())
inf = 10 ** 11
Sh = [-1 * inf] + [int(input()) for _ in range(A)] + [inf]
Te = [-1 * inf] + [int(input()) for _ in range(B)] + [inf]
for _ in range(Q):
  x = int(input())
  b, d = bl(Sh, x), bl(Te, x)
  res = inf
  for S in [Sh[b - 1], Sh[b]]:
    for T in [Te[d - 1], Te[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)

Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int N = 2002;

int n;
long dp[N][N];
pll a[N];

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++){
    cin >> a[i].first; a[i].second = i;
  }
  sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n);
  long res = 0;
  for (int x = 0; x <= n; x++){
    for (int y = 0; y <= n; y++){
      int cur = x + y;
      if (cur == n) res = max(res, dp[x][y]);
      else {
        cur++;
        dp[x + 1][y] = max(dp[x + 1][y], dp[x][y] + abs(a[cur].second - (x + 1)) * a[cur].first);
        dp[x][y + 1] = max(dp[x][y + 1], dp[x][y] + abs(a[cur].second - (n - y)) * a[cur].first);
        if (x == 0 && y == 0){
          
        }
      } 
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 34948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust\n";
    else cout<<"win\n";
}

Measured memory_bytes: 256
A,B,K = map(int,input().split())

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)
ans = []
for i in range(1,101):
    if gcd(A,B) % i == 0:
        ans.append(i)

print(ans[-K])


Measured memory_bytes: 3060
import math
def calcAngle(h,m): 
          
        # validate the input 
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
        # Calculate the angles moved by  
        # hour and minute hands with  
        # reference to 12:00 
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
        # Find the difference between two angles 
        angle = abs(hour_angle - minute_angle) 
          
        # Return the smaller angle of two  
        # possible angles 
        angle = min(360 - angle, angle) 
          
        return angle
a,b,h,m=map(int,input().split())
angle=calcAngle(h,m)
angle*=(math.pi/180)
ans=(a**2+b**2-(2*a*b*math.cos(angle)))**0.5
print('%.20f'%ans)

Measured memory_bytes: 9452
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base:: sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long

const int N = 1005;
int MOD = 1e9 + 7;

int dp[N][N];

int32_t main(){
	fast;
	int n,m;	cin >> n >> m;
	string s[n];
	for(int i=0; i<n ; i++)	cin >> s[i];
	
	memset(dp,0,sizeof(dp));
	for(int i=1 ; i<=m ; i++){
		if(s[0][i-1]=='#')	break;
		else	dp[1][i] = 1;
	}
	
	for(int i=1 ; i<=n ; i++){
		if(s[i-1][0]=='#')	break;
		else	dp[i][1] = 1;
	}	
	
	for(int i=2; i<=n ; i++)
	{
		for(int j=2; j<=m ; j++)
		{
			if(s[i-1][j-1]=='#')	continue;
			if(s[i-2][j-1]=='.')	dp[i][j] = (dp[i][j] + dp[i-1][j])%MOD;
			if(s[i-1][j-2]=='.')	dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
		}
	}
	
	cout << dp[n][m];
	
		
}




  	

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

const long long mod = pow(10, 9) + 7;
long long cnt[26];
long long N;
string s;

int main()
{
    cin >> N >> s;
    for (int i = 0; i < N;i++)
    {
        cnt[s[i] - 'a']++;
    }
    long long ans = 1;
    for (int i = 0; i < 26;i++)
    {
        ans *= (cnt[i] + 1LL);
        ans %= mod;
    }
    ans = (ans - 1LL + mod) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

int main() {
 int N = 0;
 cin >> N;

 char S[N];
 int cnt = N;

 for (int i = 0; i < N; i++) {
	cin >> S[i];
 }

 for (int i = 0; i < N-1; i++) {
	if(S[i] == S[i+1]) {
		cnt = cnt - 1;
 	}
 }
		
 cout << cnt << endl;

}

Measured memory_bytes: 384
N = int(input())
inputs = [int(i) for i in input().split()]

flag = -1
ans = 1

for i in range(1, N):
    first = inputs[i-1]
    latter = inputs[i]
    if flag == -1:
        if first < latter:
            flag = 1
        elif first > latter:
            flag = 0
    elif flag == 1:
        if first > latter:
            flag = -1
            ans += 1
    else:
        if first < latter:
            flag = -1
            ans += 1

print(ans)


Measured memory_bytes: 14252
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int a,b,c;
   cin>>a>>b>>c;
   if(a<b&&b<c) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   //while(1);
   return 0;
 }

Measured memory_bytes: 3088
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++){
      a[i] = sc.nextInt();
      if(i != n-1) System.out.print(a[i] + " ");
      else System.out.println(a[i]);
    }
    for(int i = 1; i<n; i++){
      int v = a[i];
      int j = i - 1;
      while (j >= 0 && a[j] > v){
        a[j+1] = a[j];
        j--;
      }
      a[j+1] = v;
      for(int k = 0; k<n; k++){
        if(k != n-1) System.out.print(a[k] + " ");
        else System.out.println(a[k]);
      }
    }
  }
}

Measured memory_bytes: 33676
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void) {

	set<string> s;

	string str;
	cin >> str;
	int K, N;
	cin >> K;
	N = str.size();

	for (int i = 0; i < N; i++) {
		for (int j = i; j < min(N, i + 5); j++) {
			cerr << str.substr(i, j - i + 1) << endl;
			s.insert((str.substr(i, j - i + 1)));
		}
	}

	auto itr = s.begin();
	for (int j = 0; j < K - 1; j++)itr++;
	cout << *itr << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        vector<P> box(n);
        box[0] = P(0, 0);
        for(int i = 0; i < n-1; ++i) {
            int no, d; cin >> no >> d;
            int stx = box[no].first, sty = box[no].second;
            if(d == 0) stx--;
            else if(d == 1) sty--;
            else if(d == 2) stx++;
            else sty++;
            box[i+1] = P(stx, sty);
        }
        int l = 1e9, r = -1e9, u = -1e9, d = 1e9;
        for(int i = 0; i < n; ++i) {
            chmax(r, box[i].first);
            chmin(l, box[i].first);
            chmax(u, box[i].second);
            chmin(d, box[i].second);
        }
        int yoko = r-l;
        int tate = u-d;
        cout << yoko+1 << " " << tate+1 << endl;
    }
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i,m) {
        int k;
        cin >> k;
        rep(j,k) {
            int a;
            cin >> a;
            a--;
            s[i].push_back(a);
        }
    }
    vector<int> p(m);
    rep(i,m) cin >> p[i];
    int ans = 0;
    rep(i,1<<n) {
        bool ok = true;
        rep(j,m) {
            int on = 0;
            for (int u : s[j]) {
                if (i>>u&1) on++;
            }
            if (on%2 != p[j]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3480
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	if (N >= 2 && M >= 2) {
		cout << (N - 2) * (M - 2) << endl;
	}
	else if(N == 1 && M == 1) {
		cout << 1 << endl;
	}
	else if (N == 1) {
		cout << M - 2 << endl;
	}
	else if (M == 1) {
		cout << N - 2 << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N), S(N);
  for(int i=0;i<N;i++) std::cin >> A[i];
  sort(A.begin(), A.end());
  for(int i=0;i<N;i++) S[i] = (i==0?A[0]:S[i-1]+A[i]);
  ll las = 0;
  for(int i=1;i<N;i++) if(A[i]>2*S[i-1]) las = i;
  std::cout << N - las << '\n';
  return 0;
}


Measured memory_bytes: 2296
local mfl, mce, mmi = math.floor, math.ceil, math.min
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = false
    end
  end
end
SegTree.create = function(self, n)
  local stagenum, mul = 1, 1
  self.cnt, self.stage = {1}, {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = false end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage = 1
  local stagenum = self.stagenum
  while right - left + 1 < bls(1, stagenum - start_stage) do
    start_stage = start_stage + 1
  end
  local ret = false
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)
    local sz = bls(1, stagenum - stage)
    if (l - 1) % sz ~= 0 then
      local newr = mmi(r, bls(brs(l - 2 + sz, stagenum - stage), stagenum - stage))
      -- local newr = mmi(r, mce((l - 1) / sz) * sz)
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, newr)
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = ret or self.stage[stage][brs(l + sz - 1, stagenum - stage)]-- mce(l / sz)]
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
    if ret then break end
  end
  return ret
end
SegTree.setValue = function(self, idx, value)
  self.stage[self.stagenum][idx] = value
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.stage[i + 1][idx] or self.stage[i + 1][rem]
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n = io.read("*n", "*l")
local s = io.read()
local q = io.read("*n", "*l")
local sts = {}
local t = {}
for i = 1, 26 do
  sts[i] = SegTree.new(n, function(a, b) return a or b end, false)
end
for i = 1, n do
  t[i] = s:sub(i, i):byte() - 96
  sts[t[i]]:setValue(i, true)
end

for iq = 1, q do
  local iqstr = io.read()
  local ic = iqstr:sub(1, 1)
  if ic == "1" then
    local i, cs = iqstr:match("%d (%d+) (%w)")
    i = tonumber(i)
    local c = cs:byte() - 96
    if t[i] ~= c then
      sts[t[i]]:setValue(i, false)
      t[i] = c
      sts[c]:setValue(i, true)
    end
  else
    local l, r = iqstr:match("%d (%d+) (%d+)")
    l, r = tonumber(l), tonumber(r)
    local cnt = 0
    for i = 1, 26 do
      if sts[i]:getRange(l, r) then cnt = cnt + 1 end
    end
    print(cnt)
  end
end


Measured memory_bytes: 317424
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k;
    cin >> n >> k;
    int c = (n - 1) * (n - 2) / 2;
    if (k > c)
    {
        cout << -1 << endl;
        return 0;
    }
    int m = n - 1;
    int r = c - k;
    m += r;
    cout << m << endl;
    rep(i, 2, n + 1)
    {
        cout << 1 << ' ' << i << endl;
    }
    rep(i, 2, n)
    {
        rep(j, i + 1, n + 1)
        {
            if (r == 0)
            {
                break;
            }
            r--;
            cout << i << ' ' << j << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;
vi ans;
void cacl(int n, int d) {
    fori(i,1,d-1) {
        fori(j,1,d-1) {
            if(i + j > d - 1) break;
            int k = d - i - j;
            int x = i * i + i * j + i * k +j * j + j * k +k * k;
            if(x <= n) ans[x]++;
        }
    }
}
void solve() {
    int n;
    cin >> n;
    ans = vector<int>(n + 1,0);
    for(int i =3; i <= n; ++i) {
        if(i * i > 2 * n) break;
        cacl(n,i);
    }   
    fori(i,1,n+1) cout << ans[i] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
//	freopen("D:\\data_in.txt", "r", stdin);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		try {

			int max_x = sc.nextInt();
			int max_y = sc.nextInt();
			int n = sc.nextInt();

			int min_x = 0;
			int min_y = 0;

			for (int i = 0; i < n; i++) {

				int x = sc.nextInt();
				int y = sc.nextInt();
				int a = sc.nextInt();

				if (a == 1) {
					if (min_x < x) {
						min_x = x;
					}
				}
				else if (a == 2) {
					if (x < max_x) {
						max_x = x;
					}
				}
				else if (a == 3) {
					if (min_y < y) {
						min_y = y;
					}
				}
				else if (a == 4) {
					if (y < max_y) {
						max_y = y;
					}
				}
			}

			if (max_x <= min_x || max_y <= min_y) {
				System.out.println(0);
			}
			else {
				System.out.println((max_x - min_x) * (max_y - min_y));
			}
		}
		finally {
			sc.close();
		}
	}

}


Measured memory_bytes: 10452
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

/*void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<111111;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

int COM(int n,int k){
	if(n<k)return 0;
	if(n<0||k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}*/

//}

int n,ans,cnt;
unordered_map<int,int> a;

main(){
    cin>>n;
    rep(i,n){
        int tmp;
        cin>>tmp;
        amp(a,tmp);
    }
    ans=a.size();
    for(auto x:a){
        cnt+=(!((x.se)&1));
    }
    cout<<ans-(cnt&1)<<endl;
}


Measured memory_bytes: 4388
<?php
list($n) = ints();
$t = ints();
$sum = array_sum($t);
list($m) = ints();
for ($i = 0; $i < $m; ++$i) {
    list($p, $x) = ints();
    --$p;
    $ans[] = $sum - $t[$p] + $x;
}
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4728
#include <iostream>
#include <string>
using namespace std;

#define rep(a, b, i) for(int i = a; i < b; i++)

char ch(int a, int b, int c) {
	return (a * (c - 'a') + b) % 26 + 'a';
}

int main() {
	int n, a, b, c;
	cin >> n;
	cin.ignore();

	string str, res = "";
	for (; n > 0; n--) {
		getline(cin, str);

		rep(1, 28, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 28, b) {
				res = str;
				c = 0;
				rep(0, str.size(), c) {
					if (res[c] == ' ') continue;

					res[c] = ch(a, b, res[c]);
				}
				if (res.find("this") != -1 || res.find("that") != -1) {
					cout << res << endl;
					a = 114514;
					b = 114514;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>

void sort(int*,int*,int*);
void swap(int*,int*);
void print(int,int,int);

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
   // cout<<&a<<endl;
    sort(&a,&b,&c);
    print(a,b,c);
    return 0;
}

void sort(int* a,int* b,int* c){
    //cout<<*a<<endl;
    if(*a>*b){
        swap(*a,*b);
    }
    if(*b>*c){
        swap(*b,*c);
    }
    if(*a>*b){
        swap(*a,*b);
    }
}

void swap(int x,int y){
    int tmp=x;
    x=y;
    y=tmp;
}

void print(int a,int b,int c){
    cout<<a<<" "<<b<<" "<<c<<endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int num = n;
    while(num){
        sum += num % 10;
        num = num / 10;
    }
    if(n % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> w;

  string s0;
  cin >> s0;
  w.pb(s0);
  char prev = s0[sz(s0)-1];

  rep(i, n-1){
    string s;
    cin >> s;
    if(find(all(w), s) == w.end()){
      if(s[0] != prev){
        cout << "No" << endl;
        return 0;
      }
    }else{
      cout << "No" << endl;
      return 0;
    }
    w.pb(s);
    prev = s[sz(s)-1];
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

  int handled;

  if (N % 1000 != 0){
    handled = N % 1000;
  }else{
    handled = 1000;
  }
  

  cout << 1000 - handled << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<algorithm>
#define Nil -1
#define Lens 1000000

using namespace std;

struct Node
{
	int p, l, r;
};
int N;
Node Tr[Lens];
int D[Lens];
int v, d;

void maketree()
{
	int tmp;
	for (int i = 0; i < N; i++)
	{
		cin >> v >> d;
		int tmpv = v;
		int next;
		for (int i = 0; i < d; i++)
		{
			cin >> tmp;
			
			if (i == 0)
			{
				Tr[v].l = tmp;
				Tr[tmp].p = v;
				next = tmp;
			}
			else
			{
				
				Tr[next].r = tmp;
				Tr[tmp].p = tmpv;
				next = tmp;
			}
		}
	}
}

void dns(int i, int p)
{
	D[i] = p;
	if (Tr[i].r != Nil) dns(Tr[i].r, p);
	if (Tr[i].l != Nil) dns(Tr[i].l, p + 1);
	
	
}

void printtree()
{
	int tmp = -1;
	int r;
	for (int i = 0; i < N; i++)
	{
		if (Tr[i].p == Nil)
			r = i;
	}
	dns(r, 0);
	for (int i = 0; i < N; i++)
	{
		cout << "node " << i << ": parent = " << Tr[i].p << ", " << "depth = " << D[i] << ", ";
		if (Tr[i].p == Nil)
		{
			cout << "root, [";
			if (Tr[i].l != Nil)
			{
				int next = Tr[i].l;
				cout << Tr[i].l;
				while (Tr[next].r != Nil)
				{
					cout << ", " << Tr[next].r;
					next = Tr[next].r;
				}
			}
			cout << "]";
		}
		else if (Tr[i].p != Nil&&Tr[i].l != Nil)
		{
			cout << "internal node, [";
			cout << Tr[i].l;
			int next = Tr[i].l;
			while (Tr[next].r != Nil)
			{
				cout << ", " << Tr[next].r;
				next = Tr[next].r;
			}
			cout << "]";
		}
		else
		{
			cout << "leaf, []";
		}


		cout << endl;
	}
}



int main()
{

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		Tr[i].l = Tr[i].r = Tr[i].p = Nil;
	}

	maketree();


	printtree();
	return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
    using namespace std;
    
    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;
     
    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;                            
     
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()            
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) power(x, mod-2)
    #define ncr(n,r) ( n >= r ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-r]))%mod) : (ll)0)
    #define MAX 100005
     
    ll power(ll x, ll y) { 
        ll ans=1;
        x=x%mod;
        while(y>0) { 
            if (y&1) 
                ans=(ans*x)%mod; 
            y=y>>1;
            x=(x*x)%mod; 
        } 
        return ans; 
    }
    
    // vector<ll> adj[MAX];
    // ll visit[MAX];
    // void dfs(ll node){
    //     visit[node]=1;
    //     for(auto i : adj[node]){
    //         if(!visit[i]) dfs(i);
    //     }
    // }
    
    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }
    ll sum,dp[2005];
    ll solve(ll s){
        if(dp[s]!=-1)   return dp[s];
        if(s<3) return 0;
        ll tmp=0;
        for(ll i=3; ;i++){
            if(i==s)    tmp=((tmp+1)%mod);
            else if(i>s)    break;
            else tmp=((tmp+solve(s-i))%mod);
        }
        dp[s]=tmp%mod;
        return dp[s];
    } 
    
    int main()
    {
        boost;
        cin>>sum;
        memset(dp,-1,sizeof(dp));
        cout<<solve(sum);
        return 0;
    }
    

Measured memory_bytes: 3656
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
	int N, M;
	cin >> N;

	int total = 0;
	vector<int> T(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
		total += T[i];
	}

	cin >> M;
	for (int i = 0; i < M; ++i) {
		int P, X;
		cin >> P >> X;
		cout << (total + X - T[P-1]) << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
import sys
import numpy

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, M, X = map(int, readline().split())
    cost = []; A = []
    for _ in range(N):
        c, *Atmp = map(int, readline().split())
        cost.append(c); A.append(Atmp)
    cost = numpy.array(cost)
    A = numpy.array(A)

    pay = []
    for i in range(2**N):
        jtmp = []
        costtmp = 0
        for j in range(N):
            if (i>>j)&1:
                jtmp.append(j)
        costtmp = cost[jtmp].sum()
        brain = A[jtmp,:].sum(axis=0)
        if all(brain >= X):
            pay.append(costtmp)

    if len(pay) == 0:
        ans = -1
    else:
        ans = min(pay)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27396
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;
  ll i;
  vector<ll> A(N+1);
  vector<ll> B(N);
  for(i=0;i<N+1;i++){
    cin >> A[i];
  }
  for(i=0;i<N;i++){
    cin >> B[i];
  }
  ll x;
  ll sum=0;
  for(i=0;i<N;i++){
    if(A[i]>=B[i]){
      sum+=B[i];
    }else{
      sum+=A[i];
      x = B[i] - A[i];
      if(A[i+1]>=x){
        A[i+1]-=x;
        sum += x;
      }else{
        sum += A[i+1];
        A[i+1] = 0;
      }
    }
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int dp[k + 1];
    for (int i = 0; i <= k; i++) dp[i] = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i < a[j]) break;
            if (dp[i - a[j]] == 0) 
            {
                dp[i] = 1;
                break;
            }
        }
    }
    if (dp[k] == 1) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 3992
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
suma = sum(a)%mod
result = 0
for i in range(n-1):
    temp = a[i]
    suma -= (a[i]%mod)
    result += (suma * (a[i])%mod)%mod
print(result % mod)

Measured memory_bytes: 94116
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;

using ll = long long;

int N, K;
string s;
int num[1000000] = {0};
int sum[1000000] = { 0 };
int ans = 0;
int limit;

int main() {
	cin >> N >> K;
	cin >> s;
	int j = 0;
	if (s[0] == '0') {
		num[0] = 0;
		j++;
		num[j]++;
	}
	else {
		num[0]++;
	}
	for (int i = 1; i < N; i++) {
		if (s[i] != s[i - 1]) {
			j++;
		}
		num[j]++;
	}
	sum[0] = num[0];
	for (int i = 1; i < N; i++) {
		sum[i] = sum[i - 1] + num[i];
		if (num[i] == 0)limit = i;
	}
	ans = sum[2 * K];
	for (int i = 1; i < N+2; i += 2) {
		ans = max(ans, sum[2 * K + i + 1] - sum[i]);
	}
	if (2 * K > limit - 1)ans = N;
	cout << ans;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7,N=2e5+5;
int fac[N],inv[N];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
void init(int n){
	fac[0]=1;
	for(int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)
		inv[i]=inv[i+1]*(i+1)%mod;
}
void add(int &x,int y){
	x=(x+y)%mod;
}
int C(int n,int m){
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	int n,A,B,c,inv100=ksm(100,mod-2);
	cin>>n>>A>>B>>c;
	A=A*inv100%mod;
	B=B*inv100%mod;
	c=c*inv100%mod;
	init(n+n);
	int ans=0,sum=(A+B)%mod;
	sum=ksm(sum,mod-2);
	A=A*sum%mod; B=B*sum%mod;
	for(int i=0;i<n;++i){
		int tmp=(i+n)*ksm(1+mod-c,mod-2)%mod;
		add(ans,C(n+i-1,i)*ksm(A,n)%mod*ksm(B,i)%mod*tmp%mod);	
		//cout<<ans<<endl;	
	}
	swap(A,B);
	for(int i=0;i<n;++i){
		int tmp=(i+n)*ksm(1+mod-c,mod-2)%mod;
		add(ans,C(n+i-1,i)*ksm(A,n)%mod*ksm(B,i)%mod*tmp%mod);		
	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6664
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int n, k, a[200200], b[200200];

int main(){
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++)scanf("%d", &a[i]);
    while(k--){
        bool flg = true;
        for(int j=0; j<=n; j++)b[j] = 0;
        for(int i=0; i<n; i++){
            b[max(0, i-a[i])]++;
            b[min(n, i+a[i]+1)]--;
        }
        for(int i=0; i<n; i++){
            if(i)b[i]+=b[i-1];
            flg &= (a[i]=b[i]) == n;
        }
        if(flg)break;
    }
    for(int i=0; i<n; i++){
        if(i)putchar(32);
        printf("%d", a[i]);
    }putchar(10);
   return 0;
}

Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> v;
	long long ans = 0;
	for(int i = 0; i < n; ++i){
		int a; cin >> a;
		v.push_back(a);
		ans += a;
	}
	if(ans % 10){
		cout << ans << endl;
	}else{
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		while(!v.empty()){
			if(v[v.size() - 1] % 10){
				cout << ans - v[v.size() - 1] << endl;
				break;
			}else{
				v.pop_back();
			}
		}
		if(v.empty()){
			cout << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long h[200001],value[200001],bt[200001];
long long t,n;
long long lowbit(long long x)
{
        return x&-x;
}
void maxupdate(long long index,long long max_value)
{
        while(index<=n)
        {  
                value[index]=max(value[index],max_value);
                index+=lowbit(index);
        }
}
long long maxrange(long long index)
{
        long long ret=0;
        while(index)
        {
                ret=max(ret,value[index]);
                index-=lowbit(index);
        }
        return ret;
}
int main()
{
        long long i,j,k,ans=0;
        scanf("%lld",&n);
        for(i=1;i<=n;i++)
        {
                scanf("%lld",&h[i]);
        }
        for(i=1;i<=n;i++)
        {
                scanf("%lld",&bt[i]);
        }
        for(i=1;i<=n;i++)
        {
                t=maxrange(h[i]-1);
                maxupdate(h[i],t+bt[i]);
                ans=max(ans,t+bt[i]);
        }
        printf("%lld",ans);
        return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cmath>

int main(void) {
  int N;
  //int a[10000] = {0};

  std::cin >> N;

  //for (size_t i = 0; i < N; i++) {
  //  std::cin >> a[i];
  //}

  size_t count = 0;
  for (size_t i = 0; i < N; i++) {
    //auto t = a[i];
    int t;
    std::cin >> t;
    while (1) {
      //if ((t & ((~0x0) - 1))) {
      if (t & 0x1) {
        break;
      }
      ++count;
      t = t / 2;
    }
  }

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main()
{
    int A, B;
    int ans = 0;
    cin >> A >> B;
    for (int i = A; i <= B; i++)
    {
        if (i % 10001 % 1010 % 100 == 0 && i % 10001 % 1010 / 100 < 10)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

long long N;
const int md = 1e9 + 7;
const int a[] = {0, 0, 1};
const int b[] = {1, 0, 1};

int f[64][3];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> N;
	f[63][0] = 1;
	for (int i = 62; i >= 0; --i) {
		int x = (N >> i & 1);
		for (int j = 0; j <= 2; ++j) {
			if (!f[i+1][j]) continue;
			for (int k = 0; k < 3; ++k) {
				int nj = j * 2 + x - (a[k] + b[k]);
				if (nj < 0) continue;
				nj = min(nj, 2);
				f[i][nj] = (f[i][nj] + f[i+1][j]) % md;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= 2; ++i) ans = (ans + f[0][i]) % md;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

struct State{
	int cake[16];
	int a, b;
	State(int a, int b){
		memset(this, 0, sizeof(*this));
		this->a = a;
		this->b = b;
	}
	int search(){
		if (a == 0 && b == 0){
			return 1;
		}
		if (a + b > 16){
			return 0;
		}
		if (a > 0){
			for (int i=0; i<16; ++i){
				if (takeok(i, 1)){
					cake[i] = 1;
					--a;
					if (search()){
						return 1;
					}
					++a;
				}
			}
		}
		else{
			for (int i = 0; i<16; ++i){
				if (takeok(i, 2)){
					cake[i] = 2;
					--b;
					if (search()){
						return 1;
					}
					++b;
				}
			}
		}
		return 0;
	}

	int takeok(int i, int p){
		return cake[i] == 0 && cake[i + 1] != p && cake[(i + 15)%16] != p;
	}

};



int main(){
	int a, b;
	fscanf(stdin, "%d %d", &a, &b);

	State s(a, b);
	if (s.search()){
		printf("Yay!\n");
	}
	else{
		printf(":(\n");
	}
	return 0;
}


Measured memory_bytes: 128
/* -> Written by <-
   -----------
  |K_A_Z_A_M_A|
  |___________|
  |    _    |
  |   (^_^)   |
  |  /( | )\  |
  |____|_|____|
    H O A N G
*/

#define Task ""
#define F first
#define S second
#define push_back pb
#define bit(x, i) (x >> i) & 1
#define inf 1e9 + 7
#define INF 1e18 + 7

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;
const int maxn = 2e5 + 5;

int n, a[maxn];
ll s[maxn];

void Solve()
{
    cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i], s[i] = s[i-1] + a[i];
    ll res = 0;
    for (int i = 1; i < n; i ++)
    {
        ll ans = (((s[n] - s[i]) % MOD) * a[i]) % MOD;
        res = (res + ans) % MOD;
    }
    cout << res;

}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    if(fopen(Task".inp", "r"))
    {
        freopen(Task".inp","r",stdin);
        freopen(Task".out","w",stdout);
    }
    int test_case = 1;
//    cin >> test_case;
    while (test_case --)
        Solve();
    return 0;
}


Measured memory_bytes: 5948
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Numerics;

namespace ABC164.A
{
	public class Solver
	{
		public void Run() {
        	var str = Console.ReadLine();
            var ary = str.Split();
            var S = int.Parse(ary[0]);
            var W = int.Parse(ary[1]);
            
            if (S <= W){
            	Console.WriteLine("unsafe");
            }else{
                Console.WriteLine("safe");
            }
		}

		static void Main(string[] args) {
			new Solver().Run();
		}
	}
}

Measured memory_bytes: 27484
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

vi build_list(){
    vi res(100000);
    rep(i, res.size()) res[i] = i;
    res[0] = res[1] = 0;
    for (int i = 2; i < res.size(); i++){
        if (res[i] == 0) continue;
        for (int j = i + i; j < res.size(); j += i){
            res[j] = 0;
        }
    }
    res.erase(remove(res.begin(), res.end(), 0), res.end());
    return res;
}

int main(){
    vi ps = build_list();
    int m, a, b;
    while (cin >> m >> a >> b && m | a | b){
        int r1 = 0, r2 = 1;
        for (int i = 0; i < ps.size(); i++){
            for (int j = 0; j <= i; j++){
                int p = ps[j];
                int q = ps[i];
                if (p*q > m) break;
                if (1. * a / b <= 1. * p / q){
                    if (r1 * r2 < p * q){
                        r1 = p;
                        r2 = q;
                    }
                }
            }
        }
        cout << r1 << " " << r2 << endl;
    }
}

Measured memory_bytes: 1528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int d = Math.max(a, b);
		int e = Math.max(d, c);

		System.out.println(a+b+c-e);

	}

}


Measured memory_bytes: 20948
import java.util.*;
 
class Main {
	  static long mod=1_000_000_007;
  public static void main(String[] args) {
	  int flg = 0;
	  String ans = "";
	  Scanner sc = new Scanner(System.in);
      long sx = sc.nextLong();
      long sy = sc.nextLong();
      long tx = sc.nextLong();
      long ty = sc.nextLong();
      
      long x = tx-sx;
      long y = ty-sy;
      for(int i =0;i<x;i++) {
          System.out.print("R");    	  
      }
      for(int i =0;i<y;i++) {
          System.out.print("U");    	  
      }      
      for(int i =0;i<x;i++) {
          System.out.print("L");    	  
      }
      for(int i =0;i<y;i++) {
          System.out.print("D");    	  
      }
      System.out.print("D");
      for(int i =0;i<x;i++) {
          System.out.print("R");    	  
      }
      System.out.print("RU");
      for(int i =0;i<y;i++) {
          System.out.print("U");    	  
      }      
      System.out.print("LU");
      for(int i =0;i<x;i++) {
          System.out.print("L");    	  
      }
      System.out.print("LD");
      for(int i =0;i<y;i++) {
          System.out.print("D");    	  
      }
      System.out.print("R");
  }
}

Measured memory_bytes: 25280
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	vector<bool> isprime(200000, true);
	isprime[0] = isprime[1] = false;
	vector<int> prime;
	for (long long i = 2; i < 200000; ++i) {
		if (isprime[i]) {
			prime.push_back(i);
			for (long long j = i * i; j < 200000; j += i) isprime[j] = false;
		}
	}
	int n, p;
	while (cin >> n >> p, n >= 0) {
		auto it = upper_bound(prime.begin(), prime.end(), n);
		vector<int> tmp, ans;
		for (int i = 0; i < 100; ++i) tmp.push_back(*it++);
		for (int i = 0; i < 100; ++i)
			for (int j = i; j < 100; ++j)
				ans.push_back(tmp[i] + tmp[j]);
		sort(ans.begin(), ans.end());
		cout << ans[p - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 3264