akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int N;
  int H;
  int x;  
  cin>>N>>H;
  int a[100010],b[100010];
  for(int i=0;i<N;i++)
     cin>>a[i]>>b[i];
  sort(a,a+N);
  x=a[N-1]; 
  sort(b,b+N); 
  int ans=0;
  for(int j=N;j>=0;j--)
  {
     if(x<b[j] and H>0)
     { H=H-b[j];
       ans++;}
  }
  if(H>0)
  ans+=(H+x-1)/x;
  //cout<<H<<(H+x-1)/x;
  cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 1024
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
//DEBUG 
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define all(v) (v).begin(), (v).end()
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 2e5+5, MOD = 998244353;
int t,n,m,k,x,y;


inline void add(int& x, int y)
{
	x += y;
	if (x >= MOD) x -= MOD;
}

inline void sub(int& x, int y)
{
	x -= y;
	if (x < 0) x += MOD;
}

inline int mult(int x, int y)
{
	return x * (long long) y % MOD;
}

int fact[LIM];

ll modpow(int n,int p){
    if(p==0) return 1;
    if(p%2) return (modpow(n,p-1)*1LL*n)%MOD;
    else{
        ll half=modpow(n,p/2);
        return (half*1LL*half)%MOD;
    }
}

ll modinv(int d){
    return modpow(d,MOD-2);
}

int choose(int y,int x){
    int ret=fact[y];
    ret=mult(ret,modinv(fact[x]));
    return mult(ret,modinv(fact[y-x]));
}

int gogo(int i){
    //m * (m-1)^(n-1-i) * 1^i * (n-1)Ci
    int ret=1;
    ret=mult(m,modpow(m-1,n-1-i));
    return mult(ret,choose(n-1,i));
}

int32_t main()
{
    IOS;
    fact[0]=1;
    forsn(i,1,LIM) fact[i]=mult(fact[i-1],i);
    cin>>n>>m>>k;
    int ans=0;
    forn(i,k+1){
        add(ans,gogo(i));
    }
    cout<<ans<<ln;
}


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

namespace AOJ.Volume1
{
    public class GoldbachConjecture2
    {
        public static int Main()
        {
            // 1000000??\???????´???°????±???????
            var prime = new bool[1000001];
            for(int i = 0; i <= 1000000; i++) { prime[i] = true; }
            prime[0] = false;
            prime[1] = false;
            for(int i = 2; i <= 1000000; i++)
            {
                if (prime[i])
                {
                    int cnt = 2;
                    while (i * cnt <= 1000000)
                    {
                        prime[i * cnt] = false;
                        cnt++;
                    }
                }
            }

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }
                // ????????????????????°????±???????
                int answer = 0;
                for (int i = 2; i <= n / 2; i++)
                {
                    if (!prime[i]) { continue; }
                    if (prime[n - i]) { answer++; }
                }

                Console.WriteLine(answer);
            }

            return 0;
        }
    }
}

Measured memory_bytes: 10116
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int A,B;
  cin >> A >> B;
