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

int main(){
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)&&s.at(0)==s.at(2)&&s.at(0)==s.at(3)){
    cout << "No" << endl;
  }else if(s.at(0)==s.at(1)){
    if(s.at(2)==s.at(3)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else if(s.at(0)==s.at(2)){
    if(s.at(1)==s.at(3)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else if(s.at(0)==s.at(3)){
    if(s.at(1)==s.at(2)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

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

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	int cnt = 0;
	int itr = 0;
	vector<vector<int>> ans(h,vector<int>(w));
	for(int y=0;y<h;y++) {
		if(y%2 == 0) {
			for(int x=0;x<w;x++) {
				if(cnt == a[itr]) {
					cnt = 0;
					itr++;	
				}
				ans[y][x] = itr+1;
				cnt++;
			}
		} else {
			for(int x=w-1;x>=0;x--) {
				if(cnt == a[itr]) {
					cnt = 0;
					itr++;	
				}
				ans[y][x] = itr+1;
				cnt++;
			}
		}
	}
	for(int y=0;y<h;y++)
		for(int x=0;x<w;x++)
			cout << ans[y][x] << ((x==w-1)?"\n":" ");
}

Measured memory_bytes: 384
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}


use input::*;
use std::cmp;

fn main() {
    let (a, b): (isize, isize);
    input!(a, b);
    p(cmp::max(a + b, cmp::max(a - b, a * b)));
}


Measured memory_bytes: 4352
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-b (n)
  (let ((l (loop for i below n collect (read))))
    (princ
     (loop for i from 1 below (- n 1)
	count (let ((ll
		     (sort (list (nth (1- i) l)
				 (nth i l)
				 (nth (1+ i) l))
			   #'<)))
		(= (nth i l)
		   (nth 1 ll)))))))

(solution-b)

Measured memory_bytes: 15456
// AOJ 2344: Multi Ending Story
// 2017.11.23 for test

#include <stdio.h>

#define MIN(a,b) ((a)<=(b)?(a):(b))
#define MAX 500002
int L[MAX], R[MAX], D[MAX];
long long E[MAX], U[MAX], S[MAX];

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, i, l, r;

	fgets(p=buf, 10, stdin), n = getint();
	for (i = 1; i < n; i++) {
		fgets(p=buf, 20, stdin);
		L[i] = getint(), p++, R[i] = getint();
	}
	for (i = 1; i < n; i++) D[L[i]] = D[R[i]] = D[i]+1;
	E[n] = 1;
	for (i = n-1; i > 0; i--) {
		l = L[i], r = R[i];
		E[i] = E[l] + E[r];
		U[i] = E[i] + U[l] + U[r];
		S[i] = MIN(D[i]+S[l]+S[r]+2, MIN(S[l]+U[r]+E[r]+1, S[r]+U[l]+E[l]+1));
	}
	printf("%lld\n", MIN(U[1], S[1]));
	return 0;
}

Measured memory_bytes: 19272
import sys
input = sys.stdin.readline

def main():
    n,s = map(int,input().split())
    a = list(map(int,input().split()))

    mod = 998244353

    dp = [[0]*s for _ in range(n)]

    for i in range(n):
        if a[i]-1 < s:
            dp[i][a[i]-1] += pow(2,i,mod)
            dp[i][a[i]-1] %= mod

    for i in range(n):
        for j in range(s):
            if i != n-1:
                dp[i+1][j] += dp[i][j] * 2
                dp[i+1][j] %= mod
            if i != n-1 and j + a[i+1] < s:
                dp[i+1][j+a[i+1]] += dp[i][j]
                dp[i+1][j+a[i+1]] %= mod

    print(dp[-1][-1]%mod)

if __name__ == '__main__':
    main()


Measured memory_bytes: 132460
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int smap[510][510];

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

	int N, M, Q;
	cin >> N >> M >> Q;

	int L, R;
	rep(i, 0, M)
	{
		cin >> L >> R;
		smap[L][R]++;
	}

	rep(i, 0, N+1)rep(j, 0, N)
	{
		smap[i][j + 1] += smap[i][j];
	}
	rep(i, 0, N+1)rep(j, 0, N)
	{
		smap[j + 1][i] += smap[j][i];
	}

	int p, q;
	rep(i, 0, Q)
	{
		cin >> p >> q;
		cout << smap[q][q] - smap[q][p - 1] - smap[p - 1][q] + smap[p - 1][p - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  int edge[3],n;
  double x;
  while(cin >>edge[0]>>edge[1]>>edge[2],edge[0]||edge[1]||edge[2]){
    cin >>n;
    sort(edge,edge+3);
    x = sqrt(edge[0]*edge[0]+edge[1]*edge[1]);
    while(n--){
      double a;
      cin >>a;
      if(a*2>x){cout <<"OK"<<endl;}
      else{cout <<"NA"<<endl;}
    }
  }
  return 0;
}

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

using namespace std;
int a[100005],b[100005],c[100005];
int dp[100005][3];
int main()
{
    int n,i;
    cin >> n;
    for(i = 1;i <= n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[1][1] = a[1];
    dp[1][2] = b[1];
    dp[1][3] = c[1];
    for(i = 2;i <= n;i++){
        dp[i][1] = max(dp[i-1][2] + a[i],dp[i-1][3] + a[i]);
        dp[i][2] = max(dp[i-1][1] + b[i],dp[i-1][3] + b[i]);
        dp[i][3] = max(dp[i-1][1] + c[i],dp[i-1][2] + c[i]);
    }
    cout << max(dp[n][1],max(dp[n][2],dp[n][3]));
    return 0;
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int H, W;
char S[20][20];
char C[20][20];
int rowperm[20];
bool row_used[20];

bool is_match(const string &s1, const string &s2){
    for(int i = 0; i < (int)s1.size(); i++){
        if(s1[i] != s2[(int)s1.size() - 1 - i]){
            return false;
        }
    }
    return true;
}

bool rec(int depth){
    if(depth == H / 2){
        // rowpermの順番に文字列をセット
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                C[i][j] = S[rowperm[i]][j];
            }
        }
        // colを決定する
        string ss[20];
        for(int j = 0; j < W; j++){
            for(int i = 0; i < H; i++){
                ss[j] += C[i][j];
            }
        }

        // 奇数の場合、どれか一つを除いて判定
        bool used[20] = {};
        for(int i = 0; i < W; i++){
            if(W % 2){
                if(!is_match(ss[i], ss[i])){
                    continue;
                }
                used[i] = true;
            }
            
            int cnt = 0;
            // ２つのペアを作っていく
            for(int j = 0; j < W; j++){
                if(used[j]) continue;
                used[j] = true;
                bool ok = false;
                for(int k = 0; k < W; k++){
                    if(used[k]) continue;
                    if(j == k) continue;
                    used[k] = true;
                    if(is_match(ss[j], ss[k])){
                        ok = true;
                        break;
                    }
                    used[k] = false;
                }
                if(!ok){
                    break;
                }
                else{
                    cnt++;
                }
            }
            
            if(cnt == W / 2) return true;

            if(W % 2 == 0) break;

            if(W % 2) used[i] = false;
        }
        return false;
    }
    else{
        int start = -1;
        // 使っていない一番左の要素は確定
        for(int i = 0; i < H; i++){
            if(row_used[i]) continue;
            start = i;
            break;
        }

        row_used[start] = true;
        rowperm[depth] = start;

        for(int i = start + 1; i < H; i++){
            if(row_used[i]) continue;
            rowperm[H - 1 - depth] = i;
            row_used[i] = true;
            if(rec(depth + 1))
                return true;
            row_used[i] = false;
        }
        row_used[start] = false;
    }
    return false;
}

bool solve(){
    // rowを決める
    if(H % 2){
        for(int i = 0; i < H; i++){
            row_used[i] = true;
            rowperm[H / 2] = i;
            if(rec(0)){
                return true;
            }
            row_used[i] = false;
        }
        return false;
    }
    else{
        return rec(0);
    }
}

int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++) cin >> S[i];
    if(solve()){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n; cin >> n;
	int ans = 0;
	for(int i=1;i*i<=n;i++){
		ans = i*i;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int N, K, i = 0, t = 1;
  cin >> N >> K;
  for (i; i < N; i++)
  {

    if (t >= K)
    {
      t += K;
    }
    else
    {
      t *= 2;
    }
  }

  cout << t << endl;
}

Measured memory_bytes: 256
N=int(input())
S=input()

#前計算
order=0
for c in S:
    if c=='E':
        order+=1

#計算
ans = N
for i in range(N):
    #before
    if S[i]=='E':
        order-=1
    #calc
    ans=min(ans,order)
    #after
    if S[i]=='W':
        order+=1
print(ans)


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint comb(lint n, lint m) {
    return perm(n) / (perm(n - m) * perm(m));
}

// 定数 //
#define pi acos(-1)
// End of Template //



int main() {

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

    lint N, M;
    cin >> N >> M;

    cou(N * (N - 1) / 2 + M * (M - 1) / 2);

}


Measured memory_bytes: 256
/**
	???南?不好,却道,此心安?是吾?。
**/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <queue>
//#include <tr1/unordered_set>
#include <tr1/unordered_map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define inf 1e9
#define debug(a) cout << #a" = " << (a) << endl;
#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }
#define clr(x, y) memset(x, y, sizeof x)
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) \
	for(i=a;a<b?i<=b:i>=b;a<b?i++:i--)

const int maxn = 300+20;

char s[maxn][maxn],a[maxn];
int len[maxn],p[maxn],n;
int dp[200*10+30];

int solve(int M)
{
	for(int i=0;i<=M;i++)
		dp[i] = inf;
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=0;j+p[i]<=M;j++)
			dp[j+p[i]] = min(dp[j+p[i]],dp[j]+len[i]);
	return dp[M];
}

int va[maxn];

int main(){
//	freopen("input.txt","r",stdin);
	int CASE=0;
	while(~scanf("%d",&n))
	{
		if(!n) break;
        clr(va,-1);
        for(int i=0;i<n;i++)
		{
			scanf("%s%d",s[i],&p[i]);
			len[i] = strlen(s[i]);
		}
		scanf("%s",a);
        va[0] = 0;
        for(int i=0;a[i];i++) if(va[i]!=-1)
		{
            for(int j=0;j<n;j++)
			{
				int is=1;
				for(int k=0;k<len[j];k++)
					if( a[i+k] != s[j][k] )
					{
						is=0;
						break;
					}
				if(is) va[i+len[j]] = max(va[i+len[j]],va[i]+p[j]);
			}
		}
		int M = va[strlen(a)];
//		debug(M);
        int ans = solve(M);
        printf("Case %d: %d\n",++CASE,ans);
	}
	return 0;
}

Measured memory_bytes: 1240
import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n, x, t = inm()
print(math.ceil(n / x) * t)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a); i >= (b); --i)
#define sz(a) int((a).size())
#define pconent(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
const ll MOD =  1e9+7;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(v) (cout<<#v<<" = "<<v<<endl)
#define endln (cout<<endl)
template <class T> inline void dbv(T a) {  for(auto x : a){ cout<<x<<", " ;} cout<<endl;}
void output(ll tx)
{
    ld n,m,d;
    cin>>n>>m>>d;
    ld ans;
    if(d==0)
    {
        ans = (m-1)*(((n-d))/(n*n));
    }
    else
    {
        ans = (m-1)*((2*(n-d))/(n*n));
    }
    cout << setprecision(15) << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t =1;
    // cin>>t;
    FOR(i,0,t)
    {
        output(i+1) ;
    }
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;
using u64 = std::uint_fast64_t;

void solve(void){

  llint x, k, d;
  std::cin >> x >> k >> d;

  x = std::max(x, -x);
  llint tmp = x/d;
  
  if(tmp >= k){
    std::cout << x - k*d << std::endl;
    return;
  }

  k -= tmp;
  x -= tmp*d;

  if(k%2==0) std::cout << x << std::endl;
  else       std::cout << std::abs(x-d) << std::endl;
  
  return;
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3620
N, Y=map(int,input().split())
flag=False

for i in range(0,N+1):
    for j in range(0, N+1):
        if Y==10000*(N-i-j)+5000*i+1000*j and i+j<=N:
            flag=True
            print(N-i-j, i, j)
            break
    if flag:
        break
else:
    print('-1 -1 -1')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

bool f(double a, double b, double ans){
    if(abs((ans - a) - (b - ans)) < EPS && ans - a < 90)return true;
    return false;
}

signed main(void) {
    int a,b;
    cin >> a >> b;
    if(b < a)swap(a,b);
    int c = b - 360;
    int d = a + 360;
    for(double ans = 0; ans < 360; ans += 0.5){
        if(f(a,b,ans) || f(c,a,ans) || f(b,d,ans)){
            cout << shosu(10) << ans << endl;
            return 0;
        }

    }
}



Measured memory_bytes: 3284
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

void dfs(string str,char mx,int N){
	if(str.length()==N){
		out(str);
		return;
	}

	for(char ch='a';ch<=mx;ch++){
		dfs(str+ch,ch==mx?(char)(mx+1):mx,N);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	dfs("",'a',N);
	//out(N);
	return 0;
}


Measured memory_bytes: 1536
n = int(input())

a = list(map(int, input().split()))

a.sort()

#print(a)

l = len(a)
s = sum(a)

#print(s)

target = 0
ans = 0

#if s % 2 == 1:
 #   target = int(s / n) + 1

#else:
 #   target = int(s / n)

#print(target)

target = round(s / n)
    
    
for i in range(l):
    ans = ans + (target - a[i]) * (target - a[i])

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static void B_task();

#if 1
int main()
{
	B_task();
	fflush(stdout);
	return 0;
}
#endif

static void B_task()
{
	int K, X;
	get2int(K, X);

	int min = tp_max(X - K + 1, -1000000);
	int max = tp_min(X + K - 1, 1000000);

	for (int i = min; i <= max; i++) {
		printf("%d ", i);
	}
//	printf("%d\n", max);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int main(){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    std::sort(a,a+3);
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <bitset>
using namespace std;

class UnionFindTree{
	typedef struct {
		int parent;
		int rank;
	}base_node;
	
	vector<base_node> node;
public:
	UnionFindTree(int n){
		node.resize(n);
		for(int i=0; i<n; i++){
			node[i].parent=i;
			node[i].rank=0;
		}
	}

	int find(int x){
		if(node[x].parent == x) return x;
		else{
			return node[x].parent = find(node[x].parent);
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}

	void unite(int x, int y){
		x = find(node[x].parent);
		y = find(node[y].parent);
		if(x==y) return;
		if(node[x].rank < node[y].rank){
			node[x].parent = y;
		}else if(node[x].rank > node[y].rank){
			node[y].parent = x;
		}else{
			node[x].rank++;
			unite(x,y);
		}
	}
};

int main_(){
	int n,m,p;
	cin >> n >> m >> p;

	UnionFindTree uft(n);

	vector<int> u(m),v(m);
	vector<int> e(m);
	vector<vector<int>> g(n);
	//vector<int> g(n);
	for(int i=0; i<m; i++){
		cin >> u[i] >> v[i];
		u[i]--; v[i]--;
		//g[u[i]] |= 1<<v[i];
		//g[v[i]] |= 1<<u[i];
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
		//e[i] = (1<<u[i]) | (1<<v[i]);
		uft.unite(u[i], v[i]);
	}
	bool connected = true;
	for(int i=1; i<n; i++){
		connected = connected && uft.same(0,i);
	}
	if(connected == false){
		printf("0.000000000000000000\n");
		return 0;
	}

	vector<int> edge_cnt(1<<n, 0);
	for(int i=0; i<(1<<n); i++){
		for(int j=0; j<m; j++){
			if((i>>u[j])&(i>>v[j])&1){
				edge_cnt[i]++;
			}
		}
	}

	vector<double> prob(1<<n, -1);
	prob[1] = 1;

	function<double(int)> dfs = [&](int s){
		if(prob[s] != -1) return prob[s];
		double res = 1.0;
		int s_ = s-1;
		for(int x=s_; x>=0; x=(x-1)&s_){
			int y = x|1;
			if(y==s) continue;
			double q = dfs(y);
			double tmp = 1.0;
			/*
			for(int i=0; i<m; i++){
				if( (((1<<u[i])&y) && ((1<<v[i])&(s^y))) or (((1<<v[i])&y) and ((1<<u[i])&(s^y))) ){
					tmp *= 0.01 * p;
				}
			}
			*/
			
			tmp = pow(0.01*p, edge_cnt[s] - edge_cnt[y] - edge_cnt[s^y]);

			res -= q * tmp;

			if(x==0) break;
		}
		return prob[s] = res;
	};

	double ans = dfs((1<<n)-1);
	printf("%.18f\n", ans);
	return 0;
}


int main(){
	auto start = clock();
	main_();
	//cerr << clock()-start << endl;
	return 0;
}

Measured memory_bytes: 3476
N = int(input())
A = list(map(lambda x: int(x), input().split(' ')))

import fractions

# def gcd(x, y):
#     while y != 0:
#         x, y = y, x % y
#     return x
#
# def lcm(x, y):
#     return (x * y) // gcd(x, y)
#
# ans = 1
# for a in A:
#     ans = lcm(ans, a)

ans = sum(A) - len(A)

print(ans)

Measured memory_bytes: 64620
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
#define INF 1e+14

int main() {
    int N;
    cin >> N;
    int M;
    cin >> M;
    priority_queue<int> que;
    REP(i,N) {
        int a; cin >> a;
        que.push(a);
    }
    ll ans = 0;
    while (!que.empty())
    {
        int v = que.top();
        que.pop();
        if(M == 0) {
            //cout << v << endl;
            ans += v;
        }
        else {
            v /= 2;
            M--;
            que.push(v);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
#!/usr/bin/env python3


def kyu(x):
    if x <= 599:
        return 8
    elif x <= 799:
        return 7
    elif x <= 999:
        return 6
    elif x <= 1199:
        return 5
    elif x <= 1399:
        return 4
    elif x <= 1599:
        return 3
    elif x <= 1799:
        return 2
    else:
        return 1


def main():
    x = int(input())
    k = kyu(x)
    print(k)


if __name__ == '__main__':
    main()

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

#define MAX_N 100000
#define MAX_Q 100000

struct SegmentTree {
  vector< array<int, 10> > data, lazy;
  array<int, 10> ini{{0,1,2,3,4,5,6,7,8,9}};
  int sz;
  SegmentTree(){}
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz <<= 1;
    data.resize(2*sz-1, array<int, 10>{0});
    lazy.resize(2*sz-1, ini);
    rep(i, n) data[i+sz-1][0] = 1;
    for(int k = sz-2; k >= 0; k--)
      data[k][0] = data[2*k+1][0] + data[2*k+2][0];
  }
  void push(int k, int l, int r) {
    int tmp[10];
    rep(i, 10) tmp[i] = data[k][i], data[k][i] = 0;
    rep(i, 10) data[k][lazy[k][i]] += tmp[i];
    if(r - l > 1) {
      array<int, 10> conv = ini;
      rep(i, 10) conv[i] = lazy[k][i];
      rep(i, 10) {
	lazy[2*k+1][i] = conv[lazy[2*k+1][i]];
	lazy[2*k+2][i] = conv[lazy[2*k+2][i]];
      }
    }
    lazy[k] = ini;
  }
  void update(int a, int b, int x, int y, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      rep(i, 10) if(lazy[k][i] == x) lazy[k][i] = y;
      push(k, l, r);
      return;
    }
    update(a, b, x, y, 2*k+1, l, (l+r)/2);
    update(a, b, x, y, 2*k+2, (l+r)/2, r);
    rep(i, 10) data[k][i] = data[2*k+1][i] + data[2*k+2][i];
  }
  void update(int a, int b, int x, int y) {
    update(a, b, x, y, 0, 0, sz);
  }
  int query(int a, int b, int x, int y, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) {
      int res = 0;
      for(int i = x; i <= y; i++) res += data[k][i];
      return  res;
    }
    int vl = query(a, b, x, y, 2*k+1, l, (l+r)/2);
    int vr = query(a, b, x, y, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }
  int query(int a, int b, int x, int y) {
    return query(a, b, x, y, 0, 0, sz);
  }
};

int n, q;
vector<int> graph[MAX_N];
int li[MAX_N], ri[MAX_N], idx;

SegmentTree seg;

void dfs(int u) {
  li[u] = idx++;
  for(int v : graph[u]) dfs(v);
  ri[u] = idx;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n >> q;
  rep(i, n-1) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
  }
  memset(li, -1, sizeof(li));
  memset(ri, -1, sizeof(ri));
  idx = 0;
  dfs(0);

  seg = SegmentTree(n);
  rep(i, q) {
    int t, r, x, y;
    cin >> t >> r >> x >> y;
    if(t == 1) cout << seg.query(li[r], ri[r], x, y) << endl;
    else seg.update(li[r], ri[r], x, y);
  }

  return 0;
}



Measured memory_bytes: 53924
def next_char(i):
    if i % 2 == 0:
        yield "#"
    while True:
        yield "."
        yield "#"


while True:
    h, w = [int(i) for i in input().split()]
    if h == w == 0:
        break
    for i in range(h):
        c = next_char(i)
        output = []
        for j in range(w):
            output.append(next(c))
        print("".join(output))
        next(c)
    print()



Measured memory_bytes: 5616
#include <stdio.h>

char s[102][102];
int t[101][101];
int h, w;

void dfs(char flag, int i, int j, int cost) {
  t[i][j] = cost;
  if (i < h && j + 1 < w) {
    if (s[i][j+1] == flag) {
      if (cost < t[i][j+1]) {
        dfs(flag, i, j+1, cost);
      }
    } else {
      if (cost + 1 < t[i][j+1]) {
        dfs(s[i][j+1], i, j+1, cost + 1);
      }
    }
  }
  if (i + 1 < h && j < w) {
    if (s[i+1][j] == flag) {
      if (cost < t[i+1][j]) {
        dfs(flag, i+1, j, cost);
      }
    } else {
      if (cost + 1 < t[i+1][j]) {
        dfs(s[i+1][j], i+1, j, cost+1);
      }
    }
  }
}
int main() {
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < w; j++) {
      t[i][j] = 1000000;
    }
  }

  dfs(s[0][0], 0, 0, s[0][0] == '#' ? 1 : 0);

/*
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      printf("%d ", t[i][j]);
    }
    printf("\n");
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      printf("%c", s[i][j]);
    }
    printf("\n");
  }
  */
  printf("%d", (t[h-1][w-1] + 1) / 2);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, k, n, m, x, y;
  char s[100][120];
  for(i = 0; i < 50; ++i) {
    for(j = 0; j < 100; ++j) s[i][j] = '#';
    s[i][100] = 0;
  }
  for(i = 50; i < 100; ++i) {
    for(j = 0; j < 100; ++j) s[i][j] = '.';
    s[i][100] = 0;
  }
  scanf("%d%d", &n, &m);
  n--, m--;
  for(i = 0; i < n; ++i) {
    y = i / 50 * 2;
    x = i % 50 * 2;
    s[y][x] = '.';
  }
  for(i = 0; i < m; ++i) {
    y = i / 50 * 2 + 51;
    x = i % 50 * 2;
    s[y][x] = '#';
  }
  printf("100 100\n");
  for(i = 0; i < 100; ++i) printf("%s\n", s[i]);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n  = sc.nextInt();
        int[] array = new int[n];
        int temp = 0;
        int tempCount = 0;
        for(int i=0;i<n;i++){
            array[i] = sc.nextInt();
        }
        for(int i=1;i<=n-1;i++){
            for(int j=n-1;j>=i;j--){
                if(array[j] < array[j-1]){
                    tempCount++;
                    temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;
                }
             }
        }
        for(int i=0;i<n;i++){
            System.out.print(array[i]);
            if(i<n-1){
                System.out.print(" ");
            }
        }
        System.out.println("");
        System.out.println(tempCount);
        sc.close();
    }
}


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

def equal(x,y):
    s = 0
    for i in range(len(x)):
        if x[i]==y[i]:
            s += 1
    return s

m = len(T)

for i in range(len(S)-len(T)+1):
    m = min(m, len(T) - equal(T,S[i:i+len(T)]))

print(m)  

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

int main(){
    ll x , k , d ;
    cin >> x >> k >> d ;
    map<ll,ll> where ;
    x = abs(x) ;
    if( x/d <= k ){
        k -= x / d ;
        if( k%2 == 1 ){
            cout << min( abs(x%d - d) ,  abs(x%d + d ) ) << endl ;
        }
        else cout << abs(x%d) << endl ;
    } 
    else{
        x = abs(x) - k*d ;
        cout << x << endl ;
        return 0 ;
    }
}






Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n, m;
    cin >> n >> m;
    pair<ll, ll> a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i].second >> a[i].first;
    }

    sort(a, a + n, greater<>());
    set<int> just;
    for (int i = 1; i <= n; i++) {
        just.insert(i);
    }

    ll ans = 0;

    for (auto e : a) {
        int maxi = m - e.second + 1;
        auto it = just.upper_bound(maxi);
        if (it != just.begin()) {
            it--;
            just.erase(it);
            ans += e.first;
        }
    }

    cout << ans;



}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long

int sum[86401];

signed main()
{
    int n;
    while(cin>>n, n) {
        memset(sum, 0, sizeof(sum));
        signed h, m, s, h1, m1, s1;
        for(int i=0; i<n; ++i) {
            scanf("%d:%d:%d%d:%d:%d", &h, &m, &s, &h1, &m1, &s1);
            sum[h*3600+m*60+s]++;
            sum[h1*3600+m1*60+s1]--;
        }

        int Max = 0;
        for(int i=0; i<86401; ++i) {
            if(i>0) sum[i] += sum[i-1];
            Max = max(Max, sum[i]);
        }
        cout << Max << endl;
    }
    return 0;
}

Measured memory_bytes: 3808
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <numeric>
#include <utility>
#include <queue>
#include <memory>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <iterator>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/
// #define ONLINE_JUDGE
int d[55];
int main()
{/*
	#ifdef ONLINE_JUDGE
    	freopen("aplusb.in", "r", stdin);
    	freopen("aplusb.out", "w", stdout);
	#endif*/
	int n, m, x, y;
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
			d[x]++;
			d[y]++;
	}
	for (int i = 1; i <= n; i++) {
		printf("%d\n", d[i]);
	}
}


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

int solve(int x, int med1, int med2) {
  if (x <= med1) {
    return med2;
  } else {
    return med1;
  }
}

int main() {
  int i, n, med1, med2;
  cin >> n;
  vector<int> x(n), x2(n);
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }

  x2 = x;
  sort(x2.begin(), x2.end());
  med1 = x2[n / 2 - 1];
  med2 = x2[n / 2];

  for (i = 0; i < n; i++) {
    cout << solve(x[i], med1, med2) << "\n";
  }

  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

bool comb(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, k;
	cin >> n >> k;

	//最大でn-1C2
	int ma = (n - 1) * (n - 2) / 2;
	if (ma < k) out(-1);
	else {
		//nを中心とするスターグラフ
		vector<P> res;
		for (int i = 1; i <= n - 1; i++) {
			res.push_back(P(i, n));
		}

		//ペアを潰すための辺を入れる
		ll rem = ma - k;
		ll ci = 1, cj = 2;
		for (int j = 0; j < rem; j++) {
			res.push_back(P(ci, cj));

			cj++;
			//nに到達したら始点を変える
			if (cj == n) {
				ci++;
				cj = ci + 1;
			}
		}

		out(sz(res));
		for (auto p : res) {
			cout << p.first << " " << p.second << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 924844033
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

int N, K;
int dp[4001][2001][2];
bool used[2000][2];
int fact[2001];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  fact[0] = 1;
  for (int i=1; i<=2000; i++) fact[i] = (1LL*i*fact[i-1]) % MOD;
  cin >> N >> K;
  dp[0][0][0] = 1;
  int x = N, y = 0;
  rep(i, 2*N) {
    bool cont = true;
    used[x][y] = true;
    x += K;
    y ^= 1;
    if (x >= N) {
      cont = false;
      rep(a, N) rep(b, 2) if (x >= N && !used[a][b]) x = a, y = b;
    }
    rep(j, N+1) {
      if (cont && j+1 <= N) add(dp[i+1][j+1][1], dp[i][j][0]);
      add(dp[i+1][j][0], dp[i][j][0]);
      add(dp[i+1][j][0], dp[i][j][1]);
    }
  }
  int s = 0;
  rep(sz, N+1) {
    int e = (1LL*fact[N-sz]*(dp[2*N][sz][0]+dp[2*N][sz][1])) % MOD;
    if (sz%2) e = MOD-e;
    add(s, e);
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 62848
#include<iostream>
using namespace std;
int main(){
	int i;
	long long n,a[200005],ans=0,x,sum;
	cin>>n>>x;
	for(i=1;i<=n;i++)
		cin>>a[i];
	if(a[1]>x){
		sum=a[1]-x;
		ans+=sum;
		a[1]-=sum;
	}
	for(i=1;i<=n;i++){
		if(i!=n&&a[i]+a[i+1]>x){
			sum=a[i]+a[i+1]-x;
			ans+=sum;
			a[i+1]-=sum;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n,k);
    if(k==0){
        out((ll)n*n);
        return 0;
    }
    ll ans=0;
    ll a=n-k;
    ans+=a*(a+1)/2;
    ll modr,l,r;
    for(int i=k+1;i+k<=n;i++){
        //i+1からnまでにiの余剰がk以上となるものが何個あるか
        l=(i+1)/i;
        r=n/i;
        modr=n%i;
        if(r>l){
            ans+=(r-l)*(i-k);
        }
        ans+=max(modr-k+1,(ll)0);
    }
    out(ans);
}

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

int main(){
	int n;
	cin>>n;
	int xorall=0;
	vector<int> arr(n,0);
	for(int i=0;i<n;i++){
		cin>>arr[i];
		xorall=xorall^arr[i];
	}

	for(int i=0;i<n;i++){
		arr[i]=xorall^arr[i];
	}

	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI (acos(-1))
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N, M;
VI g[60];


void dfs(int v, PII rv, vector<bool>& u){
	u[v] = true;
	rep(i, 0, SIZE(g[v]))
		if(!u[g[v][i]] && mp(v, g[v][i]) != rv) dfs(g[v][i], rv, u);
}


int solve(){
	int ans = 0;
	rep(i, 0, N){
		rep(j, 0, SIZE(g[i])){
			vector<bool> u(N, false);
			dfs(0, mp(i, g[i][j]), u);
			if(any_of(ALL(u), [](bool u){ return !u; })) ans++;
		}
	}
	return ans;
}


signed main(){
	cin >> N >> M;
	rep(i, 0, M){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].pb(b);
		g[b].pb(a);
	}

	cout << solve() << endl;

	return 0;
}

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

int main(void){
  int number;
  cin >> number;
  vector<int> heights(number);
  for(int i = 0; i < number; ++i) cin >> heights[i];

  int ans = 0;
  for(int i = 0; i < number; i++){
    bool visible = true;
    for(int j = i -1; j >= 0; j--){
      if(heights[i] < heights[j]){
        visible = false;
        break;
      }
    }
    if(visible) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256