akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 41

typedef struct node{
  int l, r;
}node;

node c[N];
int a[N], b[N];
int cnt=0;

void postorder(int root,int n){

        if(c[root].l != -1) postorder(c[root].l, n);
        if(c[root].r != -1) postorder(c[root].r, n);
        if(cnt < n - 1) printf("%d ", root);
        else printf("%d\n", root);

        cnt++;

        return;

}

int reconst(int start,int last,int n){
  int i, j;

  if(start == last) return b[start];
  else if(start > last) return -1;

  else {
    for(i = 1 ; i <= n ; i++){
      for(j = start ; j <= last ; j++){
        if(a[i] == b[j]){
          c[a[i]].l = reconst(start, j - 1, n);
          c[a[i]].r = reconst(j + 1, last, n);
          return a[i];
        }
      }
    }
  }
}


int main(){
  int n,i, root;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
  for(i = 1 ; i <= n ; i++) scanf("%d",&b[i]);
  for(i = 1 ; i <= n ; i++){
    c[i].l = -1;
    c[i].r = -1;
  }

  root = reconst(1,n,n);

  postorder(root,n);

  return 0;

}


Measured memory_bytes: 2104
import bisect

N, M, V, P = map(int, input().split())
A = list(map(int, input().split())) + [-M-1]
A.sort()

Ap = A[-P] # 初期状態でP番目に大きい点数
I = N + 2 - P
right = N + 1 - P
left = 0

while left + 1 < right:
  mid = (left + right) // 2
  b = A[mid] + M
  if b < Ap:
    left = mid
  else:
    v = V - (bisect.bisect_right(A, A[mid])-1) - (P-1)
    if v <= 0:
      right = mid
    else:
      mv = M*v
      for i in range(mid+1, I):
        if A[i] == A[mid]:
          continue
        mv -= b - A[i]
        if mv <= 0:
          break
      if mv <= 0:
        right = mid
      else:
        left = mid

print(N + 1 - right)

Measured memory_bytes: 14252
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
const double EPS = 1e-8;
int sgn(double x){return (x > EPS) - (x < -EPS);}
LL n;
int bit[20];
int main(){
   // IN;
     cin >> n;
    int len = 0;
    for(; n; n /=10) bit[len++] = n % 10;
    int ans = 0;
    FF(i, 0, len - 1) ans += bit[i];
    int ans0 = ans-bit[0];
    for(int i = 1; i <= len - 1; ++i)
        {
            ans0 -= bit[i];
            if(bit[i] > 0){
                int t = ans0 + bit[i]-1;
                t+=(i)*9;
                if(t > ans) ans = t;
            }
        }
        PR(ans);
    return 0;
}


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

int main(){
	long long a,b,c,d;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	long long tmp = max(a*d,max(b*c,max(a*c,b*d)));
	printf("%lld\n",tmp);
} 

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S;
int alp[26];

void input() {
	cin>>S;
}

