akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n) {


	string  str = to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size() / 2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if (str[i] != str[str.size() - i - 1]) {
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m, k, sum = 0;
	c_p_c();
	ll a,b,c;
	cin>>a>>b>>c;



	if(a-c<0)
	{
		ll d = a-c;
		b=b+d;
		if(b<0)
			b=0;
		cout<<0<<" "<<b<<endl;
	}else{
		cout<<a-c<<" "<<b<<endl;
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[N][3];
int f[N][3];

int main() {
	int n;
	scanf("%d",&n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			scanf("%d",&a[i][j]);
		}
	}
	memset(f, 0, sizeof f);
	f[0][0] = a[0][0], f[0][1] = a[0][1], f[0][2] = a[0][2];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			int temp = -1;
			for (int k = 0; k < 3; k++) {
				if (k == j) continue;
				temp = max(temp, f[i-1][k]);
			}
			f[i][j] = temp + a[i][j];
		}
	}
	int ans = -1;
	for (int i = 0; i < 3; i++) ans = max(ans, f[n-1][i]);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560
import sys

read = sys.stdin.read
n, *a = map(int, read().split())
a.sort()
x = 2*sum(a[(n+1)//2:]) - 2*sum(a[:(n+1)//2])
y = 2*sum(a[n//2:]) - 2*sum(a[:n//2])
if n % 2 == 1:
    x += a[n//2-1] + a[n//2]
    y -= a[n//2] + a[n//2+1]
else:
    x -= a[n//2] - a[n//2-1]
    y -= a[n//2] - a[n//2-1]
    y 
print(max(x, y))


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

#define ll long long 
queue<ll>q;

int main()
{
    int k;
    cin >> k;
    for (int i = 1; i <= 9; i++)
        q.push(i);

    int j = 1;

    while (j < k)
    {
        ll p = q.front();
        q.pop();
        j++;

        ll u = p % 10;

        if (u != 0)
            q.push(p * 10 + u - 1);

        q.push(p * 10 + u);

        if (u != 9)
            q.push(p * 10 + u + 1);
    }
    cout << q.front() << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<long long>> d(N, vector<long long>(N, 0LL));
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin >> d[i][j];

    vector<vector<long long>> d2(N, vector<long long>(N, 1LL << 60));
    for(int i=0; i<N; i++)
        d2[i][i] = 0;

    long long ans = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(i == j) continue;
            long long tmp = 1LL << 60;
            for(int k=0; k<N; k++){
                if(k == i || k == j) continue;
                tmp = min(tmp, d[i][k] + d[k][j]);
            }
            if(tmp > d[i][j]){
                d2[i][j] = d[i][j];
                ans += d[i][j];
            }
        }
    }

    for(int k=0; k<N; k++)
        for(int i=0; i<N; i++)
            for(int j=0; j<N; j++)
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);

    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            if(d2[i][j] > 1LL << 40)
                d2[i][j] = 0;

    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            if(d[i][j] != d2[i][j]){
                cout << -1 << endl;
                return 0;
            }
    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 1664
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        String S = sc.next();
        String T = sc.next();

        if (S.length() + 1 == T.length() && T.substring(0, S.length()).equals(S)) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int ans = 0;
  
  for (int i = 0; i <= A; i++){
    for (int j = 0; j <= B; j++){
      for (int k = 0; k <= C; k++){
        if (i*500 + j*100 + k*50 == X){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
local n=io.read("n")
local result=n
for i=0,n do
    local counter=0
    local draw=i
    while draw>0 do
        counter=counter+draw%6
        draw=math.floor(draw/6)
    end
    local draw=n-i
    while draw>0 do
        counter=counter+draw%9
        draw=math.floor(draw/9)
    end
    if result>counter then
        result=counter
    end
end
print(result)

Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (u == s)
    {
        cout << a - 1 << " " << b << endl;
    }
    else if (u == t)
    {
        cout << a << " " << b - 1 << endl;
    }
}


Measured memory_bytes: 256
n=gets.to_i
c=Array.new(5){0}
a=gets.split.map(&:to_i)

a.each do |e|
  if e%4==0
    c[4]+=1
  elsif e%2==0
    c[2]+=1
  else
    c[1]+=1
  end
end

if c[2]==0
  if n/2<=c[4]
    puts 'Yes'
  else
    puts 'No'
  end
else
  if c[2]==n
    puts 'Yes'
  elsif c[4]==0
    puts 'No'
  else
    if (n-c[2]-1)/2<=c[4]-1
      puts 'Yes'
    else
      puts 'No'
    end
  end
end


Measured memory_bytes: 8460
#include <stdio.h>
#define INF 10000000
#define MIN(a,b) ((a>b)?(b):(a))
#define MAX(a,b) ((a>b)?(a):(b))

int main(void){
	int N,W;
	int v[1001],w[1001];
	int dp[10001];
	int i,j,k;

	scanf("%d%d",&N,&W);
	for(i=1;i<=N;i++) scanf("%d%d",v+i,w+i);


	for(i=0;i<=W;i++) dp[i]=0;
	dp[0]=0;

	for(i=1;i<=N;i++){
		for(j=W;j>=0;j--){
			if(j-w[i]>=0) dp[j]=MAX(dp[j],dp[j-w[i]]+v[i]);
		}
	}

	printf("%d\n",dp[W]);
	return 0;
}

Measured memory_bytes: 1072
package main

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

var H, W int

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1000000000)
	fmt.Scan(&H, &W)

	q := make([][]int, 0)
	m := make([][]bool, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]bool, W) // Falseで初期化されている

		for j, v := range line {
			if string(v) == "#" {
				q = append(q, []int{i, j})
				m[i][j] = true
			}
		}
	}
	fmt.Println(bfs(q, m))
}

func bfs(q [][]int, m [][]bool) int {
	var ans int

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			var y, x int = q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == false {
				m[y+1][x] = true
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == false {
				m[y-1][x] = true
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == false {
				m[y][x+1] = true
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == false {
				m[y][x-1] = true
				q = append(q, []int{y, x - 1})
			}
		}
	}
	return ans - 1
}


Measured memory_bytes: 186752
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int MOD=1000000007;
const int N=200005;

int n,f[N],s[N],stack[N],lef[N],rig[N];
struct data{int x,v;}a[N];
struct Interval{int l,r;}itv[N];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

bool cmp(data a,data b)
{
	return a.v<b.v;
}

bool cmp1(Interval a,Interval b)
{
	return a.r<b.r||a.r==b.r&&a.l<b.l;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i].x=read(),a[i].v=read();
	sort(a+1,a+n+1,cmp);
	int top=0;
	for (int i=1;i<=n;i++)
	{
		if (!top||a[i].x>a[stack[top]].x) stack[++top]=i;
		int l=1,r=top;
		while (l<=r)
		{
			int mid=(l+r)/2;
			if (a[stack[mid]].x>=a[i].x) r=mid-1;
			else l=mid+1;
		}
		lef[i]=stack[r+1];
	}
	top=0;
	for (int i=n;i>=1;i--)
	{
		if (!top||a[i].x<a[stack[top]].x) stack[++top]=i;
		int l=1,r=top;
		while (l<=r)
		{
			int mid=(l+r)/2;
			if (a[stack[mid]].x<=a[i].x) r=mid-1;
			else l=mid+1;
		}
		rig[i]=stack[r+1];
	}
	for (int i=1;i<=n;i++) itv[i].l=lef[i],itv[i].r=rig[i];
	sort(itv+1,itv+n+1,cmp1);
	int now=1,ans=0;
	for (int i=1;i<=n;i++)
	{
		while (itv[now].r<itv[i].l-1) now++;
		f[i]=(s[i-1]+MOD-s[now-1])%MOD;
		if (itv[i].l==1) f[i]++;
		if (itv[i].r==n) (ans+=f[i])%=MOD;
		s[i]=(s[i-1]+f[i])%MOD;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7296
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

ll modpow(ll a, ll b){
    ll r = 1;
    while(b){
        r = r*((b%2)?a:1)%mod;
        a = a*a%mod;
        b>>=1;
    }
    return r;
}

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    string l;cin>>l;
    ll s = l.size();
    vector<vector<ll>> dp(s+1,vector<ll>(2));
    dp[0][0] = 1;
    rep(i,0,s){
        dp[i+1][1] = dp[i][1]*3%mod;
        if (l[i]=='0'){
            dp[i+1][0] = (dp[i+1][0]+dp[i][0])%mod;
        }else{
            dp[i+1][1] = (dp[i+1][1]+dp[i][0])%mod;
            dp[i+1][0] = (dp[i+1][0]+dp[i][0]*2)%mod;
        }
    }
    cout<<(dp[s][0]+dp[s][1])%mod<<endl;;
}

Measured memory_bytes: 8692
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  vector<ll> B(N-1); REP(i, N-1) B[i] = A[i+1]-A[i];

  int ans = 1;
  for (int i = 0; i < N-1; ++i) {
    if (B[i] == 0) continue;
    else if (B[i] > 0) {
      while (i < N-1 && B[i] >= 0) i++;
      if (i == N-1) break;
      ans++;
    } else {
      while (i < N-1 && B[i] <= 0) i++;
      if (i == N-1) break;
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
data = input().split(' ')
W = int(data[0])
H = int(data[1])
x = int(data[2])
y = int(data[3])
r = int(data[4])

lx = x - r
rx = x + r

ty = y + r
by = y + r

if (lx >= 0 and rx <= W) and (by >= 0 and ty <= H):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5596
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N = int(input())
Px = []
Py = []
for k, s in enumerate(sys.stdin.readlines()):
    x, y = map(int, s.split())
    Px.append((x, k))
    Py.append((y, k))

edge = []

Px.sort()
Py.sort()
for i in range(N - 1):
    x0, k0 = Px[i]
    x1, k1 = Px[i + 1]
    d = abs(x0 - x1)
    edge.append((d, k0, k1))

    y0, k0 = Py[i]
    y1, k1 = Py[i + 1]
    d = abs(y0 - y1)
    edge.append((d, k0, k1))

edge.sort()
uf = UnionFind(N)
cnt = 0
for d, k0, k1 in edge:
    if uf.find(k0) != uf.find(k1):
        uf.union(k0, k1)
        cnt += d

print(cnt)


Measured memory_bytes: 50788
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> A(N);
  for (auto& ai: A) scanf("%d", &ai);

  int res = 0;
  for (size_t i = 0; i < N; ++i)
    for (size_t j = 0; j < N; ++j)
      res = std::max(res, std::abs(A[i]-A[j]));

  printf("%d\n", res);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

const int INF = 1000000005;
int N, p[100005], dp[100005];
/*
void dfs(int prevPos, int currentPos, int step){
  if(dp[currentPos] <= step) return;
  dp[currentPos] = step;
  if(currentPos == N-1) return;
  if(p[currentPos] > 0) dfs(currentPos, min(N - 1, currentPos + p[currentPos]), step);
  else if(p[currentPos] < 0) dfs(currentPos, max(0, currentPos + p[currentPos]), step);
  else{
    REP(i,1,7){
      dfs(currentPos, min(N-1, currentPos+i), step+1);
    }
  }
  return;
}
*/
int main() {
  cin>>N;
  REP(i,0,N) cin>>p[i];
  REP(i,0,N) dp[i] = INF;
  dp[0] = 0;

  //dfs(-1,0,0);

  /*bfs*/
  queue< pair<int,int> > q;
  q.push(make_pair(0,0));
  while(!q.empty()){
    //if(dp[N-1] < INF) break;

    int currentPos = q.front().first;
    int currentStep = q.front().second;
    q.pop();

    REP(i,1,7){
        int nextPos = currentPos + i;
        if(p[nextPos] != 0){
          int tPos = nextPos;
          bool flag = true;
          while(p[tPos] != 0){
            if(dp[tPos] > currentStep+1){
              dp[tPos] = currentStep+1;
            }else{
              flag = false;
              break;
            }
            tPos += p[tPos];
          }
          if(flag && dp[tPos] > currentStep+1) dp[tPos] = currentStep+1,q.push(make_pair(tPos, currentStep+1));
        }else{
          if(dp[nextPos] > currentStep+1) dp[nextPos] = currentStep+1, q.push(make_pair(nextPos, currentStep+1));
        }
    }
    if(dp[N-1] < INF) break;
  }

  cout<<dp[N-1]<<endl;

  return 0;
}

Measured memory_bytes: 3924
#include <iostream>
using namespace std;
void ver(int n){
    int a,b,c,d;
    d=n%10;
    c=n%100/10;
    b=n%1000/100;
    a=n/1000;
    if(a+b+c+d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
        return;
    }
    if(a+b+c-d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
        return;
    }
    if(a+b-c+d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
        return;
    }
    if(a+b-c-d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
        return;
    }
    if(a-b+c+d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
        return;
    }
    if(a-b+c-d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
        return;
    }
    if(a-b-c+d==7){
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
        return;
    }
    if(a-b-c-d==7){
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
        return;
    }
}
int main(){
    int n;
    cin >> n;
    ver(n);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n, a, b, x;
  int score1=0;
  int score2=0;
  int score3=0;
   
  cin>>n;
  cin>>a;
  cin>>b;

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

    if(x<=a) { score1++; }
    else if(x<=b) {score2++; }
    else { score3++; }
  }
  
  int min_val = min(score1, min(score2, score3));
  cout<<min_val<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  int M=(N-1)*(N-2)/2;
  if(K<=M){
    cout<<N-1+M-K<<endl;
    REP(i,2,N) cout<<1<<" "<<i<<endl;
    int sum=0;
    rep(i,2,N){
      REP(j,i+1,N){
        if(sum==M-K) break;
        sum++;
        cout<<i<<" "<<j<<endl;
      }
    }
  }
  else cout<<-1<<endl;
  }


Measured memory_bytes: 256
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
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();
}

//change
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    if (A * N < B)
    {
        cout << A * N << endl;
    }
    else
    {
        cout << B << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>

class Dice{
    private:
        int t, b, n, e, s, w;
    public:
        void roll(char d);
        void showEast(){printf("%d\n", e);}
        int getT(){return t;}
        int getB(){return b;}
        int getN(){return n;}
        int getS(){return s;}
        int getE(){return e;}
        int getW(){return w;}
        bool eq(Dice hoge);
        Dice(int t, int s, int e, int w, int n, int b) : t(t), s(s), e(e), w(w), n(n), b(b) {}
};

bool Dice::eq(Dice hoge){
    if(t != hoge.getT()){
        return false;
    }
    if(b != hoge.getB()){
        return false;
    }
    if(n != hoge.getN()){
        return false;
    }
    if(s != hoge.getS()){
        return false;
    }
    if(w != hoge.getW()){
        return false;
    }
    if(e != hoge.getE()){
        return false;
    }
    return true;
}

void Dice::roll(char d){
    int tmp = 0;
    if (d == 'S') {
        tmp = s;
        s = t;
        t = n;
        n = b;
        b = tmp;
    }else if (d == 'E') {
        tmp = e;
        e = t;
        t = w;
        w = b;
        b = tmp;
    }else if (d == 'N') {
        tmp = n;
        n = t;
        t = s;
        s = b;
        b = tmp;
    }else if (d == 'W'){
        tmp = w;
        w = t;
        t = e;
        e = b;
        b = tmp;
    }else if (d == 'C'){    // Clockwise
        tmp = n;
        n = w;
        w = s;
        s = e;
        e = tmp;
    }else if(d == 'U'){     // Unti-Clockwise
        tmp = s;
        s = w;
        w = n;
        n = e;
        e = tmp;
    }
}

int main(){
    int a, b, c, d, e, f, q, t, s;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
    Dice dice(a, b, c, d, e, f);
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
    Dice dice2(a, b, c, d, e, f);
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    dice.roll('E');
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    dice.roll('W');
    dice.roll('W');
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    dice.roll('E');
    dice.roll('N');
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    dice.roll('S');
    dice.roll('S');
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    dice.roll('S');
    for(int i = 0; i < 4; i++){
        if(dice.eq(dice2)){
            printf("Yes\n");
            return 0;
        }
        dice.roll('C');
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    LL X;
    scanf("%lld", &X);
    
    // 2. A, B を 求める.
    // 上限は, 1019663401 = 120 * 120 * 120 * 120 * 120 - 119 * 119 * 119 * 119 * 119
    int A = 0, B = 0;
    repx(i, -120, 121){
        repx(j, -120, 121){
            LL a = (LL)j;
            LL b = (LL)i;
            if(a * a * a * a * a - b * b * b * b * b == X){
                A = j;
                B = i;
                break;
            }
        }
    }
    
    // 3. 出力.
    assert(!(A == 0 && B == 0));
    printf("%d %d\n", A, B);
    return 0;
    
}

Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
using namespace std;
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}
int n;
vector<int>ed[N];
int vis[N];
void dfs(int i,int mk){
	vis[i]=mk;
	for(int j:ed[i]){
		if(vis[j])continue;
		dfs(j,mk);
	}
}
void solve(){
	int m;
	cin>>n>>m;
	rep(i,m){
		int u,v,x;
		cin>>u>>v>>x;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int mk=0;
	rep(i,n){
		if(vis[i+1])continue;
		mk++;
		dfs(i+1,mk);
	}
	cout<<mk;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 9216
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class D
{
	public static void Main()
	{
		string[] args;
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);

		long[] x = new long[N];
		long[] y = new long[N];
		long[] z = new long[N];
		for(int i = 0; i < N; i++)
		{
			args = Console.ReadLine().Split(' ');
			x[i] = Int64.Parse(args[0]);
			y[i] = Int64.Parse(args[1]);
			z[i] = Int64.Parse(args[2]);
		}

		long ans = 0;
		for(int mask = 0; mask < (1 << 3); mask++)
		{
			List<long> xyz = new List<long>(N);
			for(int i = 0; i < N; i++)
			{
				long sum = 0;
				sum += x[i] * ((((mask >> 0) & 1) == 0) ? 1 : -1);
				sum += y[i] * ((((mask >> 1) & 1) == 0) ? 1 : -1);
				sum += z[i] * ((((mask >> 2) & 1) == 0) ? 1 : -1);
				xyz.Add(sum);
			}
			xyz.Sort((a,b) => b.CompareTo(a));
			long tmp = 0;
			for(int i = 0; i < M; i++)
				tmp += xyz[i];
			ans = Math.Max(ans,tmp);
		}

		Console.WriteLine(ans);		
	}	
}





Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  double h, w, x, y;
  cin >> h >> w >> x >> y;
  double ret = h * w / 2;
  bool has = (2 * x == h && 2 * y == w);
  cout << setprecision(10) << ret << " " << has << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n,ans=0;
  cin >> n ;
  vector<ll> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));
  rep(i,n){
    ll key=b[i];
    auto ia=lower_bound(all(a),key);
    auto ic=upper_bound(all(c),key);
    ans+=(ia-a.begin())*(c.end()-ic);
  }
  cout << ans << endl;
  return 0;
}


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

#define INF 100100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

ll comb(ll n,ll r){
   if(r==0)return 1;
   if(n==r)return 1;
   return comb(n-1,r-1)+comb(n-1,r);
}

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   ll N;
   cin>>N;
   vector<ll>a(N);
   for (ll i = 0; i < N; i++)cin>>a[i];
   sort(a.rbegin(),a.rend());
   ll MIN=INF;
   ll ans=0;
   for (ll i = 0; i < N; i++) {
      if(a[0]==a[i])continue;
      ll b;
      if(a[0]%2==0)b=abs(a[0]/2-a[i]);
      else b=min(abs((a[0]-1)/2-a[i]),abs((a[0]+1)/2-a[i]));
      if(b<=MIN){    
         ans=a[i];
         MIN=b;
      }
   }
   cout<<a[0]<<" "<<ans<<endl;
   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int h,w; cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h){
        rep(j,w) cin >> a[i][j];
    }
    vector<vector<int>> ans;
    rep(i,h-1){
        rep(j,w){
            if(a[i][j] %2 == 1){
                ans.push_back({i,j,i+1,j});
                a[i+1][j]++;
            }
        }
    }
    rep(i,w-1){
        if(a[h-1][i] %2 == 1){
            ans.push_back({h-1,i,h-1,i+1});
            a[h-1][i+1]++;
        }
    }
    int n = ans.size();
    cout << n << endl;
    rep(i,n){
        cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2]+1 << " " <<  ans[i][3]+1 << endl;
    }
}

Measured memory_bytes: 10544
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

const dy = [-1, 0, 1, 0];
const dx = [0, 1, 0, -1];

void main() {
    int H, W; readf("%d %d\n", &H, &W);
    auto F = new string[H];
    foreach (ref L; F) L = readln.chomp;

    auto D = new int[][](H, W);
    foreach (ref a; D) a[] = int.max / 2;

    int sy, sx;
    void init_yx() {
        foreach (int i, L; F) {
            foreach (int j, x; L) {
                if (x == '%') {
                    sy = i;
                    sx = j;
                    return;
                }
            }
        }
        assert(false);
    }
    init_yx();

    alias P = Tuple!(int, "y", int, "x");

    D[sy][sx] = 0;
    DList!P Q;
    Q.insert(P(sy, sx));
    while (! Q.empty) {
        auto c = Q.front; Q.removeFront;
        foreach (k; 0 .. 4) {
            int ny = c.y + dy[k];
            int nx = c.x + dx[k];
            if (ny < 0 || ny >= H) continue;
            if (nx < 0 || nx >= W) continue;
            if (F[ny][nx] == '#') continue;
            if (D[ny][nx] <= D[c.y][c.x] + 1) continue;
            D[ny][nx] = D[c.y][c.x] + 1;
            Q.insert(P(ny, nx));
        }
    }

    int soldier = int.max;
    int princess = int.max;
    foreach (i, L; F) {
        foreach (j, x; L) {
            if (x == '$') {
                soldier = min(soldier, D[i][j]);
            } else if (x == '@') {
                princess = min(princess, D[i][j]);
            }
        }
    }
    writeln(princess < soldier ? "Yes" : "No");
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll n;
    int k;
    cin >> n >> k;
    vector<int> num;

    int now = 1;
    while (now <= n) {
        int ng = 0, ok = n + 1, mid;
        while (ok - ng > 1) {
            mid = (ok + ng) / 2;
            ((n / mid < n / now) ? ok : ng) = mid;
        }
        num.push_back(ok - now);
        now = ok;
    }
    int m = sz(num);
    // rep(i, m) cout << num[i] << " \n"[i == m - 1];

    auto dp = make_vec<ll>(k + 10, m + 10);
    rep(i, m) dp[0][i] = 1LL;
    rep(i, k) {
        ll now = 0;
        rrep(j, m) {
            (now += dp[i][m - 1 - j] * num[m - 1 - j]) %= MOD;
            (dp[i + 1][j] += now) %= MOD;
        }
    }
    cout << dp[k][0] << endl;
}


Measured memory_bytes: 55676
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
#define pb push_back
int n, x, ban[2333];
int main(void) {
  read(n);
  rep (i, n) {
    int t; read(t); x ^= t;
    re0 (k, 31) if (t >> k & 1) {
      ban[k] = true;
      break;
    }
  }
  int ans = 0;
  for (int k = 31; ~k; k --)
    if (x >> k & 1) {
      if (!ban[k]) return puts("-1"), 0;
      ++ ans;
      for (int i = k; ~i; i --)
        x ^= 1<< i;
    }
  cout << ans << "\n";
    
}

Measured memory_bytes: 256
cnt = [0] * 6

for i in range(3):
    a = list(map(int, input().split()))
    cnt[a[0]] += 1
    cnt[a[1]] += 1

cnt_ = 0
ok = True
for i in range(1, 5):
    if cnt[i] % 2 == 1:
        cnt_ += 1
    if cnt[i] == 0:
        ok = False

print("YES" if ok and cnt_ == 2 else "NO")

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){

    int N,K;
    scanf("%d %d",&N, &K);
    
    int d[K];
    int A[N];
    int i,j,tmp;
    for(i = 0; i < N; i++){
        A[i] = 0;
    }
    for(i = 0; i < K; i++){
        scanf("%d",&d[i]);
        for(j = 0; j < d[i]; j++){
            scanf("%d",&tmp);
            A[tmp-1] = 1;
        }
    }

    int cnt = 0;
    for(i = 0; i < N; i++){
        if(0 == A[i]){
            cnt++;
        }
    }

    printf("%d\n",cnt);

    return 0;
}

Measured memory_bytes: 1692
#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

//つよいせぐつりー！(RUQ+RAQ) ばぐってるかも
struct LazySegTree { //参照は + sz - 1;
	ll sz;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
	LazySegTree(ll n) {
		sz = 1;
		while (sz < n) sz *= 2;
		node.resize(2 * sz - 1);//
		lazy.resize(2 * sz - 1);//
		lazyFlag.resize(2 * sz - 1);
	}
	void eval(ll k, ll l, ll r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];//
			if (r - l > 1) {
				lazy[2 * k + 1] = lazy[k] / 2;//
				lazy[2 * k + 2] = lazy[k] / 2;//
				lazyFlag[2 * k + 1] = lazyFlag[2 * k + 2] = true;
			}
			lazyFlag[k] = false;
			lazy[k] = 0;//
		}
		else {
			if (lazy[k] == 0)return;
			node[k] += lazy[k];//
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] / 2;//
				lazy[2 * k + 2] += lazy[k] / 2;//
			}
			lazy[k] = 0;//
		}
	}
	void add(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;//
			eval(k, l, r);

		}
		else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];//
		}
	}
	void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = (r - l) * x;//	
			lazyFlag[k] = true;
			eval(k, l, r);

		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];//
		}
	}
    void add(ll a, ll x) {
		add(a, a + 1, x);
	}
	void update(ll a, ll x) {
		update(a, a + 1, x);
	}
	ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;//
		if (a <= l && r <= b) return node[k];
		ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return vl + vr;//
	}
	void init() {
		REPR(i, sz - 2) node[i] = node[2 * i + 1] + node[2 * i + 2];//
	}
};

