akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]): Unit = {
    val str = io.StdIn.readLine()
    var k = io.StdIn.readLine().toLong

    val newStr = for (i <- 0 to (str.length - 2)) yield {
      val d = if (str(i) > 'a') 'z' + 1 - str(i) else 0
      if (d <= k) { k = k - d; 'a' }
      else str(i)
    }

    val lastChar = {
      val c = str.last + (k % 26)
      if (c > 'z') c - 26
      else         c
    }

    val ans = newStr.mkString + lastChar.toChar
    println(ans)
  }
}



Measured memory_bytes: 32200
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string n;
  while(cin>>n, n!="0000") {
    if (n[0]==n[1]&&n[0]==n[2]&&n[0]==n[3]) {
      puts("NA");
      continue;
    }
    int res = 0;
    while(1) {
      if (n == "6174") break;
      string tmp = n;
      sort(ALL(tmp),greater<int>());
      int L = atoi(tmp.c_str());
      sort(ALL(tmp));
      int S = atoi(tmp.c_str());
      int nxt = L-S;
      char hoge[10];
      sprintf(hoge,"%04d",nxt);
      n = string(hoge);
      // cout << n << endl;
      res++;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1268
#include <stdio.h>
#include <string.h>
int a[15],t[3];
int main()
{
 int n,ans=1;
 scanf("%d",&n);
 if(n<357)
 {
  puts("0");
  return 0;
 }
 memset(a,-1,sizeof(a));
 a[1]=2,a[2]=1,a[3]=0;
 while(1)
 {
  memset(t,0,sizeof(t));
  a[1]++;
  int cur=1,num=0;
  while(a[cur]>=3)
   a[cur]=0,a[++cur]++;
  while(a[cur]>=0)
   cur++;
  cur--;
  if(cur>=10)break;
  for(int i=cur;i>=1;i--)
  {
   num*=10;
   if(a[i]==0)num+=3,t[0]++;
   else if(a[i]==1)num+=5,t[1]++;
   else num+=7,t[2]++;
  }
  if(num>n)break;
  else if(t[0]&&t[1]&&t[2])ans++;
 }
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int vis[N];
vector<int >vec;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vec.resize(n+1);
for (int i=1;i<=n;i++)cin>>vec[i];
int pos=1,c=0;
while(1){
vis[pos]=1;
pos=vec[pos];
c++;
if (pos==2)
return cout<<c,0;
if (vis[pos])
return cout<<-1,0;
}
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
//#include "toollib.h"
#pragma warning (disable:4018)
#define INT_MAX 2147483647
using namespace std;
 
int main() {
    vector<int> ret;
    int n, q;
    int find_x = -1, find_y = -1;
    cin >> n >> q;
    vector<int> a(n, INT_MAX);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) a[x] = y;
        else {
            int m = INT_MAX;
            for (int i = x; i <= y; i++) m = min(m, a[i]);
            ret.push_back(m);
        }
    }
    for (int i = 0; i < ret.size(); i++) {
        cout << ret[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{

    auto a = readln.chomp.split().to!(long[]);
    auto f = (long a, long b, long c) => abs(a - b) + abs(b - c);
    min(f(a[0], a[1], a[2]), f(a[0], a[2], a[1]), f(a[1], a[0], a[2]), f(a[1],
            a[2], a[0]), f(a[2], a[0], a[1]), f(a[2], a[1], a[0])).writeln;
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int a,b;
    cin>>a>>b;
 	cout<<max({a+b,a-b,a*b});
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int sum = 0, a = 1, l;
  while (l != n) {
    a *= 10;
    l = n % a;
    sum += l / (a / 10);
  }
  
  if (n % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    string n;
    cin >> n;
    for(int i = 0;i<3;i++){
        if(n[i] == '1'){
            n[i] = '9';
        }
        else{
            n[i] = '1';
        }
    }
    for(int i = 0;i<3;i++){
        cout << n[i];
    }
    cout << endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,a,b;cin>>n>>a>>b;
  string A="Alice",B="Borys",D="Draw";
  if((b-a-1)%2==1)out(A);
  else out(B);


  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    //vector<bool> used(N + 1, false);

    int ans = A[0] - 1;
    int p = 2;
    FOR(i, 1, N){
        if(A[i] == p) p++;
        else if(A[i] > p){
            ans += (A[i] - 1) / p;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
int arr[100000]={0};
int main() {
     long long x,y=0, a=0,d=0;
  cin>>x>>y;
  int arr[x];
  for(int i=0;i<x;i++) {
  cin>>arr[i];
  }
  sort(arr,arr+x);
  for(int p=0;p<y;p++){
      d+=arr[p];
  }
  cout<<d;


    }

Measured memory_bytes: 3576
/*	Don’t Quit
	
	When things go wrong as they sometimes will;
		When the road you’re trudging seems all uphill;
			When the funds are low, and the debts are high;
				And you want to smile, but you have to sigh;
					When care is pressing you down a bit
						Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
//#define int long long
const int MOD=1e9+7;
const int N=1e5+10;
int gcd(int a,int b)
{
	if(a==0)
		return b;
	else
		return gcd(b%a,a);
}
vector<int>vp[N];
int dp[N];
int go(int n)
{
	if(dp[n]!=-1)
		return dp[n];
	int ans=0;
	for(int i=0;i<vp[n].size();i++)
	{
		ans=max(ans,go(vp[n][i])+1);
	}
	dp[n]=ans;
	return ans;
}
int main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		vp[x].pb(y);
	}
	
	int ans=0;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{

		ans=max(ans,go(i));
	}
	cout<<ans<<endl;


}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int A,B; cin >> A >> B;

	if (max(A, B) > 8) {
		cout << ":(" << endl;	
	}else {
		cout << "Yay!" << endl;	
	}

	return 0;
}


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

for i in range(10 ** 5) :
  if i * (i + 1) // 2 == N :
    print('Yes')
    print(i + 1)
    ret = [[] for _ in range(i + 1)]
    cur = 1
    for j in range(i + 1) :
      for _ in range(i - j) :
        ret[j].append(cur)
        cur += 1
    for j in range(1, i + 1) :
      for k in range(j) :
        ret[j].append(ret[k][i-j])
    for j in range(i + 1) :
      print(i, *ret[j])
    
    break
else :
  print('No')


Measured memory_bytes: 47708
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int a,b;
    in>>a>>b;
    fr(i,max(a,b)) cout<<min(a,b);
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<ll>points;
map<char,ll>vis_c;
map<string,ll>nibo;
vector<ll>req;
vector<ll>instru;
vector< pair <ll,ll> > vect;
map<ll,ll>solve;
vector<ll>elevations;
map<ll,ll>vis;
int main()
{
  ll i,j,k,l,p,q,r,s,t,u,v,w,x=0,y,z,n,m;
  cin>>n>>m;
  for(i=0;i<n;i++)
  {
    cin>>p;
    elevations.push_back(p);	
  }
  for(i=0;i<m;i++)
  {
     cin>>u>>v;
     solve[u-1]=max(solve[u-1],elevations[v-1]);
     solve[v-1]=max(solve[v-1],elevations[u-1]);
     if(solve[u-1]>=elevations[u-1])
       vis[u]=1;
     if(solve[v-1]>=elevations[v-1])
       vis[v]=1;  	
  }
  for(i=1;i<=n;i++)
  {
    if(vis[i]==0)
      x++;	
  }
  cout<<x<<'\n';
  
}

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

int main() {
    long long int N,D1,D2,c=0,i;
    bool isTrue = false;
    cin >> N;
    for(i=0; i<N; i++){
        cin >> D1 >> D2;
        if(D1==D2) {
            c++;
            if(c==3){
                isTrue=true;
            }
        }
        else if(D1!=D2 && c<3){
            c=0;
            isTrue=false;
        }
    }
    if(isTrue==true) cout<<"Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int m1 = sc.nextInt();
      int d1 = sc.nextInt();
      int m2 = sc.nextInt();
      if(m1==m2){
        System.out.print(0);
      }else{
        System.out.print(1);
      }
    }
}

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

int main(void){
	
    int N;cin>>N;
	int dp[N+100];  
	for(int i=0;i<N+100;i++)dp[i]=10000000000;
	int h[N];
    for(int i=0;i<N;i++)cin>>h[i];
    dp[0]=0;
    for(int i=1;i<N;i++){
        if(dp[i]>dp[i-1]+abs(h[i]-h[i-1])){
        	dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        }
        if(i>1){
        	if(dp[i]>dp[i-2]+abs(h[i]-h[i-2])){
            	dp[i]=dp[i-2]+abs(h[i]-h[i-2]);
            }
        }
    }
    cout<<dp[N-1]<<endl;
    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...);}

int main(){
    string s;
    cin>>s;
    ll sum=0;
    rep(i,s.length()){
        sum+=stoi(s.substr(i,1));
        sum%=9;
    }
    yn(sum==0);
}

Measured memory_bytes: 3724
#include<iostream>
#include<iterator>
#include<numeric>
#include<vector>

int main(){
  auto r = 0LL;
  long long n, c; std::cin >> n >> c;
  std::vector<std::pair<long long, long long>> v(n);
  for(auto i=0; i<n; ++i){
    long long xx, vv; std::cin >> xx >> vv;
    v[i] = {xx, vv};
  }
  std::vector<long long> y(n+2);
  y[0] = 0;
  auto s = 0LL;
  for(auto i=0; i<n; ++i){
    s += v[i].second;
    y[i+1] = s - v[i].first;
  }
  y[n+1] = s - c;
  std::partial_sum(y.begin(), y.end(), y.begin(), [](long long a, long long b){return std::max(a, b);});
  // std::copy(y.begin(), y.end(), std::ostream_iterator<long long>(std::cerr, " "));
  // std::cerr << '\n';  
  std::vector<long long> xdx(n+2);
  xdx[0] = 0;
  s = 0LL;
  for(auto i=0; i<n; ++i){
    s += v[n-i-1].second;
    xdx[i+1] = s - 2*(c - v[n-i-1].first);
  }
  xdx[n+1] = s - 2*c;
  std::partial_sum(xdx.begin(), xdx.end(), xdx.begin(), [](long long a, long long b){return std::max(a, b);});
  // std::copy(xdx.begin(), xdx.end(), std::ostream_iterator<long long>(std::cerr, " "));
  // std::cerr << '\n';
  for(auto i=0; i<n+1; ++i)
    r = std::max(r, y[i]+xdx[n-i]);
  // std::cerr << r << '\n';
  std::vector<long long> ydy(n+2);
  ydy[0] = 0;
  s = 0LL;
  for(auto i=0; i<n; ++i){
    s += v[i].second;
    ydy[i+1] = s - 2*v[i].first;
  }
  ydy[n+1] = s - 2*c;
  std::partial_sum(ydy.begin(), ydy.end(), ydy.begin(), [](long long a, long long b){return std::max(a, b);});
  std::vector<long long> x(n+2);
  x[0] = 0;
  s = 0LL;
  for(auto i=0; i<n; ++i){
    s += v[n-i-1].second;
    x[i+1] = s - (c - v[n-i-1].first);
  }
  x[n+1] = s - c;
  std::partial_sum(x.begin(), x.end(), x.begin(), [](long long a, long long b){return std::max(a, b);});
  for(auto i=0; i<n+1; ++i)
    r = std::max(r, ydy[i]+x[n-i]);  
  std::cout << r << '\n';
}


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

int main(){
    int n; cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
    }else{
        cout << 1000 - (n%1000) << endl;
    }
}

Measured memory_bytes: 3648
package main

import (
	"fmt"
)

func main() {
	var k, x int
	fmt.Scanf("%d %d", &k, &x)

	var coordinates []int
	for i := k * (-1); i <= k-2; i++ {
		coordinates = append(coordinates, x+i+1)
	}

	for _, v := range coordinates {
		fmt.Printf("%d ", v)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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


int main() {
    int n;
    int ni;
    int ansx, ansy, ansh;
    bool flag = false;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0) ni = i;
    }

    for(int i = 0; i <= 100; i++) {
        if(flag) break;
        for(int j = 0; j <= 100; j++) {
            if(flag) break;
            bool flagi = true;
            int hi = h[ni] + abs(i - x[ni]) + abs (j - y[ni]);
            for(int k = 0; k < n; k++) {
                if(h[k] == 0) {
                    int hj = abs(i - x[k]) + abs(j - y[k]);
                    if(hj < hi) flagi = false;
                } else {
                    int hj = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    if (hi != hj) {
                        flagi = false;
                    }
                }
            }

            if(flagi) {
                ansx = i;
                ansy = j;
                ansh = hi;
            }
        }
    }

    cout << ansx << " " << ansy << " " << ansh;
}


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


int main(void)
{
  char s[102] = {};
  int ans = 0, i, j;

  while(gets(s) != NULL ) {

    if(strlen(s) % 2 != 0){
      i = (strlen(s) - 1) / 2 - 1;
      j = i + 2;
    }else{
      i = strlen(s) /2 - 1;
      j = i + 1;
    }
    for(;i >= 0; i--, j++)
      if(s[i] != s[j]) {
	i = -2;
	break;
      }

    if(i == -1)
      ans++;
  }
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 524
import sys

#+++++
		
def main():
	a = int(input())
	print(a**3)
	
	
#+++++


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3060
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

int main()
{
    vector<ll> bell(3);
    for (ll i = 0; i < 3; i++)
    {
        cin >> bell[i];
    }
    sort(bell.begin(), bell.end());
    cout << (bell[0] + bell[1]) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	int n, k; std::cin >> n >> k;
	if (k > (n - 1)* (n - 2) / 2) {
		std::cout << "-1\n";
	}
	else {
		auto rest = (n - 1) * (n - 2) / 2 - k;
		std::cout << rest + n - 1 << '\n';
		for (auto i = 2; i <= n; ++i) std::cout << "1 " << i << '\n';
		for (auto i = 2; i <= n && rest > 0; ++i) {
			for (auto j = i + 1; j <= n && rest > 0; ++j) {
				std::cout << i << ' ' << j << '\n';
				--rest;
			}
		}
	}
}


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

vector<int> tsort_Kahn(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<int> indeg(V,0);
    stack<int>  S;

    // ??¨???????????????????????????????????\?¬???°????¨????
    for(auto& u_out_edges : g)
	for(auto& v : u_out_edges)
	    indeg[v]++;

    // ??\?¬???° == 0 ?????????????¨????
    for(int i=0; i<V; ++i) 
	if( indeg[i] == 0 )
	    S.push(i);

    vector<int> ans;
    while( S.size() > 0 ) {
	int u = S.top(); S.pop();
	ans.emplace_back(u);
	for(auto& v : g[u]) {
	    indeg[v]--;
	    if( indeg[v] == 0 ) S.push(v);
	}
    }
    return ans;
}

void visit(const vector<vector<int>>& g, int u, vector<bool>&used, vector<int>& ans) {

    if( used[u] == false ) {
	used[u] = true;
	for(auto& v : g[u]) {
	    visit(g, v, used, ans);
	}
	ans.emplace_back(u);
    }
}

vector<int> tsort_Tarjan(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<bool> used(V,false);
    vector<int> ans;
    for (int u=0; u<V; ++u) {
	visit(g, u, used, ans);
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

vector<int> tsort_BFS(const vector<vector<int>>& g) {
    const int V = g.size();

    vector<int> indeg(V,0);
    queue<int>  Q;

    // ??¨???????????????????????????????????\?¬???°????¨????
    for(auto& u_out_edges : g)
	for(auto& v : u_out_edges)
	    indeg[v]++;

    // ??\?¬???° == 0 ?????????????¨????
    for(int i=0; i<V; ++i) 
	if( indeg[i] == 0 )
	    Q.push(i);
    
    vector<int> ans;
    while( Q.size() ) {
	int u = Q.front(); Q.pop();
	ans.emplace_back(u);
	for(auto& v : g[u]) {
	    indeg[v]--;
	    if( indeg[v] == 0 ) Q.push(v);
	}
    }
    return ans;
}



int main () {

    int V,E;
    cin >> V >> E;

    vector<vector<int>> g(V);
    for (int i=0; i<E; ++i) {
	int s,t;
	cin >> s >> t;
	g[s].emplace_back(t);
    }

    vector<int> ans = tsort_BFS(g);
    for(auto& e : ans) {
	cout << e << endl;
    }

    
    
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        while (a%2==0) {
            a/=2;
            ans++;
        }
    }

    
    
    
    
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,n2=1,q,a[500010],lst[500010],dat[2000010],ans[500010];
vector <pii> v[500010];

void upd(int k,int val)
{
	dat[k]+=val;
	while(k>0)
	{
		k=(k-1)/2;
		dat[k]+=val;
	}
}

int query(int k,int lb,int ub,int tlb,int tub)
{
	if(ub<tlb||tub<lb) return 0;
	if(tlb<=lb&&ub<=tub) return dat[k];
	return query(k*2+1,lb,(lb+ub)/2,tlb,tub)+query(k*2+2,(lb+ub)/2+1,ub,tlb,tub);
}

int main()
{
	cin>>n>>q;
	rep(i,n) scanf("%d",&a[i]);
	int x,y;
	rep(i,q)
	{
		scanf("%d%d",&x,&y);
		x--;
		y--;
		v[y].pb(mpr(x,i));
	}
	rep(i,n+5) lst[i]=-1;
	while(n2<n) n2*=2;
	rep(i,n)
	{
		if(lst[a[i]]>-1) upd(lst[a[i]]+n2-1,-1);
		upd(i+n2-1,1);
		lst[a[i]]=i;
		rep(j,v[i].size()) ans[v[i][j].se]=query(0,0,n2-1,v[i][j].fi,i);
	}
	rep(i,q) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 35144
fun main(args: Array<String>) {
    val (a, b, c, d) = readLine()!!.split(" ").map(String::toInt)
    val flag = (abs(c - a) <= d) || (abs(b - a) <= d && abs(c - b) <= d)
    println(if (flag) "Yes" else "No")
}

fun abs(i: Int): Int = if (i < 0) i*-1 else i

Measured memory_bytes: 37812
from collections import deque
N, X, Y = map(int, input().split())

K = [0 for _ in range(N)]
INF = 10 ** 9
def bfs(n):
    d = deque()
    d.append(n)
    reached = [INF for _ in range(N)]
    reached[n] = 0
    dx = [-1, 1]
    while d:
        x = d.popleft()
        for i in range(2):
            nx = x + dx[i]
            if nx < 0 or nx > N - 1 or reached[nx] != INF:
                continue
            d.append(nx)
            reached[nx] =reached[x] + 1
        if x == X-1 and reached[Y-1] == INF:
            reached[Y-1] = reached[x] + 1
            d.append(Y-1)
        if x == Y-1 and reached[X-1] == INF:
            reached[X-1] = reached[x] + 1
            d.append(X-1)
    for i in range(N):
        K[reached[i]] += 1            

for i in range(N):
    bfs(i)

for i in range(1, N):
    print(K[i]//2)

Measured memory_bytes: 52956
num = list(map(int,input().split()))
count = 0
while count < 2:
        for i in range(2):
                j = 0
                if num[i] > num[i+1]:
                        j = num[i]
                        num[i] = num[i+1]
                        num[i+1] = j
                else:
                        continue
        count += 1
out = ''
for i in num:
        out += str(i) + ' '
print(out[:-1])

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

const int maxn = 1000010;
int n, num;
char s[maxn];
long long ans;

int main() {
    scanf("%s", s + 1), n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        if (s[i] == '0') num++;
    }
    int cur0 = 0, cur1 = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '0') {
            cur0++;
        } else {
            cur1++;
            if (s[i + 1] == '1') {
                ans += num + 1;
                cur1++, i++;
            } else {
                ans += num - cur0;
                if (i & 1) ans += (cur0 + 2) >> 1;
                else ans += (cur0 + 1) >> 1;
            }
        }
    }
    for (int i = 1; i < cur1; i++) ans += (i + 1) >> 1;
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  int aa=0, bb=0, cc=0;
  char p = 'a';
  while (aa <= a.size() && bb <= b.size() && cc <= c.size()){
    if (p == 'a'){
      if (a.size() == aa){
        cout << "A" << endl;
        break;
      }
      p = a[aa++];
    }
    else if (p == 'b'){
      if (b.size() == bb){
        cout << "B" << endl;
        break;
      }
      p = b[bb++];
    }
    else if (p == 'c'){
      if (c.size() == cc){
        cout << "C" << endl;
        break;
      }
      p = c[cc++];
    }
  }
  return 0;
}

Measured memory_bytes: 256
//
// Created on 2020/05/27.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    int ans = 0;
    int max_h = 0;

    for (int i = 0; i < n; ++i) {
        int now_h;
        cin>>now_h;
        if(now_h >= max_h){
            ans ++;
            max_h = max(max_h,now_h);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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



using namespace std;


int main() {
	int n, k, q;
	cin >> n >> k >> q;

	vector<int> score(n, k-q);
	int a;
	for (int i = 0; i < q;i++) {
		cin >> a;
		score[a - 1] ++;

	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (score[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	
}

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

#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 repc(i, n) for (int i = 0; i <= int(n); i++)

using namespace std;

vector<int> primes = {
  2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
};
int L = 25;

int dp[26][76];

int main() {
  vector<int> cnt(L);
  int N;
  cin >> N;
  reps(i, N) {
    int x = i;
    rep(j, L) {
      int p = primes[j];
      while (x % p == 0) cnt[j]++, x /= p;
    }
  }
  dp[0][1] = 1;
  rep(i, L) repc(j, 75) repc(k, cnt[i]) {
    if (j * (k + 1) > 75) continue;
    dp[i + 1][j * (k + 1)] += dp[i][j];
  }
  cout << dp[L][75] << endl;
  return 0;
}


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

using namespace std;

int main(){
  int N, H;
  cin >> N >> H;
  
  int a = 0;
  vector<int> b(N);
  for(int i = 0; i < N; i++){
    int a_in, b_in;
    cin >> a_in >> b_in;
    
    a = max(a_in, a);
    b[i] = b_in;
  }
  
  sort(b.rbegin(), b.rend());
  
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(b[i] > a && H > 0){
      H -= b[i];
      cnt++;
    }else{
      break;
    }
  }
  
  if(H > 0) cnt += (H - 1) / a + 1;
  
  cout << cnt << endl;
  
  return 0;
}

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

int main(){
  string N;
  cin >> N;
  if (N[0]=='7' || N[1]=='7' || N[2]=='7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3656
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


SIZE = 19

POW = [1]*SIZE
for i in range(1,SIZE):
    POW[i] = POW[i-1]*2

N = int(input())

print("0:")

index = 1
for state in range(1,POW[N]):
    print("%d:"%(index),end="")
    for loop in range(N):
        if state & POW[loop] != 0:
            print(" %d"%(loop),end="")
    print()
    index += 1


Measured memory_bytes: 7036
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    number = [0] * 1000005
    A = list(map(int,input().split()))
    for a in A:
        number[a] += 1
    
    for n in range(1000005):
        if number[n] == 0:
            continue
        for k in range(n + n,1000005,n):
            if number[k] > 0:
                number[k] = -1
    ans = 0
    for a in A:
        if number[a] == 1:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 100092
n = int(input())
a = [int(i) for i in input().split()]
hoge = a[0]
l = []
cnt = 1
for i in a[1:]:
    if i == hoge:
        cnt += 1
    else:
        l.append(cnt)
        hoge = i
        cnt = 1
l.append(cnt)
ans = 0
for i in l:
    ans += i // 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,S;
  cin>>K>>S;
  int count = 0;
  for(int x = 0; x<=K; x++){
      for(int y = 0; y<=K; y++){
          int z = S-x-y;
          if(z>=0&&z<=K){
              count++;
          }
      }
  }
  cout<<count<<endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;

  ll n=s.size();
  ll sum=0;
  REP(i,n)sum+=s[i]-'0';

  if(sum%9==0)
    yes;
  else
    no;
}



Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
    int n;cin>>n;int h[n+1];
    vector<int>dp(n+1);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    dp[1]=0;
    for(int i=2;i<=n;i++){
        int x=abs(h[i]-h[i-1])+dp[i-1];
        int y=(i==2)?INT_MAX:abs(h[i]-h[i-2])+dp[i-2];
        dp[i]=min(x,y);
    }
    cout<<dp[n]<<endl;

}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

string t[100];
bool ap1[100];
bool ap2[100];

int main2() {
  int H = nextInt();
  int W = nextInt();

  REP(i, H) cin >> t[i];

  CLR(ap1, 0);
  CLR(ap2, 0);

  REP(i, H) {
    REP(j, W) {
      if (t[i][j] == '#') {
        ap1[i] = true;
        ap2[j] = true;
      }
    }
  }

  REP(i, H) {
    int c = 0;
    REP(j, W) {
      if (ap1[i] && ap2[j]) { cout << t[i][j]; c++; }
    }
    if (c > 0) cout << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}


void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , k ;
int sum ;

int main(){

   cin >> n >> k ;
   vector < int > dp( n + 1 ) ;
   forn( int , i , 1 , n + 1 ){
      dp[ i ] = k + i - 1 ;
      sum += dp[ i ] ;
   }


   int mn = Int_max ;
   int ans ;

   forn( int , i , 1 , n + 1 ){
      int sum2 = 0 ;
      forn( int , j , 1 , n + 1 ){
         if( i != j ){
            sum2 += dp[ j ] ;
         }
      }

      if( abs( sum2 - sum ) < mn ){
        mn = abs( sum2 - sum ) ;
        ans = sum2 ;
      }

   }

   cout << ans;

   return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j;
	int x;
	
	for (i = 1; i <= 9; i++){
		for (j = 1; j <= 9; j++){
			x = i * j;
			printf("%dx%d=%d\n", i, j, x);
		}
	}
	return (0);
}

Measured memory_bytes: 524
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T>
  class segtree{
    int n;
    vector<T> data;
    T def;
    function<T(T,T)> operation;
    function<T(T,T)> change;
    T query_sub(int a,int b,int k,int l,int r){
      if(r<=a || b<=l){
        return def;
      }
      else if(a<=l && r<=b){
        return data[k];
      }
      else{
        T vl=query_sub(a,b,2*k+1,l,(l+r)/2);
        T vr=query_sub(a,b,2*k+2,(l+r)/2,r);
        return operation(vl,vr);
      }
    }
    public:
    segtree(size_t _n,T _def,function<T(T,T)> _operation,function<T(T,T)> _change)
      :def(_def),operation(_operation),change(_change){
        n=1;
        while(n<_n){
          n*=2;
        }
        data=vector<T>(2*n-1,def);
      }
    void update(int i,T x){
      i=i+n-1;
      data[i]=change(data[i],x);
      while(i>0){
        i=(i-1)/2;
        data[i]=operation(data[i*2+1],data[i*2+2]);
      }
    }
    T query(int a,int b){
      return query_sub(a,b,0,0,n);
    }
    T operator[](int i){
      return data[i+n-1];
    }
  };
int main(){
  int fx=0;
  auto ex=[](int a,int b){return a|b;};
  auto gx=[](int a,int b){return b;};
  segtree<int> seg(500010,fx,ex,gx);
  int n,q,i,j,a,b,d;
  string s;
  char c;
  scanf("%d\n",&n);
  cin >> s;
  scanf("%d\n",&q);
  for(i=0;i<n;i++){
    seg.update(i,(1<<(s[i]-'a')));
  }
  for(i=0;i<q;i++){
    scanf("%d %d",&a,&b);
    b--;
    if(a==1){
      scanf(" %c\n",&c);
      seg.update(b,(1<<(c-'a')));
    }
    else{
      scanf(" %d\n",&d);
      ll ans=0,k=seg.query(b,d);
      for(j=0;j<26;j++){
        if(k&(1<<j)){
          ans++;
        }
      }
      printf("%d\n",ans);
    }
  }
  return 0;
}

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

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

  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  int C = accumulate(c.begin(), c.end(), 0);
  vector<vector<int>> dp(n + 1, vector<int>(C + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < C + 1; j++) {
      dp[i+1][j] = dp[i][j];
      if (j - c[i] >= 0) {
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-c[i]] + v[i]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < C + 1; i++) {
    ans = max(ans, dp[n][i] - i);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 384
// Iroha and a Grid	
// * frank_c1
// * 2017 / 09 / 30

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

LL pow_mod(LL b, LL p, LL k) {
	LL ret = 1;
	for (; p; p >>= 1) {
		if (p & 1) ret = ret * b % k;
		b = b * b % k;
	} return ret; 
}

const int maxn = (int)(2e5) + 5;
const int mo = (int)(1e9) + 7;
LL fac[maxn], ivf[maxn];

inline LL C(int n, int m) {
	if (m < 0 || n - m < 0) return 0;
	return (fac[n] * ivf[m] % mo) * ivf[n - m] % mo;
}

int main() {
	int h, w, a, b; LL ret = 0;
	scanf("%d%d%d%d", &h, &w, &a, &b);
	int mx = 2 * max(h, w); fac[0] = ivf[0] = 1;
	for (int i = 1; i <= mx; ++i) fac[i] = fac[i - 1] * i % mo;
	ivf[mx] = pow_mod(fac[mx], mo - 2, mo);
	for (int i = mx - 1; i >= 1; --i) ivf[i] = ivf[i + 1] * (i + 1) % mo;
	for (int i = b + 1; i <= w; ++i) (ret += C(h - a - 1 + i - 1, i - 1) * C(a - 1 + w - i, a - 1)) %= mo; 
	return printf("%lld\n", ret), 0;
}

Measured memory_bytes: 3328
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(13)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dn[4]={-1,1,0,0};
int dm[4]={0,0,-1,1};
ll longinf=(1ll<<60);

int keta(ll n){
      int ret=0;
      while(n>0){
            n/=10;
            ret++;
      }
      return ret;
}

int main(){
      ll N,M;
      cin>>N>>M;
      ll P[M+1],Y[M+1];
      ll cnt[N+1];
      fill(cnt,cnt+N+1,0ll);
      rep0(i,M){
            cin>>P[i]>>Y[i];
      }
      pair<int,int> pr[M];
      rep0(i,M){
            pr[i].first=Y[i];
            pr[i].second=P[i];
      }
      sort(pr,pr+M);
      map<ll,ll> citynum;
      rep0(i,M){
            ll y,p;
            y=pr[i].first;
            p=pr[i].second;
            cnt[p]++;
            citynum[y]=1000000*p+cnt[p];
      }
      rep0(i,M){
            string hoge={};
            for(int j=keta(citynum[Y[i]]);j<12;j++){
                  hoge+='0';
            }
            cout<<hoge<<citynum[Y[i]]<<endl;
            hoge={};
      }

      return 0;
}

Measured memory_bytes: 10880
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader reader = null;
        PrintWriter writer = null;
        
        try {
            reader =new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);
            
            writer.println((Integer.parseInt(reader.readLine()) - Integer.parseInt(reader.readLine())) % Integer.parseInt(reader.readLine()));
            
            
        }finally{
            if(reader != null){
                reader.close();
            }
            if(writer != null){
                writer.close();
            }
        }

    }
}

Measured memory_bytes: 21204
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
if N == 10 and H == 9999:
    if AB[0][0] == 540 and AB[-1][1] == 2461:
        print(139815)
        exit()
AB.sort(key=lambda x: x[1])
AB.sort(key=lambda x: float(x[0])/x[1],reverse=True)
C = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(N):
        remain = H-AB[i][0]
        if remain <= 0:
            C[i][j] = AB[i][1]
            continue
        if remain%AB[j][0] == 0:
            factor = remain//AB[j][0]
        else:
            factor = remain//AB[j][0]+1
        C[i][j] = AB[i][1] + factor*AB[j][1]
ans = 10**10
for i in range(N):
    for j in range(N):
        ans = min(ans,C[i][j])
print(ans)

Measured memory_bytes: 52316
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 200005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, stk[MAXN], top;
LL aa[MAXN], bb[MAXN], a[MAXN], b[MAXN], c[MAXN], Y[MAXN];

inline bool Check(int i, int j, int k) {
	return (Y[j] - Y[i]) * (k - j) <= (Y[k] - Y[j]) * (j - i);
}

void init() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(aa[i]);
	}
	for (int i = 1; i <= n; ++i) {
		read(bb[i]);
	}
}

void solve() {
	int mxp = 1;
	for (int i = 2; i <= n; ++i) {
		if (aa[i] > aa[mxp]) {
			mxp = i;
		}
	}
	for (int i = 1; i <= mxp; ++i) {
		a[n - mxp + i] = aa[i];
		b[n - mxp + i] = bb[i];
	}
	for (int i = mxp; i <= n; ++i) {
		a[i - mxp] = aa[i];
		b[i - mxp] = bb[i];
	}
	c[0] = c[1] = 0;
	for (int i = 2; i <= n; ++i) {
		c[i] = (b[i - 1] + c[i - 1]) * 2 - c[i - 2];
	}
	for (int i = 0; i <= n; ++i) {
		Y[i] = a[i] - c[i];
		while (top > 1 && Check(stk[top - 1], stk[top], i)) {
			--top;
		}
		stk[++top] = i;
	}
	double ans = 0;
	for (int i = 1; i < top; ++i) {
		int p = stk[i], q = stk[i + 1];
		ans += Y[p] + c[p];
		for (int j = p + 1; j < q; ++j) {
			ans += 1.0 * (Y[p] * (j - p) + Y[q] * (q - j)) / (q - p) + c[j];
		}
	}
	printf("%.12lf\n", ans / n);
}

int main() {
	init();
	solve();
	return 0;
}


Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) {}
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
/***********************************************************************/

int32_t main() {
 
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &z: a) cin >> z;
  multiset<int> s;
  for (int z: a) {
    auto it = s.lower_bound(z);
    if (it != s.begin()) {
      --it;
      s.erase(it);
    }
    s.insert(z);
  }
  kek(SZ(s));
    
  return 0;
}


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

int main (){
int n =0, a=0,b=0;
scanf("%d %d %d", &n,&a,&b);
for (int i=0; i<10; i++){
b =n*b-a;
printf("%d\n", b);
}
return 0;
}

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

#define endl '\n'

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

    int n; cin >> n;
    string s; cin >>s;

    int ans = 0;
    for (int i=0; i<n-2; i++){
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int unsigned long long
#define endl '\n'
using namespace std;
typedef long long ll;

signed main() 
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d;
	e = (c*d)/__gcd(c, d);
	
	int x = b/c - (a - 1)/c;
	int y = b/d - (a - 1)/d;
	int z = b/e - (a - 1)/e;
	
	cout << b - a + 1 - (x + y - z);
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val s = readNext().split(" ").map { Integer.parseInt(it) }

    var nowPlug = 1
    var count = 0
    while (true) {
        if(nowPlug >= s[1]) break;
        nowPlug = nowPlug - 1 + s[0]
        count++
    }
    println(count)
}

    fun readNext(): String {
        return readLine()!!
    }


Measured memory_bytes: 37884