void solve() {
	ll res=(ll)S.len*(S.len-1)/2+1;
	for(int i=0; i<S.len; i++) {
		res-=alp[S[i]-'a'];
		alp[S[i]-'a']++;
	}
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3732
n,k=map(int,input().split())
a=[0]+[int(input())-k for _ in range(n)]
sm=0
ac=[]
for ai in a:
    sm+=ai
    ac.append(sm)


def rec(l):
    ll=len(l)
    if ll<=1:
        return 0
    l1=l[:ll//2]
    l2=l[ll//2:]
    res=rec(l1)+rec(l2)
    l1.sort()
    l2.sort()
    i2=0
    for i in range(len(l1)):
        while i2<len(l2) and l2[i2]<l1[i]:
            res+=len(l1)-i
            i2+=1
    return res
print(n*(n+1)//2-rec(ac))
    
    

Measured memory_bytes: 89636
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    static int N;
    static int S;
    static int[] A;

    public static void main(String[] args) {
        N = in.nextInt();
        S = in.nextInt();
        A = new int[N];
        for (int i = 0; i < N; i++)
            A[i] = in.nextInt();
        dp = new long[N][S];
        for (int i = 0; i < N; i++) for (int j = 0; j < S; j++)
            dp[i][j] = -1;
        out.println(dp(0, 0, 0));
        out.flush();
    }

    static long dp[][];

    private static long dp(int n, int s, int c) {
        if (s == S) return mPow(2, N - c);
        if (s > S || n >= N) return 0;
        if (dp[n][s] == 0) return 0;
        if (dp[n][s] > 0) return (dp[n][s] * mInv(mPow(2, c))) % MOD;
        long l = (dp(n + 1, s, c) + dp(n + 1, s + A[n], c + 1)) % MOD;
        dp[n][s] = (l * mPow(2, c)) % MOD;
        return l;
    }

    static final int MOD = 998244353;
    static long mPow(long a, long b) {
        long ret = 1;
        while (b > 0) {
            if (b % 2 == 1)
                ret = (ret * a) % MOD;
            a = (a * a) % MOD;
            b /= 2;
        }
        return ret;
    }
    static long mInv(long a) {
        return mPow(a, MOD - 2);
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 106960
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    vll vec(3);
    REP(i, 3) {
        cin >> vec.at(i);
    }
    sort(ALL(vec));
    if (vec.at(0) + vec.at(1) == vec.at(2)) {
        cout << "Yes" << endl;
        return 0;
    } else {
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

#define ll long long

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

    int result = N % 10;

    if(result == 3) {
        std::cout << "bon" << std::endl;
    }
    else if(result == 0 or result == 1 or result == 6 or result == 8) {
        std::cout << "pon" << std::endl;
    }
    else {
        std::cout << "hon" << std::endl;
    }
}

Measured memory_bytes: 3656
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
t=i1()
def gcd(a,b):
  while b:
    if a<b:
        c=b
        b=a
        a=c
    if b:a%=b
  return a
for i in range(t):
 [a,b,c,d]=i2()
 if a<b:
   print("No")
 else:
   if d<b:
      print("No")
   else:
      if c>=b:
         print("Yes")
      else:
         g=gcd(b,d)
         x=b-g+a%g
         if x>c:
           print("No")
         else:
           print("Yes")

Measured memory_bytes: 38768
S = input()
T = input()

d_s2t = dict()
d_t2s = dict()

flg = True
for s, t in zip(S, T):
    if d_s2t.get(s, t) == t:
        d_s2t[s] = t
    else:
        flg = False
        break

    if d_t2s.get(t, s) == s:
        d_t2s[t] = s
    else:
        flg = False
        break

print('Yes' if flg else 'No')

Measured memory_bytes: 3632
from itertools import product
datas=[]
num=0

N=int(input())
for i in range(N):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        datas.append((num,x-1,y))
    num+=1
#print(datas)

ans=0
for i in product([0,1],repeat=N):
    ok=True
    cnt=0
    for j in datas:
        if (i[j[0]]==1 and i[j[1]]!=j[-1]):
            ok=False
            break
    if ok:
        cnt=sum(i)
        ans=max(ans,cnt)
    
print(ans)

Measured memory_bytes: 9204
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

int ar[2*N];
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n,xo=0;
        cin>>n;
        for(int i=1; i<=n; ++i) {
            cin>>ar[i];
            xo^=ar[i];
        }
        for(int i=1; i<=n; ++i) {
            cout<<(xo^ar[i]);
            if(i!=n)cout<<" ";
        }
    }
    return 0;
}



Measured memory_bytes: 4380
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3

output:
1 0
2 1
3 2
4 1
"""

import sys
from collections import deque

UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(adj_list)
    return init_adj_table


def graph_bfs(v_init):
    status[v_init] = VISITED_IN_QUEUE
    distance[v_init] = 0
    queue.appendleft(v_init)

    while queue:
        current = queue.popleft()
        for v in adj_table[current]:
            if status[v] is UNVISITED:
                status[v] = VISITED_IN_QUEUE
                distance[v] = distance[current] + 1
                queue.append(v)
        status[current] = POPPED_OUT
    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = list(map(lambda x: x.split(), _input[1:]))
    init_adj_table = [[] for _ in range(vertices_num + 1)]
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    queue = deque()
    status = [UNVISITED] * (vertices_num + 1)
    distance = [-1] * (vertices_num + 1)

    adj_table = generate_adj_matrix(vertices_info)
    ans = graph_bfs(1)
    for j in range(vertices_num):
        print(j + 1, ans[j + 1])

Measured memory_bytes: 8040
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
typedef vector<ll> vll;

const ll MAX=1000000000000000000;

int N; vll A;
void input()
{
    cin>>N;
    A.resize(N);
    for(int i=0;i<N;++i) cin>>A[i];
}

void solve()
{
    sort(A.begin(),A.end());
    ll ans=1;
    for(int i=0;i<N;++i){
        if(A[i]==0){
            cout<<0<<endl; return;
        }
        else if(MAX/ans<A[i]){
            cout<<-1<<endl; return;
        }
        ans*=A[i];
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    ll n;
    cin >> n;
   
    ll sum=0;
    ll min_val=LLONG_MAX;
    ll count=0;
    for (ll i=0;i<=n-1;i++)
    {
        ll a;
        cin >> a;
        sum=sum+abs(a);
        min_val=min(min_val,abs(a));

        if (a<0)
        {
            count++;
        }
    }

    if (count%2==0)
    {
        cout << sum << endl;
    }
    else
    {
        cout << sum-2*min_val << endl;
    }

    return 0;
}

Measured memory_bytes: 3664
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	for i := 0; i < 4; i++ {
		c := 0
		for j := 0; j < 4; j++ {
			if s[i] == s[j] {
				c++
			}
		}
		if c != 2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
use proconio::input;
fn main() {
    input! {
        _: usize,
        a: usize,
        b: usize,
        s: String
    }

    let lim = a + b;
    let mut count = 0;
    let olim = b;
    let mut ocount = 0;

    for c in s.chars() {
        if c == 'a' {
            if count < lim {
                println!("Yes");
                count += 1;
                continue;
            }
        }

        if c == 'b' {
            if count < lim && ocount < olim {
                println!("Yes");
                count += 1;
                ocount += 1;
                continue;
            }
        }

        println!("No");
    }
}


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

using namespace std;

int main()
{
    int raw[100]={};
    int n;    
    cin >> n;
    for(int i=0;i<n;i++){cin >> raw[i];}
    for(int j=n-1; 0 <= j; j--)
    {
        printf("%d", raw[j]);
        if(j!=0) {cout << ' ';}
        else     {cout << endl;}
    }
}


Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Io.Read<int>();
            var S = Io.Read();

            var numABC = 0;
            for (var i = 0; i < S.Length - 2; i++)
            {
                if (S[i] == 'A' && S.Substring(i, 3) == "ABC")
                {
                    numABC++;
                }
            }

            Io.Write(numABC.ToString());
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }

        class Io
        {
            public static string Read()
            {
                return Console.ReadLine();
            }

            public static IEnumerable<string> ReadRepeat(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read());
            }

            public static T Read<T>()
            {
                return (T)Convert.ChangeType(Read(), typeof(T));
            }

            public static IEnumerable<T> ReadRepeat<T>(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read<T>());
            }

            public static string[] ReadList(char devide = ' ')
            {
                return Read().Split(devide);
            }

            public static T[] ReadList<T>(char devide = ' ')
            {
                return ReadList(devide)
                    .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                    .ToArray();
            }

            public static IEnumerable<T[]> ReadListRepeat<T>(int count, char devide = ' ')
            {
                return Enumerable.Range(0, count).Select(_ => ReadList<T>(devide));
            }

            public static void Write(string value)
            {
                Console.WriteLine(value);
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A < C && C < B || A > C && C > B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        while(true){
            String s = sc.next();
            if(s.equals("0")) break;
            for(int i = 0; i < s.length(); i++){
                sum += s.charAt(i) - '0';
            }
            System.out.println(sum);
            sum = 0;
        }
    }
}



Measured memory_bytes: 26156
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<ll> a(n),b(n),c(n-1);
  rep(i,0,n){
    std::cin>>a[i];
    a[i]--;
  }
  rep(i,0,n)std::cin>>b[i];
  rep(i,0,n-1)std::cin>>c[i];

  ll ans=b[0],prev=a[0];

  rep(i,1,n){
    ans+=b[i];
    if(a[i]==prev+1)ans+=c[prev];
    prev=a[i];
  }

  std::cout<<ans;

  return 0;
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}


int n, m;

void solve() {
    read(n, m);
    vt<ar<int, 2>> a(m);
    vt<int> v(n + 1);
    FOR(m) {
        read(a[i][0], a[i][1]);
        if (a[i][0] == 1) {
            v[a[i][1]]++;
        }
    }
    
    FOR(m) {
        if (a[i][1] == n && v[a[i][0]]) {
            print("POSSIBLE");
            return;
        }
    }
    print("IMPOSSIBLE");
    
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        //write("Case #", i + 1, ": ");
        solve();
        
    }
    
}



Measured memory_bytes: 7920
#include<stdio.h>
#define REP(i,n) for (int i = 0 ; i < (int)n ; i++)
typedef long long ll;

int main(){
    int r,c; 
    scanf("%d %d",&r,&c);
    int a[r+1][c+1];
    REP(i,r+1){
        REP(j,c+1){
            a[i][j] = 0;
        }
    }
    REP(i,r){
        REP(j,c){
            scanf("%d",&a[i][j]);
            a[i][c] += a[i][j]; 
            a[r][j] += a[i][j];
        }
        a[r][c] += a[i][c];
    }
    REP(i,r+1){
        REP(j,c+1){
            if( j == c ) printf("%d",a[i][j]);
            else printf("%d ",a[i][j]);
            
        }
        printf("\n");
    }
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
  int n, h;
  cin >> n >> h;
  vector<long>a(n), b(n);
  for(int i=0; i<n; i++){
    cin >> a[i] >> b[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  long i;
  for(i=0; i<n; i++){
    if(h<=0){
      cout << i;
      return 0;
    }
    if(b[i]<a[0])break;
    h-=b[i];
  }
  if(h<=0){
    cout << i;
    return 0;
  }
  if(h%a[0]==0)i+=h/a[0];
  else i+=h/a[0]+1;
  cout << i;
  return 0;
}

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

#define mp make_pair
#define pb push_back
const int INF = 1000000000;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

ll Q, H, S, D, N;

int main(){
    cin >> Q >> H >> S >> D >> N;
    if(2* Q < H){
        H = 2 * Q;
    }
    if(2 * H < S){
        S = 2 * H;
    }
    if(2 * S < D){
        D = 2 * S;
    }
    ll c = (N/2 * D) + (N%2 * S);
    cout << c << endl;
    

}

Measured memory_bytes: 256
import collections
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]

kind = dict(collections.Counter(ball))

if len(kind) <= K:
    print(0)
else:
    skind = sorted(kind.items(),key=lambda x: x[1])
    sumNum = 0
    for i in range(len(skind)-K):
        sumNum += skind[i][1]
    print(sumNum)

Measured memory_bytes: 39316
#!/usr/bin/env python3
import sys
import numpy as np
import numba

input = sys.stdin.readline


def I():
    return int(input())


# @njit((i8[:],), cache=True)
@numba.jit
def main(n):
    table = np.zeros(n, np.int64)

    for i in range(1, n):
        table[::i] += 1

    ans = 0
    for n in table[1:]:
        q, r = divmod(n, 2)
        ans += q * 2 + 1 * r

    return ans


N = I()

print(int(main(N)))


Measured memory_bytes: 128296
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	char n[11];
	int i, s = 0;
	scanf("%s", n);
	for (i = 0; n[i] != '\0'; i++) s += n[i] - '0';
	puts(atoi(n) % s ? "No" : "Yes");
	return 0;
}

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

int n,ans;
int f[100005];
int v[16],cnt,dp[1<<15],x[1<<15];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        f[a]^=c;
        f[b]^=c;
    }
    for(int i=0;i<n;i++){
        if(!f[i])ans++;
        else v[f[i]]++;
    }
    for(int i=1;i<=15;i++){
        ans+=v[i]>>1;
        v[i]&=1;
        if(v[i])v[cnt++]=i;
    }
    for(int s=0;s<1<<cnt;s++){
        for(int i=0;i<cnt;i++){
            if(s>>i&1)x[s]^=v[i];
        }
    }
    for(int s=0;s<1<<cnt;s++){
        int rs=s^((1<<cnt)-1);
        for(int t=rs;t;t=(t-1)&rs){
            if(!x[t])dp[s|t]=max(dp[s|t],dp[s]+1);
        }
    }
    ans+=dp[(1<<cnt)-1];
    cout<<n-ans<<endl;

    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM =  1000000007;
int main()
{
    // 整数の入力
    ll W,H,x,y;
    cin >> W >> H >> x >> y;
    cout << fixed  <<W * H * 1.0/2 << " ";
    if (2 * x == W && 2 * y == H ){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int d[n];
    REP(i,n){
        cin >> d[i];
    }
    int ans = 0;
    REP(i,n){
        for(int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

A = sorted(A)
ans = 1
if N % 2 == 0:#[1,1,3,3,5,5,...]
  for i in range(N):
    xx = int(i / 2)
    if A[i] != 2 * xx + 1:
      ans = 0
    else:
      if i % 2 == 1:
        ans *= 2
        ans %= mod
else:#[0, 2, 2, 4, 4 ...]
  for i in range(N):
    xx = int((i + 1)/2)
    if A[i] != 2 * xx:
      ans = 0
    else:
      if (i % 2 == 0) and (i != 0):
        ans *= 2
        ans %= mod
      
      
  
  
print(ans)



Measured memory_bytes: 20600
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	mochis := make([]int, n)
	overlapm := []int{}
	for i := 0; i < n; i++ {
		fmt.Scan(&mochis[i])
	}
	m := make(map[int]bool)
	for _, mochi := range mochis {
		if !m[mochi] {
			m[mochi] = true
			overlapm = append(overlapm, mochi)
		}
	}
	fmt.Println(len(overlapm))
}


Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;

	public void solve() {

		StringBuilder sb = new StringBuilder();
		String S;
		N = nextInt();
		for(int i = 0;i < N;i++){
			sb.append(nextInt());
		}

		S = sb.toString();

		for(int i = 0;i < (int)1e4 + 1;i++){
			if(S.indexOf(String.valueOf(i)) == -1){
				out.println(i);
				break;
			}
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x >= r && x <= W-r && y >= r && y <= H-r){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
H,W=map(int,input().split())
#H×Wのマス目入力の周りに"."を付け加える関数
def pixel_input(H,W,border="."):
    pixel = [[border]*(W+2)] + \
    [[border] + list(input()) + [border] for _ in range(H)] + \
    [[border]*(W+2)]
    return pixel
S=pixel_input(H,W)
flag=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="#":
            if S[i-1][j]==S[i+1][j]==S[i][j-1]==S[i][j+1]==".":
                print("No")
                sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  for(int i=0;i<N;i++){cin >> A[i];}
  for(int i=0;i<N;i++){cin >> B[i];}
  for(int i=0;i<N;i++){cin >> C[i];}
  sort(A.begin(),A.end()); sort(C.begin(),C.end());
  long long count=0;
  long long a,c;
  for(int i=0;i<N;i++){
    auto pos=lower_bound(A.begin(),A.end(),B[i]);
    a=pos-A.begin();
    auto posx=upper_bound(C.begin(),C.end(),B[i]);
    c=C.end()-posx;
    count+=a*c;
  }
  cout << count << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
string reverse(int,int,string);
string notReverse(int,int,string);

int main(){
  int n;
  cin >> n;
  int i = 0;
  while(i != n){
    set<string> s;
    string str;
    
    cin >> str;
    
    s.insert(str);
    for(int j = 0;j < str.length()-1;j++){
      string tmp = str;
      
      s.insert(reverse(0,j,str)+notReverse(j+1,str.length()-1,str));
      s.insert(reverse(j+1,str.length()-1,str)+notReverse(0,j,str));
      
      s.insert(notReverse(0,j,str)+notReverse(j+1,str.length()-1,str));
      s.insert(notReverse(j+1,str.length()-1,str)+notReverse(0,j,str));

      
      
      s.insert(notReverse(0,j,str)+reverse(j+1,str.length()-1,str));
      s.insert(notReverse(j+1,str.length()-1,str)+reverse(0,j,str));
      
      s.insert(reverse(0,j,str)+reverse(j+1,str.length()-1,str));
      s.insert(reverse(j+1,str.length()-1,str)+reverse(0,j,str));
      


      
    }
        cout << s.size() << endl;
    /////////////
    /*
    set<string>::iterator it = s.begin();
    s.erase( it++ );    // 要素を削除し、インクリメントを１つ先へ進める
    
    // 要素を出力する
    it = s.begin();
    while( it != s.end() )
      {
	cout << *it << endl;
	++it;
      }
    */
    ////////////
    
    i++;
  }
    
  return 0;
}
string reverse(int f,int l,string str){
  string tmp = string(str,f,l+1);
  string tmp2 = string(str,f,l+1);
  for(int i = 0;i <= l-f;i++){
    tmp[i] = tmp2[l-f-i];
  }
  
  
  return tmp;
}
string notReverse(int f,int l,string str){
  string tmp = string(str,f,l+1);
  return tmp;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

void solve()
{
string s;
cin>>s;
int i=0;
long long sum=0;
while(i<s.size())
{
	sum+=(s[i]-'0');
	i++;
}

if(sum%9==0)
	cout<<"Yes";
else 
	cout<<"No";
}
int main()
{	
	fast;
	int t=1;
	//cin>>t;
	while(t--)
		solve();
}	


Measured memory_bytes: 3768
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char c = sc.next().charAt(0);
        switch(c){
            case'a':
            case'e':
            case'i':
            case'o':
            case'u':
                System.out.println("vowel");
                break;
            default:
                System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 21716
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    l = r = 0
    for i in range(0,x+1):
        if i in a:
            l += 1
    sign = 1 if x<n else -1
    for i in range(x,n+sign,sign):
        if i in a:
            r += 1
    ans = min(l,r)
    print(ans)
    return

if __name__=='__main__':
    n,m,x = IL()
    a = set(IL())
    solve()

Measured memory_bytes: 9380
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;

    ll ans = N*(N+1)/2;
    p(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

const int MAX = 25;
const int NIL = -1;

typedef struct {
    int parent;
    int left;
    int right;
    int depth;
    int height;
} Node;
Node nodes[MAX];

int degree(int u)
{
    int count = 0;
    if (nodes[u].left != NIL) count++;
    if (nodes[u].right != NIL) count++;
    return count;
}

void setDepth(int u, int depth)
{
    if (u == NIL) return;

    nodes[u].depth = depth;
    setDepth(nodes[u].left, depth + 1);
    setDepth(nodes[u].right, depth + 1);
}
// 兄弟ノードを求める
int getSibling(int u)
{
    if (nodes[u].parent == NIL) return NIL;
    int parent = nodes[u].parent;
    // ノードuが親から見て右の子ノードの場合、左子ノードを返す。
    if (nodes[parent].left != u && nodes[parent].left != NIL)
        return nodes[parent].left;
    if (nodes[parent].right != u && nodes[parent].right != NIL)
        return nodes[parent].right;
    return NIL;

        return nodes[parent].left;
}

inline int max(int a, int b)
{
    return (a < b) ? b : a;
}

int setHeight(int u)
{
    int h1 = 0;
    int h2 = 0;
    h1 = (nodes[u].right == NIL) ? 0 : setHeight(nodes[u].right) + 1;
    h2 = (nodes[u].left == NIL) ? 0 : setHeight(nodes[u].left) + 1;

    nodes[u].height = max(h1, h2);
    return nodes[u].height;
}

void printNode(int u)
{
    cout << "node " << u << ": ";
    cout << "parent = " << nodes[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    cout << "degree = " << degree(u) << ", ";
    cout << "depth = " << nodes[u].depth << ", ";
    cout << "height = " << nodes[u].height << ", ";
    if (nodes[u].parent == NIL)
        cout << "root";
    else if (nodes[u].left == NIL && nodes[u].right == NIL)
        cout << "leaf";
    else
        cout << "internal node";
    cout << endl;
}


int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    for (int i = 0; i < MAX; i++)
    {
        nodes[i].parent = NIL;
        nodes[i].left = NIL;
        nodes[i].right = NIL;
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
       int id, left, right;
       cin >> id >> left >> right;
        nodes[id].left = left;
        if (left != NIL)
            nodes[left].parent = id;

        nodes[id].right = right;
        if (right != NIL)
            nodes[right].parent = id;
    }

    int root;
    // find root
    for (int i = 0; i < n; i++)
    {
        if (nodes[i].parent == NIL)
        {
            root = i;
            break;
        }
    }

    setDepth(root, 0);
    setHeight(root);

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


    return 0;
}


Measured memory_bytes: 3172
import math
n=int(input())
R=[0]*n
sum=0
for i in range(n):
    R[i]=int(input())
for i in range(n):
    if R[i]<0:
        continue
    s=math.sqrt(R[i])
    s=int(s)+1
    for j in range(2,s+1):
        if R[i]==j:
            sum=sum+1
        if R[i]%j==0:
            break
        if j==s:
            sum=sum+1
print(sum)


Measured memory_bytes: 6044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

struct Node {
    int key;
    Node* next;
    Node* prev;
};

Node* nil;

Node* listSearch(int key)
{
    Node* cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init()
{
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList()
{
    Node* cur = nil->next;
    int isf = 1;
    while (1) {
        if (cur == nil) {
            break;
        }
        if (isf == 0) {
            printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

void deleteNode(Node* t)
{
    if (t == nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

void insert(int key)
{
    Node* x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            insert(key);
            np++;
            size++;
        } else {
            if (strlen(com) > 6) {
                if (com[6] == 'F') {
                    deleteFirst();
                } else {
                    deleteLast();
                }
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }

    printList();
    return 0;
}


Measured memory_bytes: 34376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
long long MOD = 1e9 + 7;
using namespace std;

int main() {
  int n;
  int x[10];
  int y[10];
  cin >> n;
  rep(i, n) { cin >> x[i] >> y[i]; }

  double ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      double dx = x[i] - x[j];
      double dy = y[i] - y[j];
      ans += pow(dx * dx + dy * dy, 0.5) * 2 / n;
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 640
//package practice; 
import java.io.*;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		 
		long n = sc.nextLong();
		long k = sc.nextLong();
		long max = ((n-1)*(n-2))/2;
		List<Pair> ans = new ArrayList<>();
		if(k>max) out.println(-1);
		else {
			for(int i=2;i<=n;++i) ans.add(new Pair(1,i));
			long need = max-k;
			for(int i=2;i<=n && need>0;++i) {
				for(int j=i+1;j<=n && need>0;++j) {
					ans.add(new Pair(i,j));
					--need;
				}
			}
			
			out.println(ans.size());
			for(Pair p : ans) out.println(p.u+" "+p.v);
		}
		
		 out.close();
		 
	}
	static class Pair{
		int u;
		int v;
		Pair(int u,int v){
			this.u = u;
			this.v = v;
		}
	}
	
}		






Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

double l[20],a[20],b[20];
double d[20][20];

int main(){
  int n,m;
  double dp[1<<20];
  
  cin >> n >> m;

  for(int i=0;i<n;i++)cin >> l[i] >> a[i] >> b[i];

  for(int y=0;y<n;y++){
    for(int x=y;x<n;x++){
      d[x][y] =(l[x]-l[y])*(l[x]-l[y]) + (a[x]-a[y])*(a[x]-a[y]) + (b[x]-b[y])*(b[x]-b[y]);
      d[y][x] = d[x][y];
    }
  }

  double mx = 0.0;
  for(int i=0;i<(1<<n);i++){
    int cnt = 0;
    for(int j=0;j<n;j++){
      if( i & (1<<j) ){
	cnt++;
	int tmp = i - (1<<j);
	if(cnt==1){
	  dp[i] = dp[tmp];
	  for(int k=0;k<n;k++){
	    if( tmp & (1<<k) )dp[i] += d[j][k];
	  }
	}
      }
    }
    if(cnt == m)mx = max(dp[i],mx);
  }
  printf("%.8lf\n",mx);
}

Measured memory_bytes: 9124
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		StringBuffer sb = new StringBuffer(s);
		StringBuffer sbr = sb.reverse();
		if ( sbr.toString().equals(s) ) {
			String s1 = s.substring(0, (s.length()-1)/2);

			StringBuffer sb1 = new StringBuffer(s1);
			StringBuffer sbr1 = sb1.reverse();
			
			String s2 = s.substring((s.length()+1)/2);

			StringBuffer sb2 = new StringBuffer(s2);
			StringBuffer sbr2 = sb2.reverse();
			
			if ( sbr1.toString().equals(s1) && sbr2.toString().equals(s2) ) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ChristmasEve | diff ChristmasEve.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ChristmasEve.cpp && ./a.out

/*
 
 2/3/2019
 
 10:36-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,K;

void solve() {
  sort(A,A+N);
  LL res=1e9;
  REP(i,N) if(i+K<=N) {
    SMIN(res,A[i+K-1]-A[i]);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 1024