int main() {
    ll n, q;
    cin >> n >> q;
    LazySegTree seg(n);
    REP(i, q){
        ll t;
        cin >> t;
        if(t == 0){
            ll a, b, c;
            cin >> a >> b >> c;
            seg.update(a, b + 1, c);
            seg.add(a, b + 1, c);
            seg.add(a, b + 1, -c);
        }
        else{
            ll a, b;
            cin >> a >> b;
            cout << seg.query(a, b + 1) << endl;
        }
    }
}


Measured memory_bytes: 7064
#include <algorithm>
#include <iostream>
#include <climits>

using namespace std;

const int N = 5000;

int ii[N], cc[N], qu[N];
bool visited[N];

int main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int p; cin >> p, p--;
		ii[i] = p;
	}
	for (int i = 0; i < n; i++)
		cin >> cc[i];
	long long ans = LLONG_MIN;
	for (int i = 0; i < n; i++) {
		fill(visited, visited + n, false);
		int cnt = 0;
		int i_ = i;
		while (!visited[i_]) {
			qu[cnt++] = i_;
			visited[i_] = true;
			i_ = ii[i_];
		}
		int m = 0;
		int i__ = i;
		while (i__ != i_) {
			m++;
			i__ = ii[i__];
		}
		if (k < m) {
			long long a = 0;
			for (int h = 0; h < k; h++)
				ans = max(ans, a += cc[qu[h]]);
		} else {
			long long a = 0;
			for (int h = 0; h < m; h++)
				ans = max(ans, a += cc[qu[h]]);
			long long b = 0;
			for (int h = m; h < cnt; h++) {
				if (0 < h && h <= k)
					ans = max(ans, a + b);
				b += cc[qu[h]];
			}
			if (b > 0) {
				long long b_ = 0;
				for (int h = m; h < cnt && h <= k; h++) {
					ans = max(ans, a + (k - h) / (cnt - m) * b + b_);
					b_ += cc[qu[h]];
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
vector<long> fact_inv, inv, Com;
void init_nCk(int n,int k){
  fact_inv.resize(k+5);
  inv.resize(k+5);
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for(int i=2;i< k+5;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
  Com.resize(k+5);
  Com[0]=1;
  for(int i=1;i<k+5;i++){
    Com[i]=Com[i-1]*((n-i+1)*inv[i]%MOD)%MOD;
  }
}
int K,i,a;
long x=1,ans=0;
int nCk(int k){
    assert(!(k<0));
    return Com[k];
}
int main(){
  string S;
  cin>>K>>S;
  a=K+S.size();
  init_nCk(a,K);
  for(i=0;i<=K;i++){
    ans+=x*nCk(i);
    if(ans>MOD)ans%=MOD;
    x=x*25%MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

// O(1)
// O(N)

// Avoid this
// for(int i = 1;i <= 1000000;i++) if(memo[pos] == 0) cout << "YES"; // O(log(N)) -> memorinya sejuta
// Use this instead
// for(int i = 1;i <= 1000000;i++) if(memo.count(pos)) cout << "YES"; // O(log(n)) -> memorinya 0
// O(log N)
// (memo[pos] != 0)
// C++ bakal giniin : memo[pos] = int(0);, return memo[pos]; // O 
// memo.count(pos);

const LL LINF = 4557430888798830399LL;

LL n, d;
map <LL, LL> memo;
LL cost[3];
LL fact[3] = {2,3,5};

LL dp(LL pos){
    
    if(pos == 0) return 0;
    if(pos == 1) return d;

    if(memo.count(pos)) return memo[pos];
    
    LL ret = pos*d;
    if(pos > (1'000'000'000'000'000'000LL)/d) ret = LINF;

    // Coba dibagi X
    // Ada 2 cara, jadiin lowerbound X dimana, 2|X
    for(int i = 0;i < 3;i++){
        int x = fact[i];

        // misal x = 5
        // 12 -> 10/2
        LL rem = pos%x; // rem -> 2

        LL nx = pos-rem; // nx = 10
        LL nxcost = (pos-nx)*d; // pos dikurang kurangin sampe nx, terus bagi 5

        if(nx/x != 0) nxcost += cost[i];
        ret = min(dp(nx/x)+nxcost, ret);

        if(rem == 0) continue;
        
        // 12 -> 15/2
        nx = pos-rem+x; // nx = 15
        nxcost = (nx-pos)*d; // pos ditambah tambahin sampe nx, terus bagi 5

        if(nx/x != 0) nxcost += cost[i];
        ret = min(dp(nx/x)+nxcost, ret);
    }

    return memo[pos] = ret;
}

int main(){
    int testCases; cin >> testCases; int tc = 0;
    while(++tc <= testCases){

        memo.clear();
        cin >> n >> cost[0] >> cost[1] >> cost[2] >> d;
        cout << dp(n) << endl;
    
    }
}

Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int fun(int num){
	int ans=0;
	while(num>0){
		ans+=num%10;	num/=10;
	}
	return ans;
}

int main()
{
	int n;	cin>>n;
	int ans=100;
	for(int i=1;i<=n;i++){
		if(n-i < i)	break;
		ans=min(ans,fun(i)+fun(n-i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include"iostream"
using namespace std;
int n;
int main()
{
	cin >> n; 
	if (n == 1 || n == 0){
		cout << 1 << endl; return 0;
	}
	long long a=1, b=1,c;
	for (int i = 1; i < n; i++)
	{
		c = a + b;
		a = b;
		b = c;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
using namespace std;

const int N = 4;

int main(void){
  int ans = 0;
  for (int i=0; i<N; i++){
    char c;
    scanf("%c", &c);
    if (c=='+') ans++;
    else if (c=='-') ans--;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int n, w;
const int mx = 100 * 1e3 + 1;
vector<pair<int, ll>>arr;
ll dp[105][mx];
ll sol(int idx, int val){
	if (idx == n){
		if (!val)
			return 0;
		return OO;
	}
	if (val < 0)
		return OO;
	ll &ret = dp[idx][val];
	if (~ret)
		return ret;
	return ret = min(sol(idx + 1, val),
		sol(idx + 1, val - arr[idx].second) + arr[idx].first);
}
int main(){
	K_K();
	cin >> n >> w;
	arr.resize(n);
	clr(dp, -1);
	for (int i = 0; i < n; i++){
		cin >> arr[i].first >> arr[i].second;
	}
	int ans = 0;
	for (int i = 1; i < mx; i++){
		if (sol(0, i) <= w){
			ans = i;
		}
	}
	cout << ans;
}

Measured memory_bytes: 85680
#include <stdio.h>

int H = 1, W = 1;

int main()
{
    while (H != 0 && W != 0)
    {
        scanf("%d %d", &H, &W);
        for (int i = 1; i <= H; i++)
        {
            for (int j = 1; j <= W; j++)
            {
                printf("#");
            }
            printf("\n");
        }
        if (H != 0 && W != 0)
        {
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll mask[41];
set<pair<ll,int> >used;
int n,m,a[41],ans,sum;
bool u[41];
void rec(ll zan,int cur,ll use){
	if(cur == n-1){
		ll M = 0; int S = 0;
		rep(i,n) if(((use>>i)&1LL)) M |= mask[i];
		rep(i,n) if(!((M>>i)&1LL)) S += a[i];
		ans = max(ans,S);
		return;
	}
	if(used.find(mp(use,cur)) != used.end()) return ;
	used.insert(mp(use,cur));
	rep(i,n){
		if(!((mask[cur]>>i)&1LL)) continue;
		if(!((zan>>i)&1LL)) continue;
		ll go = zan - (zan&mask[cur]);
		//assert(!((go>>i)&1LL));
		go += (1LL<<i);
		rec(go,i,use|(1LL<<i));
	}
}
int main(){
    cin>>n>>m;
    rep(i,n){
        cin>>a[i]; sum+=a[i];
        mask[i] = 1LL<<i;
    }
    rep(i,m){
        int a,b;
        cin>>a>>b; a--; b--;
        mask[a] |= 1LL<<b;
        mask[b] |= 1LL<<a;
    }
    queue<int>que;
    que.push(0);
    while(!que.empty()){
        int q = que.front(); que.pop(); if(u[q]) continue;
        u[q] = 1;
        rep(i,n) if( ((mask[q]>>i)&1LL) == 1LL && !u[i]){
            que.push(i);
        }
    }
    ll beg = 0;
    rep(i,n) if(u[i]) beg += 1LL<<i; 
    rec(beg,0,1);
    cout<<sum-ans<<endl;
}

Measured memory_bytes: 86132
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			int n = in.nextInt();
			int count=0;
			if(n>36)
				System.out.println("0");
			else {
				for(int i=0;i<=9;i++) {
					for(int j=0;j<=9;j++) {
						for(int k=0;k<=9;k++) {
							for(int l=0;l<=9;l++) {
								if(i+j+k+l==n)
									count++;
							}
						}
					}
				}
				System.out.println(count);
			}
		}
		in.close();
	}
}


Measured memory_bytes: 26568