cout << (A + B) % 24 << endl;
  
    return 0;
}


Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A,B=[],[]
for _ in range(n):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()
if n%2==1:
  l=A[n//2]
  r=B[n//2]
  print(r-l+1)
else:
  l=A[n//2-1]+A[n//2]
  r=B[n//2-1]+B[n//2]
  print(r-l+1)


Measured memory_bytes: 92088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 1000000007
#define MOD 1000000007
#define SEP " "

int		main(void)
{
	int n;
	cin >> n;
	vector<int> a(n+1);
	for (int i = 0; i < n+1; i++)
		cin >> a[i];
	vector<int> b(n);
	for (int i = 0; i < n; i++)
		cin >> b[i];
	ll sum = 0;
	sum += min(b[0], a[0]);
	b[0] -= min(b[0], a[0]);
	for (int i = 1; i < n + 1; i++)
	{
		sum += min(b[i-1], a[i]);
		a[i] -= min(b[i-1], a[i]);
		if (i == n)
			break ;
		sum += min(b[i], a[i]);
		b[i] -= min(b[i], a[i]);
	}
	cout << sum << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<string> w(n);
	bool out = false;

	for (int i = 0; i < n; i++) {
		cin >> w[i];
		for (int j = 0; j < i; j++) {
			if (w[i] == w[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (i > 0) {
			if (w[i - 1].substr(w[i - 1].length() - 1, 1) != w[i].substr(0, 1)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<long long> x(n);
  vector<long long> y(m);
  for(int i=0; i<n; i++) cin >> x.at(i);
  for(int i=0; i<m; i++) cin >> y.at(i);
  long long Xsum=0;
  long long Ysum=0;
  for(int i=0; i<n; i++){
      Xsum=(Xsum+x.at(i)*(i-(n-1-i)))%1000000007;
  }
  for(int i=0; i<m; i++){
      Ysum=(Ysum+y.at(i)*(i-(m-1-i)))%1000000007;
  }
  long long ans;
  ans=Xsum*Ysum%1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in).useDelimiter("[,\\n]");
		
		double x = 0;
		double y = 0;
		double angle = 90;
		
		while(true)
		{
			double r = sc.nextDouble();
			double t = sc.nextDouble();
			
			if (r == 0 && t == 0) break;
			
			x += r * Math.cos(Math.toRadians(angle));
			y += r * Math.sin(Math.toRadians(angle));
			angle -= t;
		}
		System.out.println(Integer.toString((int)x));
		System.out.println(Integer.toString((int)y));
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int maxx = 100010;
const int INF = 1 << 30;

class DisjointSet {
public:
    // rank璁板綍鏍戠殑楂樺害
    vector<int> rank, p;
    DisjointSet() {};
    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++)
            makeSet(i);
    }
    void makeSet(int i) {
        p[i] = i;
        rank[i] = 0;
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y) {
        // 鍖呭惈x鐨勬爲鐨勯珮搴︽洿楂橈紝鍒欏皢y鐨勬爲鍚堝苟鍒皒涓?
        if (rank[x] > rank[y])
            p[y] = x;
        else {
            p[x] = y;
            if (rank[x] == rank[y])
                rank[y]++;
        }
    }
    int findSet(int x) {
        if (x != p[x])
            p[x] = findSet(p[x]);
        return p[x];
    }
};

class Edge {
public:
    int source, target, cost;
    Edge(int source = 0, int target = 0, int cost = 0) :
        source(source), target(target), cost(cost) {}
    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};


int kruskal(int n, vector<Edge> edges) {
    int totalCost = 0;
    sort(edges.begin(), edges.end());

    DisjointSet dset = DisjointSet(n + 1);
    for (int i = 0; i < n; i++)
        dset.makeSet(i);

    int len = edges.size();
    for (int i = 0; i < len; i++) {
        Edge e = edges[i];
        // 鍒ゆ柇鏄惁浼氭垚鐜?
        if (!dset.same(e.source, e.target)) {
            // 娣诲姞鏈€灏忕敓鎴愭爲鐨勮竟
            //MST.push_back(e);
            totalCost += e.cost;
            dset.unite(e.source, e.target);
        }
    }
    return totalCost;
}
int main() {

    int n, m, cost;
    int source, target;
    scanf("%d %d", &n, &m);
    vector<Edge> edges;
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &source, &target, &cost);
        edges.push_back(Edge(source, target, cost));
    }
    printf("%d\n", kruskal(n, edges));
    return 0;
}


Measured memory_bytes: 5172
#include<stdio.h>

  void  show(int A[],int N){
    for (int i = 0; i < N; i++) {
      printf("%d",A[i] );
      if(i!=N-1)printf(" ");
    }
    printf("\n");
  }

  int insert(int A[],int N){
    int minj;
    int sw=0;
    int i,j;
    int s;
    for (i = 0; i < N-1; i++) {
      minj=i;
      for (j = i; j < N; j++) {
        if(A[minj]>A[j]) minj=j;
      }
      s=A[i];A[i]=A[minj];A[minj]=s;
      if(minj!=i)sw++;
    }
    show(A,N);
    return sw;
  }

  int main(){
    int A[100];
    int N;
    scanf("%d\n",&N );
    for (int i = 0; i < N; i++) {
      scanf("%d",&A[i] );
    }
    printf("%d\n",insert(A,N) );
    return 0;
  }


Measured memory_bytes: 2104
# F - LIS on Tree

from bisect import bisect_left

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n
adj = {u: [] for u in range(n)}
for i in range(n - 1):
    u, v = map(int, input().split())
    adj[u - 1].append(v - 1)
    adj[v - 1].append(u - 1)

# lis[i] == 長さi+1の増加列の末尾の最小値
lis = [float('inf')] * n

lislen = [0] * n  # lislen[u] == 頂点uまでのLISの長さ
backup = [None] * n

# DFS (with an explicit stack)
stack = [(0, 0)]  # (parent, child)
while len(stack) > 0:
    p, u = stack.pop()
    if p == None:  # 帰りがけ
        l, x = backup[u]
        lis[l] = x  # 復元
    else:  # 行きがけ
        l = bisect_left(lis, a[u])  # a[u]を使って長さl+1のLISを作れる
        backup[u] = (l, lis[l])  # 後で復元するために保存
        lis[l] = a[u]  # 更新
        lislen[u] = bisect_left(lis, float('inf'))  # 現時点のLISの長さ
        stack.append((None, u))  # 帰りがけタスクをpush
        for v in adj[u]:
            if v != p:
                stack.append((u, v))

for u in range(n):
    print(lislen[u])


Measured memory_bytes: 103056
//
// Created by MengHaitao on 2019/11/27 0027.
//
//insert sort
#include <iostream>
using namespace std;
int a,b;
int gcd(int x,int y)
{
    if(y==0) return x;
    return gcd(y,x%y);
}
void solve()
{
    cin>>a>>b;
    cout<<gcd(a,b)<<endl;
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define MAXN 100233
using namespace std;
string s;
int R[MAXN],L[MAXN];
int ans[MAXN]={};
int main()
{
	cin>>s;
	int len=s.size();
	for (int i=0;i<len;i++)
	{
		if (s[i]=='R') R[i]=i;
		else R[i]=R[i-1];
	}
	for (int i=len-1;i>=0;i--)
	{
		if (s[i]=='L') L[i]=i;
		else L[i]=L[i+1];
	}
	for (int i=1;i<len;i++)
	{
		if (s[i]=='R') continue;
		if ((i-R[i])&1)
		{
			ans[R[i]+1]++;
		}
		else ans[R[i]]++;
	}
	for (int i=len-2;i>=0;i--)
	{
		if (s[i]=='L') continue;
		if ((L[i]-i)&1)
		{
			ans[L[i]-1]++;
		}
		else ans[L[i]]++;
	}
	for (int i=0;i<len;i++)
	{
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
s = input()
t = input()

n = N
while 0 <= n:
    a = s[-(n+1):]
    b = t[0:n+1]
    if a == b:
        print(len(s+t[n+1:]))
        exit()
    n -= 1

print(len(s+t))
exit()

Measured memory_bytes: 3060
n = int(input())
alst = [int(i) for i in input().split()]
blst = [int(i) for i in input().split()] + [0]
n_monster = 0
next_capa = 0
for a, b in zip(alst, blst):
	n_monster += min(a, b + next_capa)
	next_capa = max(b - max(a - next_capa, 0), 0)
print (n_monster)

Measured memory_bytes: 19648
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D[200010];
    map<int, int> mp;
    rep(i, N) {
        cin >> D[i];
        mp[D[i]]++;
    }

    int M; cin >> M;
    int T[200010];
    rep(i, M) {
        cin >> T[i]; 
        mp[T[i]]--;
        if(mp[T[i]] < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


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

N, M = map(int, input().split())
count = 0

min_a = 1
max_b = N

for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b

print(max(0, max_b-min_a+1))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)


//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
/////////////////////////



//Answer


int main() {

int L,R,d;
cin>>L>>R>>d;
int A,B;
if(L%d==0){
  A=L;
}else{
  A=L+d-L%d;
}
if(R%d==0){
  B=R;
}else{
B=R-R%d;
}
cout<<((B-A)/d)+1<<endl;


}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int H,N;
    Scd2(H,N);

    vi a(N);
    vi b(N);
    Rep(i,N){
        Scd2(a[i],b[i]);
    }

    int dp[15004] = {};
    int dpe[15002] = {};
    Rep(i,15002){
        dp[i] = INF;
    }
    dp[0] = 0;

    Rep(ni,N){
        Rep(hi,H){
            int hhi = min( (ll)H, hi+a[ni] );
            dp[hhi] = min( dp[hhi], dp[hi] + b[ni] );
        }
    }

    printf ("%d\n", dp[H] );


    return 0;
}



Measured memory_bytes: 256
# C - Tax Increase
# https://atcoder.jp/contests/abc158/tasks/abc158_c

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

for x in range(1, 100000):
  if int(x * 0.08) == a and int(x * 0.1) == b:
    print(x)
    exit()

print(-1)

Measured memory_bytes: 3064
#include<algorithm>
#include<cstdio>
#define s(A) std::sort(A,A+10);
main(){
int Z[20],p;
for(int i=0;i<20;)
scanf("%d",&p),Z[i++]=p;
s(Z);
s(Z+10);
printf("%d %d\n",Z[7]+Z[8]+Z[9],Z[17]+Z[18]+Z[19]);
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int x = Integer.parseInt(scan.next());
        int[] l = new int[n];
        int sum = 0;
        int bNum = 1;
        for(int i = 0; i < l.length; i++){
            l[i] = Integer.parseInt(scan.next());
        }
        for(int i : l){
            if(sum + i > x){
                break;
            }
            sum += i;
            bNum++;
        }
        System.out.println(bNum);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> //std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> // std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N; std::cin >> N;
  std::vector<int> v(N); for(int i=0; i<N; i++) std::cin >> v[i];

  std::sort(v.begin(), v.end());
  double ans = v[0];
  for(int i=0; i<N; i++){
    ans = (ans+(double)v[i])/2.;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    for (int i = 0; i < 26; i++)
        cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    for (int i = 0; i < d; i++)
        for (int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> t(d);
    for (int i = 0; i < d; i++)
        cin >> t[i];
    
    int score = 0;
    vector<int> last(26, 0);
    for (int i = 1; i <= d; i++) {
        score += s[i-1][t[i-1]-1];
        last[t[i-1]-1] = i;
        for (int j = 0; j < 26; j++)
            score -= c[j] * (i - last[j]);
        cout << score << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3644
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n,k;
		cin >> n >> k;
		int a[n+5];
		rep(i,1,n)
			cin >> a[i];
		queue<int> q;
		rep(i,1,k)
		{
			q.push(a[i]);
		}
		rep(i,k+1,n)
		{
			int x = q.front();
			q.pop();
			if(x<a[i])
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
			q.push(a[i]);
		}
	}
}

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

#define ll long long

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

    int n;
    cin >> n;
    set <int> a;

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a.insert(x);
    }

    cout << a.size() << endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    string s=to_string(n);
    int sum=0;
    for(auto x:s){
        sum+=(x-'0');
    }
    if(n%sum)cout<<"No";
    else cout<<"Yes";




}

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

queue<int> xt,yt;
int x,y;
bool dpx[20000][8000];
bool dpy[20000][8000];

int main(){
    memset(dpx,false,sizeof(dpx));
    memset(dpy,false,sizeof(dpy));
    string s;
    cin >> s;
    cin >> x >> y;
    x+=10000;
    y+=10000;
    int t=0,p=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='F'){
            p++;
            if(i==s.length()-1){
                if(t%2==0) xt.push(p);
                else yt.push(p);
            }
        }
        else if(s[i]=='T'){
            if(t%2==0) xt.push(p);
            else yt.push(p);
            t++;
            p=0;
        }
    }
    int cx=xt.size();
    int cy=yt.size();
    int c=1;
    dpx[10000][0]=true;
    while(xt.size()!=0){
        int t=xt.front();
        xt.pop();
        if(c==1) dpx[10000+t][c]=true;
        else{
            for(int i=0;i<20000;i++){
                if(dpx[i][c-1]==true){
                    dpx[i+t][c]=true;
                    dpx[i-t][c]=true;
                }
            }
        }
        c++;
    }
    dpy[10000][0]=true;
    c=1;
    while(yt.size()!=0){
        int t=yt.front();
        yt.pop();
        for(int i=0;i<20000;i++){
            if(dpy[i][c-1]==true){
                dpy[i+t][c]=true;
                dpy[i-t][c]=true;
            }
        }
        c++;
    }
    if(dpx[x][cx]==true&&dpy[y][cy]==true) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 312832
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	ll N;
    cin >> N;
    VL A;
    rep(i,N){
        A.PB(0);
    }
    
    reps(i,N){
        if(i<N){
            ll a;
            cin >> a;
            A[a-1] += 1;
        } 
    }
    
    rep(i,N){
        cout << A[i] << endl;
    }
    return 0;
}


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

int main(){
    int N, M;
    cin >> N;
    M = 1e9+7;
    int dp[4][4][4][101];
    for(int j=0; j<4; j++) for(int k=0; k<4; k++) for(int l=0; l<4; l++){
        for(int i=0; i<=100; i++){
            if(i==3 && !((j==0 && k==1 && l==2)||(j==1 && k==0 && l==2)||(j==0 && k==2 && l==1))){
                dp[j][k][l][3] = 1;
            }else{
                dp[j][k][l][i] = 0;
            }
        }
    }

    for(int i=3; i<N; i++){
        for(int j=0; j<4; j++) for(int k=0; k<4; k++) for(int l=0; l<4; l++){
            if((j==0 && l==1) || (j==0 && k==1) || (k==0 && l==1) || (k==1 && l==0)){
                dp[k][l][0][i+1] = (dp[k][l][0][i+1] + dp[j][k][l][i])%M;
                dp[k][l][1][i+1] = (dp[k][l][1][i+1] + dp[j][k][l][i])%M;
                dp[k][l][3][i+1] = (dp[k][l][3][i+1] + dp[j][k][l][i])%M;
            }else if(k==0 && l==2){
                dp[k][l][0][i+1] = (dp[k][l][0][i+1] + dp[j][k][l][i])%M;
                dp[k][l][2][i+1] = (dp[k][l][2][i+1] + dp[j][k][l][i])%M;
                dp[k][l][3][i+1] = (dp[k][l][3][i+1] + dp[j][k][l][i])%M;
            }else{
                for(int m=0; m<4; m++){
                    dp[k][l][m][i+1] = (dp[k][l][m][i+1] + dp[j][k][l][i])%M;
                }
            }
        }
    }

    int ret = 0;
    for(int j=0; j<4; j++) for(int k=0; k<4; k++) for(int l=0; l<4; l++){
        // cout << j << " " << k << " " << l << " " << ret << " " << dp[j][k][l][N] << endl;
        ret = (ret + dp[j][k][l][N])%M;
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
from collections import deque

codes = input()

s1 = deque([])
s2 = deque([])

sums = 0
for idx1, ch in enumerate(codes):
    if ch == '\\':
        s1.append(idx1)
    elif ch == '/' and len(s1) > 0:
        idx2 = s1.pop()
        area = idx1 - idx2
        sums += area
        while len(s2) > 0 and s2[-1][0] > idx2:
            area += s2.pop()[1]
        s2.append([idx2, area])

output = []
while len(s2) > 0:
    output.append(s2.pop()[1])
output.reverse()
print(sum(output))
output.insert(0, len(output))
print(" ".join(map(str, output)))


Measured memory_bytes: 6564
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int a = 0, b = 0, greater = 0, result = 0;

    scanf("%d %d", &a, &b);

    greater = (a > b) ? a : b;

    for (int i = 0; i < 2; i++) {
        result += greater;
        if (a > b) {
            a--;
        } else {
            b--;
        }
        greater = (a > b) ? a : b;
    }
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  vi ans(n);
  REP(i, n) {
    if (i < k) {
      cout << s;
    } else {
      cout << (s == 1000000000 ? 1 : s + 1);
    }
    cout << (i != n - 1 ? " " : "\n");
  }
}


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

int n,w;
int const pp=10e5;
int arr[102][2] ;
long long dp[102][pp];

long long solve(int idx ,int rem)
{
    if(idx>=n)
        return 0;
    long long &ret=dp[idx][rem] ;
    if(ret)
        return ret;
    if(rem-arr[idx][0]>=0)
        ret=arr[idx][1]+solve(idx+1,rem-arr[idx][0]);
    return  ret=max(solve(idx+1,rem) ,ret);
}
int main()
{
     //freopen("input.txt", "rt", stdin);
    // freopen("output.txt", "wt", stdout);
    
    cin>>n>>w;
    for (int i=0 ;i<n ;i++)
        cin>>arr[i][0]>>arr[i][1];
    printf("%lld\n",solve(0 , w));
    return 0;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) c.begin(), c.end()
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	int W, H, N; cin >> W >> H >> N;
	vector<vector<int>> v(H, vector<int>(W, 0));
	rep(h, 0, N) {
		int x, y, a; cin >> x >> y >> a;
		if (a == 1) {
			rep(j, 0, x)rep(i, 0, H)v[i][j] = true;
		}
		if (a == 2) {
			rep(j, x, W)rep(i, 0, H)v[i][j] = true;
		}
		if (a == 3) {
			rep(j, 0, W)rep(i, 0, y)v[i][j] = true;
		}
		if (a == 4) {
			rep(j, 0, W)rep(i, y, H)v[i][j] = true;
		}
	}

	int ans = 0;
	rep(i, 0, H)rep(j, 0, W) {
		if (!v[i][j])ans++;
	}
	//rrep(i, 0, v.size()) {
	//	cout << v[i][0];
	//	rep(j, 1, v[i].size()) { cout << " " << v[i][j]; }
	//	cout << endl;
	//}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::ios;
using std::string;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string str;
  int count = 0;
  cin >> str;
  char t = str[0];
  for (int i = 1; i < str.size(); i++) {
    if (str[i] != t) {
      count++;
      t = str[i];
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
// Java implementation of Kosaraju's algorithm to print all SCCs
import java.io.*;
import java.util.*;
import java.util.LinkedList;

// This class represents a directed graph using adjacency list
// representation
public class Main
{ // Driver method
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        String str=""+n;
        int sum=0;
        for (int i = 0; i < str.length(); i++) {
            sum+=str.charAt(i)-'0';
        }
        if(n%sum==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n],b[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &a[i], &b[i]);
  }
  long max = 0;
  long n_th;
  for (long i = 0; i < n; i++) {
    if (a[i] > max) {
      max = a[i];
      n_th = i;
    }
  }
  printf("%ld\n", max+b[n_th]);

  return 0;
}

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

int main() {
  int N, M, a, b, count;
  cin >> N >> M;
  vector<vector<int>> ans(N, vector<int>(M));
  
  
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    ans.at(a-1).at(i) = 1;
    ans.at(b-1).at(i) = 1;
  }
  
  for (int i = 0; i < N; i++) {
    count = 0;
    for (int j = 0; j < M; j++)
      count += ans.at(i).at(j);
    cout << count << endl;
  }
}


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

using namespace std;

struct Card
{
	int num;
	char type;	
};

void trace(int n, Card c[])
{
	for (int i = 0; i < n; ++i)
	{
		cout << c[i].type << c[i].num;
		if (i < n - 1)
		{
			cout << " ";
		}
	}
	cout << endl;
}

void bubbleSort(int n, Card c[])
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = n - 1; j > i; j--)
		{
			if (c[j].num < c[j - 1].num)
			{
				swap(c[j], c[j - 1]);
			}
		}
	}
	return;
}

void selectionSort(int n, Card c[])
{
	int min = 0;
	for (int i = 0; i < n; ++i)
	{
		min = i;
		for (int j = i; j < n; ++j)
		{
			if (c[j].num < c[min].num)
			{
				min = j;
			}
		}
		if (i != min)
		{
			swap(c[i], c[min]);
		}
	}
	return;
}

int main(int argc, char const *argv[])
{
	int n = 0;
	cin >> n;
	Card c1[n], c2[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> c1[i].type >> c1[i].num;
		c2[i] = c1[i];
	}
	bubbleSort(n, c1);
	selectionSort(n, c2);
	trace(n, c1);
	cout << "Stable" << endl;
	trace(n, c2);
	for (int i = 0; i < n; ++i)
	{
		if (c1[i].type != c2[i].type)
		{
			cout << "Not stable" << endl;
			return 0;
		}
	}
	cout << "Stable" << endl;
	return 0;
}

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

int main()
{
    int n;
    long long k;
    scanf("%d%lld", &n, &k);
    std::pair<int, int> *ab = new std::pair<int, int>[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &ab[i].first, &ab[i].second);
    }
    std::sort(ab, ab + n);
    for (int i = 0; i < n; i++)
    {
        k -= ab[i].second;
        if (k <= 0)
        {
            printf("%d\n", ab[i].first);
            break;
        }
    }

    delete[] ab;
    return 0;
}

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


using namespace std ;

int main () {
int sum=0,a,b,c,x;
cin>>a;
int s[2][200];
for(int i=0;i<2;i++)
    for(int j=0;j<a;j++)
    cin>>s[i][j];
if(a==1)
{
cout<<s[0][0]+s[1][0];return 0;
}
s[1][0]+=s[0][0];
for(int i=1;i<a;i++)
{s[0][i]+=s[0][i-1];
s[1][i]+=max(s[0][i],s[1][i-1]);

}

cout<<s[1][a-1]<<endl;
return 0;
}



Measured memory_bytes: 384
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    


if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    if not num >= min(p, q) >= 0:
        print(0)
        exit()
    comb_init()
    print(comb(num, min(p, q)))

Measured memory_bytes: 80860
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 約数列挙
vector<ll> divisor_list(ll n){
    vector<ll> ans;
    // 約数のペアの小さい方はi^2までにある
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ll tmp = n/i;
            if (tmp!=1) ans.push_back(tmp);
            if (i!=1) ans.push_back(i);
        }
    }
    ans.push_back(2);

    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> insu1;
    vector<ll> insu2;
   
    for(ll i=2; i*i<=n; i++){
        ll tmp = n;
        while(tmp%i==0){
            tmp /= i;
        }
        if (tmp%i==1) insu1.push_back(i);
    }

    insu1.push_back(n);
    insu2 = divisor_list(n-1);
    copy(insu2.begin(), insu2.end(), back_inserter(insu1));
    sort(insu1.begin(), insu1.end());
    insu1.erase(unique(insu1.begin(), insu1.end()), insu1.end());
    ll ans = insu1.size();
    // rep(i, ans) cout << insu1[i] << endl;
    cout << ans<< endl;
    return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
//typedef pair<int,int> P;

#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define rrep(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) rep(i,0,n)
#define RREP(i,n) rrep(i,n,0)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
string s;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int cnt = 0;
  int a = 0, b = 0, c = 0;
  REP(i,n) {
    cin >> s;
    REP(j,sz(s) - 1) {
      if (s[j] == 'A' && s[j+1] == 'B') cnt++;
    }
    if (s[0] == 'B' && s[sz(s)-1] == 'A') c++;
    else if (s[0] == 'B') b++;
    else if (s[sz(s)-1] == 'A') a++;
  }

  if (a != 0) {
    cnt += c;
    cnt += min(a,b);
  } else {
    //a==0
    if (c != 0) {
      cnt += c - 1;
      if (b != 0) cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanInit()

	n := nextInt()

	cnt := 0
	for i := 1; i <= n; i += 2 {
		if numDivSlow(i) == 8 {
			cnt++
		}
	}

	fmt.Println(cnt)

}

// 約数の数をカウントする(愚直)
func numDivSlow(a int) int {
	cnt := 1
	for i := 1; i <= a/2; i++ {
		if a%i == 0 {
			cnt++
		}
	}
	return cnt
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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



int main(){
	long long n,a,b;
	cin >> n >> a >> b;
	
	long long A[n+10];
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	
	long long ans=0;
	for(int i=1;i<n;i++){
		ans+=min( (A[i]-A[i-1])*a,b);
	}
	cout << ans << endl;
	return 0;
}

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

#define VMAX 10000

int main() {
    unsigned short *A, *B;

    int C[VMAX+1];
    int n, i;

    scanf("%d", &n);

    A = malloc(sizeof(short)*n+1);
    B = malloc(sizeof(short)*n+1);

    for (i = 0; i <= VMAX; i++) { C[i] = 0; }

    for (i = 0; i < n; i++ ) {
        scanf("%hu", &A[i]);
        C[A[i]]++;
    }

    for (i = 1; i <= VMAX; i++) { C[i] = C[i] + C[i-1]; }

    for (i = 0; i < n; i++ ) {
        B[C[A[i]]-1] = A[i];
        C[A[i]]--;
    }
    for (i = 0; i < n; i++) {
        printf("%d", B[i]);
        printf( (i == n-1) ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 9612
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;


string element[110]={"","H","He","Li","Be","B","C","N","O","F",
                     "Ne","Na","Mg","Al","Si","P","S","Cl","Ar",
                     "K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co",
                     "Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr",
                     "Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh",
                     "Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe",
                     "Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu",
                     "Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf",
                     "Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl",
                     "Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th",
                     "Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"};


int n,m ,pos[20], s1[20], s2[20];
bool flag;
string s;
vector<int> ans[22];
map<string, int> mp;

void dfs(int l, int sum, int r)
{
       // cerr << "Enter---\n";
        if(r == m + 1){
            flag = 1;
            return;
        }
        if(s2[r] == sum){
            dfs(1,0, r+1);
            return;
        }

        int pre = -1;
        for(int i = l; i <= n && !flag && s1[i] + sum <= s2[r]; i++){
            if(pos[i] == -1 && s1[i] != pre){
                pre = s1[i];
                pos[i] = r;
                dfs(l+1, s1[i]+sum, r);
                if(!flag) pos[i] = -1;
            }
        }
}


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        int n, k;
        cin >> n >> k;
        int x = ((n - 2) * ( n - 1))/ 2;
        if(x < k){
            cout << "-1\n";
            return 0;
        }

        vector<pair<int,int> > ans;
        for(int i = 1; i < n; i++){
            ans.push_back({i,n});
        }

        while(x > k){
            for(int i = 1; i <= n - 2; i++){
                for(int j = i + 1; j <= n - 1; j++){
                    ans.push_back({i,j});
                    x--;
                    if(x <= k) break;
                }
                if(x <= k) break;
            }
        }
        cout << ans.size() << endl;
        for(auto x: ans)
            cout << x.first << " "<<x.second<<endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


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

using ll=long long;


int main(){
    int n,m,i,j,k,rm,cm,ans=0;
    cin>>n>>m>>k;
    int arr[n][m];
    char ch;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>ch;
            if(ch=='.')arr[i][j]=0;
            else arr[i][j]=1;
        }
    }
    for(rm=0;rm<pow(2,n);rm++){
        for(cm=0;cm<pow(2,m);cm++){
            int ct = 0;
            for(i=0;i<n;i++){
                if((1<<i)&rm)continue;
                for(j=0;j<m;j++){
                    if((1<<j)&cm)continue;
                    if(arr[i][j])ct++;
                }
            }
            if(ct==k)ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

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

	int N, ans = 0;

	cin >> N;

	for (int i = 1; i <= N; i++) {
		if (GetDigit(i) % 2) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int N; cin >> N;
  
  vector<int> n(N);
  for(int i = 0; i < N; i++){
    cin >> n.at(i);
  }
  
  sort(n.begin(), n.end());
  reverse(n.begin(), n.end());
  
  int a, b;
  a=0; b=0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0)
      a += n.at(i);
    else
      b += n.at(i);
  }
  
  cout << a - b << endl;
}




Measured memory_bytes: 384
let () =
  let linein = read_line ()
  and wordin = read_line () in
  let line = linein^linein
  and lenw = String.length wordin
  and lenl = String.length linein in
  let rec check i =
    match i with
      -1 -> "No"
    | i -> if wordin = (String.sub line i lenw) then
             "Yes"
           else
             check (i-1)
  in check (lenl-1) |> print_endline;;

Measured memory_bytes: 2112
#include<cstdio>
#include<algorithm>
const int MaxN=100010;
int N;
struct edge{int to;edge*next;}E[MaxN],*ne=E,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
int f[MaxN],tmp[MaxN];
int dfs(int i){
	for(edge*e=fir[i];e;e=e->next)dfs(e->to);
	int c=0;
	for(edge*e=fir[i];e;e=e->next)tmp[c++]=f[e->to];
	std::sort(tmp,tmp+c);
	f[i]=c;
	for(int j=0;j<c;j++)if(c-j+tmp[j]>f[i])f[i]=c-j+tmp[j];
	return f[i];
}
int main(){
	scanf("%d",&N);
	for(int i=2,a;i<=N;i++)scanf("%d",&a),link(a,i);
	printf("%d\n",dfs(1));
}

Measured memory_bytes: 7552
import java.util.*;

class Main {

	static List<Long> orthometric = new LinkedList<Long>();
	static Map<Long,List<Integer>> seaLevel = new TreeMap<Long,List<Integer>>();

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int len = sc.nextInt();
			long now = 0l;
			for (int i=0; i<len; i++) {
				long a = sc.nextLong();
				if (a != now) {
					orthometric.add(a);
					if (!seaLevel.containsKey(a)) {
						List<Integer> list = new LinkedList<Integer>();
						list.add(orthometric.size()-1);
						seaLevel.put(a, list);
					} else seaLevel.get(a).add(orthometric.size()-1);
					now = a;
				}
			}
			if (orthometric.size()>0) {
				int max = findLand();
				System.out.println(max);
			} else System.out.println("0");
		}
	}

	public static int findLand() {
		int max = 0;
		Long[] oArray = new Long[orthometric.size()];
		orthometric.toArray(oArray);
		int count = 1;
		for (List<Integer> l : seaLevel.values()) {
			for (int i : l) {
				if ((i!=0)&&(i!=oArray.length-1)) {
					if ((oArray[i-1]!=-1)&&(oArray[i+1]!=-1)) count++;
					else if ((oArray[i-1]==-1)&&(oArray[i+1]==-1)) count--;
				} else if ((i==0)&&(i!=oArray.length-1)) {
					if (oArray[i+1]==-1) count--;
				} else if ((i!=0)&&(i==oArray.length-1)) {
					if (oArray[i-1]==-1) count--; 
				}
				oArray[i] = -1l;
			}
			max = Math.max(max, count);
		}
		return max;
	}
}


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

int main( )
{
    string s;
    int i, j, k, l;
    cin >> s;
    l = (int) s.size();
    int last = 0;
    int c = 0;
    for (i = 0; i < l; i++) {
        if (s[i] - '0' == last) {
            c++;
        }
        last = last ^ 1;
    }
    last = 1;
    int c1 = 0;
    for (i = 0; i < l; i++) {
        if (s[i] - '0' == last) {
            c1++;
        }
        last = last ^ 1;
    }
    cout << min(c, c1) << '\n';
    return 0;
}


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

typedef long long ll;

ll p5(ll x) {
	return x * x * x * x * x;
}

int main()
{
	 
	ll x; scanf("%lld", &x);
			
	for(ll b = -1000; b <= 1000; b++)
		for(ll a = b + 1; a <= 1000; a++)
			if(p5(a) - p5(b) == x) {
				printf("%lld %lld\n", a, b);
				return 0;
			}	
}

Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,M,X;
  cin>>N>>M;
  if(M>1){
  X=(N-M)*100+M*1900;
  for(int i=0;i<M;i++){X=X*2;}
  cout<<X<<endl;
  return 0;
  }

  if(M==1){
  X=(N-M)*100+M*1900;
  cout<<X*2<<endl;
  return 0;
  }
  
  }

Measured memory_bytes: 256