akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main()
{
  int n, k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  
  int j = 0;
  for(int i=k;i<n;i++, j++)
  {
    if(a[j] < a[i])
      cout<<"Yes";
    else cout<<"No";
    
    cout<<"\n";
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int INF = 1e9;

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

    int n, c, sum = 0;
    cin >> n >> c;
    vi v(n), w(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    vector<vll> dp(n + 1, vll(sum + 1));

    dp[0][0] = 0;
    for (int i = 1; i <= sum; ++i) {
        dp[0][i] = INF;
    }
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = 0;
        for (int j = 0; j <= sum; ++j) {
            dp[i][j] = INF;
            dp[i][j] = min(dp[i - 1][j], j >= v[i - 1] ? 
                           dp[i - 1][j - v[i - 1]] + w[i - 1] : INF);
        }
    }
    for (int j = sum; j >= 0; --j) {
        if (dp[n][j] <= c) {
            cout << j << '\n';
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int a[10], b[10][10], c[10][10][10];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        int d = (s[i] - '0');
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if (b[j][k]) {
                    c[j][k][d] = 1;
                }
            }
        }
        for (int j = 0; j < 10; j++) {
            if (a[j]) {
                b[j][d] = 1;
            }
        }
        a[d] = 1;
    }
    int res = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                res += c[i][j][k];
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

const int MAXN=100000+10;
int tree[MAXN],cnt[3];
int n;
vector<int> edge[MAXN];

void bfs()
{
	queue<int> q;
	q.push(1);
	q.push(n);
	while(!q.empty())
	{
		int temp=q.front();
		q.pop();
		cnt[tree[temp]]++;
		for(int i=0;i<edge[temp].size();++i)
		{
			int v=edge[temp][i];
			if(tree[v])continue;
			else tree[v]=tree[temp];
			q.push(v);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	tree[1]=1,tree[n]=2;
	bfs();
	if(cnt[2]>=cnt[1])cout<<"Snuke"<<endl;
	else cout<<"Fennec"<<endl;
	return 0;
}

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

using namespace std;

int N;
int K;
int a[100+5];

bool dp[100000+5];
bool memoize[100000+5];

inline bool solve(int rem_stone)
{
      if (rem_stone <= 0) return false;
      bool &ret = dp[rem_stone];
      bool &mem = memoize[rem_stone];
      if (mem) return ret;
      mem = 1;
      for (int i = 0; i < N; i++)
      {
            if (a[i] <= rem_stone && !solve(rem_stone - a[i])) return ret = true;
      }
      return ret = false;
}

int main()
{
      cin >> N >> K;
      for (int i = 0; i < N; i++) cin >> a[i];
      if (N == 1)
      {
            int turn = K / a[0];
            if (turn & 1) cout << "First";
            else cout << "Second";
            exit(0);
      }
      if (solve(K)) cout << "First";
      else cout << "Second";
}


Measured memory_bytes: 3584
#include <stdio.h>
int main(void)
{
int H ,W;
int i, j;
while(1){
scanf("%d %d" ,&H ,&W);
if(H == 0 && W == 0) break;
for ( i = 0; i < H; i++ ){
for ( j = 0; j < W; j++ ){
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>

double dis2(double xa,double ya,double xb,double yb){
	return (xa-xb)*(xa-xb)+(ya-yb)*(ya-yb);
}

int main(){
	
	double xa,ya,ra,xb,yb,rb;
	int n;
	int i,j,k,l,m;
	int ans;

	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%lf %lf %lf %lf %lf %lf",
			&xa,&ya,&ra,&xb,&yb,&rb);
		if((xa+ra)>(xb+rb)&&(xa-ra)<(xb-rb)
			&&(ya+ra)>(yb+rb)&&(ya-ra)<(yb-rb))
			ans=2;
		else if((xa+ra)<(xb+rb)&&(xa-ra)>(xb-rb)
			&&(ya+ra)<(yb+rb)&&(ya-ra)>(yb-rb))
			ans=-2;
		else if(dis2(xa,ya,xb,yb)<=(ra+rb)*(ra+rb))
			ans=1;
		else ans=0;
		printf("%d\n",ans);
	}



	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int a[N];
  int ans = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    ans += a[i] - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int n, d, x, asdf, sum;

int main(){
	scanf("%d %d %d", &n, &d, &x);
	
	for(int i=0; i<n; i++){
		scanf("%d", &asdf);
		sum += (d-1)/asdf + 1;
	}
	
	printf("%d", sum + x);
	
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;

namespace abc042.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputIntArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int sum = 0;

            foreach (int param in inputIntArray)
            {
                if (param == 5 || param == 7)
                {
                    sum += param;
                }
            }
            Console.WriteLine(sum == 17 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 28184
#2019/10/17
S = open(0).read()
if len(S)%2 != 0:
    S=S[:-3]
else:
    S=S[:-2]
for i in range(int(len(S)/2)):
    #print("S=",S)
    #print(S[:int(len(S)/2)])
    #print(S[int(len(S)/2):])
    if S[:int(len(S)/2)] == S[int(len(S)/2):]:
        print(len(S))
        break
    else:
        S=S[:-2]

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> al = new ArrayList<>();
		
		int i = 0;
		int cnt = 0;
		int x = 999;
		while(x != 0) {
			x = sc.nextInt();
			if(x == 0) {
				break;
			} else {
				cnt++;
				al.add(x);
			}
		}
		
		while(i < cnt) {
			i++;
			System.out.println("Case " + i + ": " + al.get(i-1));
		}
		
		
	}
}

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



int main() {
  int n;
  cin >> n;
  vector<int> ans(n+5);
 
  int sn=sqrt(n);
  for(int x=1; x<sn; x++){
    for(int y=1; y<=sn; y++){
      for(int z=1; z<=sn; z++){
        ll tmp=x*x+y*y+z*z+x*y+y*z+z*x;
        if(tmp<=n)ans[tmp]++;
      }
    }
  }
  
  
  for(int i=1; i<=n; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3576
import copy
import sys
input = sys.stdin.readline

n, m = map(int,input().split())
graph = [[] for i in range(n+1)]
for i in range(m):
    u, v = map(int,input().split())
    graph[u].append(v)
s, g = map(int,input().split())

INF = 10**7
ans = [[INF, INF, INF] for i in range(n+1)]
q = [s]
d = 0
while q:
    nq = []
    d += 1
    p = d % 3
    for cf in q:
        for ct in graph[cf]:
            if ans[ct][p] == INF:
                ans[ct][p] = d
                nq.append(ct)
    q = copy.deepcopy(nq)
if ans[g][0] == INF:
    print(-1)
else:
    print(ans[g][0]//3)

Measured memory_bytes: 42456
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//grobal変数


int main() {
	int a, b;
	int c,d;
	int ans = 0;
	cin >> a >> b >> c >> d;
	for (int i = 0; i <= 100; i++) {
		if (a <= i && i <= b) {
			if (c <= i && i <= d) {
				ans++;
			}
		}
	}
	if (ans) ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = tuple(map(int, input().split()))

from fractions import gcd
def lcm(x, y):
    return x * y // gcd(x, y)

gcds = [0] * N
gcds[0] = A[0]
rev_gcds = [0] * N
rev_gcds[-1] = A[-1]

for i in range(1, N):
    gcds[i] = gcd(A[i], gcds[i-1])
    rev_gcds[N-1-i] = gcd(A[N-1-i],  rev_gcds[N-i])

ans = 1
for i in range(N):
    if i == 0:
        tmp = rev_gcds[i+1]
    elif i == N-1:
        tmp = gcds[i-1]
    else:
        tmp = gcd(gcds[i-1], rev_gcds[i+1])
    ans = max(ans, tmp)

print(ans)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;



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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> M(h, vector<char>(w));
    rep(i, h){
        rep(j, w){
            cin >> M[i][j];
        }
    }

    vector<vector<int>> cnt1(h, vector<int>(w, 0)), cnt2(h, vector<int>(w, 0));

    rep(i, h){
        rep(j, w){
        int cnt = 0;
            if(M[i][j] == '.'){
                for (int k = j; k < w; ++k) {
                    if(M[i][k] == '.'){
                        cnt++;
                    }else{
                        //cnt = 0;
                        break;
                    }
                }
                for (int k = j; k < w; ++k) {
                    if(M[i][k] == '.'){
                        cnt1[i][k] = cnt;
                    }else{
                        break;
                    }
                }
                j += cnt;
            }
        }
    }

    rep(i, w){
        rep(j, h){
        int cnt = 0;
            if(M[j][i] == '.'){
                for (int k = j; k < h; ++k) {
                    if(M[k][i] == '.'){
                        cnt++;
                    }else{
                        break;
                    }
                }
                for (int k = j; k < h; ++k) {
                    if(M[k][i] == '.'){
                        cnt2[k][i] = cnt;
                    }else{
                        break;
                    }
                }
                j += cnt;
            }
        }
    }


    int ans = 0;
    rep(i, h){
        rep(j, w){
            if(M[i][j] == '.'){
                ans = max(ans, cnt1[i][j] + cnt2[i][j] - 1);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 35712
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		String x=sc.next();
		for(int i=0;i<x.length();i++) {
			x=x.replace(x.charAt(i), 'x');
		}
		pw.print(x);
		pw.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int N, M, T;
	int a[101];
	cin >> N >> M >> T;
	REP(i, 0, N) cin >> a[i];

	int ans = M;
	REP(i, 1, N) {
		if (a[i] - a[i - 1] >= (2 * M)) ans += (2 * M);
		else ans += a[i] - a[i - 1];
	}
	if (T - a[N - 1] >= M) ans += M;
	else ans += T - a[N - 1];

	cout << T - ans << endl;

    return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
int main(void){
	
	int a;
	int i=0;
	
do{
	
	i++;
	scanf("%d",&a);
	
	
	if(a!=0){
		printf("Case %d: %d\n",i,a);
	}
	
	
}while(a!=0);

return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
int main()
{
    using namespace std;
    int n,x,t,r;
    cin>>n;
    cin>>x;
    cin>>t;
    if(n%x!=0)
    {
    r=n/x+1;
    cout<<r*t;
    }
    else
    {
        r=n/x;
        cout<<r*t;
}


}


Measured memory_bytes: 3632
/*  -*- coding: utf-8 -*-
 *
 * 3016.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 127;
const int INF = 1 << 29;

/* typedef */

typedef vector<int> vi;

/* global variables */

int xss[MAX_N + 1][MAX_N + 1];

/* subroutines */

inline int xsum(int x0, int y0, int x1, int y1) {
  return (xss[y1][x1] - xss[y1][x0] - xss[y0][x1] + xss[y0][x0]);
}

inline bool hline(int y, int x0, int x1) {
  return (xsum(x0, y, x1, y + 1) == x1 - x0);
}

inline bool vline(int x, int y0, int y1) {
  return (xsum(x, y0, x + 1, y1) == y1 - y0);
}

int rec(int x0, int y0, int x1, int y1) {
  vi vx, vy;
  for (int y = y0 + 1; y < y1; y += 2)
    if (hline(y, x0, x1)) vy.push_back(y);
  for (int x = x0 + 1; x < x1; x += 2)
    if (vline(x, y0, y1)) vx.push_back(x);
  
  int minsum = INF;

  for (vi::iterator yit = vy.begin(); yit != vy.end(); yit++)
    for (vi::iterator xit = vx.begin(); xit != vx.end(); xit++) {
      int yy = *yit, xx = *xit;
      int sum = 1;
      if (xsum(x0, y0, xx, yy) > 0) {
	int r = rec(x0, y0, xx, yy);
	if (r >= INF) continue;
	sum += r;
      }
      if (xsum(xx + 1, y0, x1, yy) > 0) {
	int r = rec(xx + 1, y0, x1, yy);
	if (r >= INF) continue;
	sum += r;
      }
      if (xsum(x0, yy + 1, xx, y1) > 0) {
	int r = rec(x0, yy + 1, xx, y1);
	if (r >= INF) continue;
	sum += r;
      }
      if (xsum(xx + 1, yy + 1, x1, y1) > 0) {
	int r = rec(xx + 1, yy + 1, x1, y1);
	if (r >= INF) continue;
	sum += r;
      }

      if (minsum > sum) minsum = sum;
    }

  return minsum;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int y = 0; y < n; y++) {
    char s[MAX_N + 4];
    scanf("%s", s);
    for (int x = 0; x < n; x++)
      xss[y + 1][x + 1] =
	((s[x] == 'x') ? 1 : 0) + xss[y + 1][x] + xss[y][x + 1] - xss[y][x];
  }

  if (xsum(0, 0, n, n) == 0) {
    puts("0");
    return 0;
  }

  printf("%d\n", rec(0, 0, n, n));
  return 0;
}



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

typedef long long ll;
using namespace std;

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

	int a[4];

	for (int i = 0;i < 4;i++){
		cin >> a[i];
	}

	sort(a,a+4);

	if(a[0] == a[1] && a[2] == a[3]) cout << "yes" << endl;
	else cout << "no" << endl;

	return 0;

}


Measured memory_bytes: 3200
#include <stdio.h>
#define N  100

void trace(int a[], int n) {
  int i;
  printf("%d", a[0]);
  for (i = 1; i < n; i++)
    printf(" %d", a[i]);
  putchar('\n');
}

void insertionSort(int a[], int n) {
  int t, i, j, k;
  
  for (i = 1; i < n; i++) {
    t = a[i];
    j = i - 1;
    
    while (j >= 0 && a[j] > t) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = t;
    trace(a, n);
  }
}

int main(void) {
  int a[N], n, i, j;

  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  trace(a, n);
  
  insertionSort(a, n);
    
  return 0;
}

Measured memory_bytes: 604
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）

const ll INF=1e18;

class UnionFind{
public:
	vector<ll> par,num;
 
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	ll size(int v){
		return num[find(v)];
	}
};

signed main(){
    int n,m,k;
    cin>>n>>m>>k;
    V<int> a(m),b(m),c(k),d(k);
    rep(i,m) cin>>a[i]>>b[i];
    rep(i,k) cin>>c[i]>>d[i];
    Graph G(n);
    UnionFind tree(n);
    V<int> deg(n);
    V<set<int>> st(n),ss(n);
    rep(i,m){
        a[i]--;b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        deg[a[i]]++;
        deg[b[i]]++;
        st[a[i]].insert(b[i]);
        st[b[i]].insert(a[i]);
        tree.unite(a[i],b[i]);
    }
    V<int> u(n,0);
    rep(i,k){
        c[i]--;d[i]--;
        if(tree.same(c[i],d[i])){
            if(!st[c[i]].count(d[i])) u[c[i]]++;
            if(!st[d[i]].count(c[i])) u[d[i]]++;
        }
    }
    rep(i,n){
        ll cnt=tree.size(i)-deg[i];
        cout<<cnt-u[i]-1<<' ';
    }
}

Measured memory_bytes: 29308
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll ans = 0, pre = -1, s, k, t;std::cin >> k >> t;
  multimap<ll, ll, greater<ll>> m;
  re(i, t){
    std::cin >> s;
    m.emplace(s, i+1);
  }
  while(!m.empty()){
    ll now = (*m.begin()).second, num = (*m.begin()).first;
    if(now==pre&&m.size()==1){
      ans++, num--;
      auto itr = m.begin();
      m.erase(itr);
      if(num!=0) m.emplace(num, now);
    }else{
      auto itr = m.begin();
      if(pre==now){
        itr++;
        now = (*itr).second, num = (*itr).first;
      }
      pre = now, num--;
      m.erase(itr);
      if(num!=0) m.emplace(num, now);
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

typedef string::const_iterator State;
class ParseError
{
};

int number(State &begin)
{
    int ret = 0;

    while (isdigit(*begin))
    {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int term(State &begin)
{
    int ret = number(begin);

    for (;;)
    {
        if (*begin == '*')
        {
            begin++;
            ret *= number(begin);
        }
        else
        {
            break;
        }
    }
    return ret;
}

int expr(State &begin)
{
    int ret = term(begin);
    for (;;)
    {
        if (*begin == '+')
        {
            begin++;
            ret += term(begin);
        }
        else
        {
            break;
        }
    }
    return ret;
}
int exprWrong(State &begin)
{
    int ret = number(begin);
    for (;;)
    {
        if (*begin == '+')
        {
            begin++;
            ret += number(begin);
        }
        else if (*begin == '*')
        {

            begin++;
            ret *= number(begin);
        }
        else
        {
            break;
        }
    }
    return ret;
}
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int ans;
    cin >> ans;
    State begin = s.begin();
    int ansc = expr(begin);
    begin = s.begin();
    int answ = exprWrong(begin);
    if (ans == ansc && ans != answ)
    {
        cout << "M" << endl;
    }
    else if (ans != ansc && ans == answ)
    {
        cout << "L" << endl;
    }
    else if (ans == ansc && ans == answ)
    {
        cout << "U" << endl;
    }
    else if (ans != ansc && ans != answ)
    {
        cout << "I" << endl;
    }

    return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
const int N=100005 ;
vector<int>e[N];
int dep[N] , md[N], fa[N],n,s,t;
void dfs(int u,int f)
{
dep[u]=md[u]=dep[f]+1,fa[u]=f;
for(auto v:e[u])if(v!=f)dfs(v ,u) ,md[u]=max( md[u],md[v]);
}
int main(){
scanf( "%d%d%d",&n, &s,&t);
for(int i=1;i<n;i++){
int u,v;
scanf ( "%d%d" , &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}dfs(t,0);
int ans=0,x=s;
while(1){
if(dep[s]-dep[x]>=dep[x]-dep[t])break ;
ans=max(ans,md[x]-1);
x=fa[x];
}
printf( "%d\n",ans-1);
return 0;
}


Measured memory_bytes: 12032
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;


int main(){
int n,i,minv,maxv;
int a[MAX];

cin >> n;

for(i = 0;i < n;i++){
    cin >> a[i];
}

maxv = -2000000000;
minv = a[0];

for(i=1;i<n;i++){
    maxv = max(a[i] - minv,maxv);
    minv = min(minv, a[i]);
}

cout << maxv << endl;
return 0;
}


Measured memory_bytes: 3888
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String t;
		int i, cnt, idx;
		while(true){
			t = sc.next();
			if(t.equals("-")) break;
			cnt = sc.nextInt();
			for(i=0; i<cnt; i++){
				idx = sc.nextInt();
				t = t.substring(idx).concat(t.substring(0, idx));
			}
			System.out.println(t);
		}
	}
}

Measured memory_bytes: 18192
package main

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

func main() {
	x := readi()

	i := 0
	tmp := 100
	for {
		tmp = int(float64(tmp) * 1.01)
		i++
		if tmp >= x {
			break
		}
	}
	fmt.Println(i)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

// 最大公約数
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

// 最小公倍数
func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func factorical(n int) int {
	if n > 0 {
		return n * factorical(n-1)
	}
	return 1
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=400005,INF=1<<30;

ll rui(ll a,ll b){
    ll res=1;
    for(int i=0;i<b;i++){
        if(log10(res)+log10(a)>=13) return 1100000000000;
        res*=a;
        if(res>=1100000000000) break;
    }
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    
    set<ll> SE,div;
    
    N--;
    
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            SE.insert(i);
            SE.insert(N/i);
        }
    }
    
    N++;
    
    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            div.insert(i);
            div.insert(N/i);
        }
    }
    
    for(ll b=1;b<=40;b++){
        for(auto a:div){
            ll x=rui(a,b);
            if(N%x) continue;
            ll y=N/x-1;
            if(y%a==0) SE.insert(a);
        }
    }
    
    for(auto a:div){
        for(ll b=1;b<=40;b++){
            ll x=rui(a,b);
            if(x==N) SE.insert(a);
        }
    }
    
    cout<<SE.size()-1<<endl;
}




Measured memory_bytes: 512
from collections import deque

N, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]

memo = {}
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].append(b)
    E[b].append(a)
    memo[(a, b)] = i
    memo[(b, a)] = i

K = max(len(e) for e in E)

A = [0] * (N - 1)

cand = {i for i in range(1, K + 1)}

visited = [False] * (N + 1)

Q = deque([(-1, 1)])
visited[1] = True
while Q:
    p, v = Q.popleft()
    c = 0
    for u in E[v]:
        if visited[u]:
            continue
        visited[u] = True
        c += 1 + (c + 1 == p)
        Q.append((c, u))
        A[memo[(v, u)]] = c

print(K)
for a in A:
    print(a)


Measured memory_bytes: 55068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long P, long long Q, long long R)
{
}
int main()
{
    vector<ll> p;
    long long P;
    scanf("%lld", &P);
    long long Q;
    scanf("%lld", &Q);
    long long R;
    scanf("%lld", &R);
    solve(P, Q, R);
    p.push_back(P);
    p.push_back(Q);
    p.push_back(R);

    SORT(p);

    cout << p[0] + p[1] << endl;
    return 0;
}


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

int main(){
  int i,j,N,*arr,minj,tmp,count = 0;
  scanf("%d",&N);
  arr = (int *)malloc(sizeof(int) * N);
  for(i = 0; i < N; i++){
    scanf("%d",&arr[i]);
  }

  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(arr[j] < arr[minj]){
	minj = j;
      }
    }
    tmp = arr[i];
    arr[i] = arr[minj];
    arr[minj] = tmp;
    if(i != minj) count++;
  }
  for(i = 0; i < N; i++){
    printf("%d",arr[i]);
    if(i == N-1){
      printf("\n");
      break;
    }
    printf(" ");
  }
  printf("%d\n",count);
  

  free(arr);
  return 0;
}



Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>dis(n);
    
    for(int i=0;i<n;i++){
        cin>>dis[i];
        //cout<<dis[i]<<" ";
    }//cout<<"\n";
    vector<int>costs(n,INT_MAX);
    costs[0]=0;
    for(int i=1;i<n;i++){
        int count=k,j=i-1;
        while(count-- && j>=0){
            int cost = costs[j] + abs(dis[i]-dis[j]);
            //cout<<cost<<"\n";
            if(cost < costs[i])
                costs[i]=cost;
            j--;
        }
    }
    cout<<costs[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

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

bool isPrime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll N;
  cin >> N;
  vector<ll> X(N);

  for (ll i = 0; i < N; i++) {
    cin >> X[i];
  }

  ll ans = 1LL << 60;
  for (ll i = 1; i <= 100; i++) {
    ll hp = 0;
    for (auto x : X) {
      hp += (x - i) * (x - i);
    }
    ans = min(ans, hp);
  }

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


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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;
   cout << counter << endl;
  
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int[] A;
        static int[] numtype;
        static readonly int WIN = 1;
        static readonly int UNJ = 0;
        static readonly int LOSE = -1;
        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            A = Sarray();
            var amax = A.Max();
            var amin = A.Min();

            numtype = new int[K + 1];
            for (var i = 0; i <= K; ++i)
                numtype[i] = isWinnerNum(i);
            if (WIN == numtype[K])
                WriteLine("First");
            else
                WriteLine("Second");
        }
        //負け数に持っていけたら勝ち
        static int isWinnerNum(int i)
        {
            if (numtype[i] != UNJ) return numtype[i];
            foreach (var a in A)
            {
                if (0 <= i - a)
                {
                    numtype[i - a] = isLoserNum(i - a);
                    if (LOSE == numtype[i - a])
                        return WIN;
                }
            }
            return LOSE;
        }
        //どう頑張っても勝ち数になるなら負け
        static int isLoserNum(int i)
        {
            if (numtype[i] != UNJ) return numtype[i];
            foreach (var a in A)
            {
                if (0 <= i - a)
                {
                    numtype[i - a] = isWinnerNum(i - a);
                    if (LOSE == numtype[i - a])
                        return WIN;
                }
            }
            return LOSE;
        }
    }
}

Measured memory_bytes: 13780
import java.util.*;

public class Main {

	private static List<Integer>[] g;

	private static boolean[] inStack;

	private static boolean[] visited;

	private static long[] memo;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] a = new int[n][n - 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - 1; j++) {
				a[i][j] = sc.nextInt() - 1;
			}
		}
		Map<Integer, Integer>[] m = new HashMap[n];
		for (int i = 0; i < n; i++) {
			m[i] = new HashMap<>();
		}

		int nodes = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n - 1; j++) {
				if (a[i][j] < i) {
					a[i][j] = m[a[i][j]].get(i);
				} else {
					m[i].put(a[i][j], nodes);
					a[i][j] = nodes++;
				}
			}
		}

		//for (int i = 0; i < a.length; i++) {
		//	for (int j = 0; j < a[i].length; j++) {
		//		System.out.print(a[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}

		g = new ArrayList[n * (n - 1) / 2];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<>();
		}

		int[] ds = new int[n * (n - 1) / 2];

		for (int i = 0; i < a.length; i++) {
			for (int j = 1; j < a[i].length; j++) {
				g[a[i][j - 1]].add(a[i][j]);
				ds[a[i][j]]++;
			}
		}

		if (hasCycle()) {
			System.out.println(-1);
			return;
		}

		long answer = 0;
		Arrays.fill(visited, false);
		memo = new long[visited.length];

		for (int i = 0; i < ds.length; i++) {
			if (ds[i] > 0 || visited[i]) continue;
			answer = Math.max(answer, dfs2(i));
		}

		System.out.println(answer);
	}

	private static boolean hasCycle() {
		inStack = new boolean[g.length];
		visited = new boolean[g.length];
		Arrays.fill(inStack, false);
		Arrays.fill(visited, false);
		for (int i = 0; i < g.length; i++) {
			if (visited[i]) continue;
			boolean hasCycle = dfs(i);
			if (hasCycle) return true;
		}

		return false;
	}

	private static boolean dfs(int x) {
		if (inStack[x]) return true;
		if (visited[x]) return false;
		visited[x] = true;
		inStack[x] = true;
		for (int i = 0; i < g[x].size(); i++) {
			boolean a = dfs(g[x].get(i));
			if (a) return true;
		}

		inStack[x] = false;
		return false;

	}

	private static long dfs2(int x) {
		if (visited[x]) return memo[x];
		visited[x] = true;
		memo[x] = 1;
		if (g[x].size() == 0) return memo[x];


		long a = 0;
		for (int i = 0; i < g[x].size(); i++) {
			a = Math.max(a, dfs2(g[x].get(i)));
		}
		memo[x] = a + 1;
		return memo[x];
	}
}


Measured memory_bytes: 323808
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
  a1, b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)

mp = [10 ** 8] * (h + max(a))
mp[0] = 0
for i in range(h):
  for j in range(n):
    mp[i+a[j]] = min(mp[i+a[j]], mp[i] + b[j])

print(min(mp[h:]))


Measured memory_bytes: 41580
n,k=map(int,input().split(" "))
h=list(map(int,input().split(" ")))


h.sort()


i=1
try:
    while i<=k:
       h[-i]=0
       i+=1
except:
    pass


i=0
ans=0
while i<n:
    ans+=h[i]
    i+=1
print(ans)



Measured memory_bytes: 26016
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		//System.out.println(S);
		
		if(S.equals("AAA")||S.equals("BBB")) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,k = I()

 
print(k*((k-1)**(n-1)))

Measured memory_bytes: 72736
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll N;
    cin>>N;
    string s=to_string(N);
    int a[s.length()];
    int ans=0;
    bool ok=true;
    for(int i=0; i<s.length(); ++i){
        a[i]=(N%10);
        N/=10;
    }
    ans+=a[s.length()-1];
    for(int i=0; i<s.length()-1; ++i){
        if(a[i]!=9){
            ok=false;
        }
        ans+=9;
    }
    if(ok==true)cout<<ans<<endl;
    else cout<<ans-1<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,k;
    cin>>n>>k;
    int max=(n-1)*(n-2)/2;
    if(max<k)cout<<-1<<endl;
    else{
        vii ans;
        for(int i=2;i<=n;++i)ans.PB(MP(1,i));
        int d=max-k;
        int v=2;
        while(d>0){
            for(int i=v+1;i<=n;++i){
                ans.PB(MP(v,i));
                d--;
                if(d==0)break;
            }
            v++;
        }
        int m=ans.size();
        cout<<m<<endl;
        rep(i,m){
            cout<<ans[i].F<<" "<<ans[i].S<<endl;
        }
    }
}


Measured memory_bytes: 3600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] s = new String[n];
    long start = 0;
    long last = 0;
    long both = 0;
    long cnt = 0;
    for(int i = 0;i < n;i++){
      s[i]=sc.next();
      for(int j = 0;j < s[i].length()-1;j++)
        if(s[i].substring(j,j+2).equals("AB"))cnt++;
      if(s[i].charAt(0)=='B'&&s[i].charAt(s[i].length()-1)=='A')both++;
      else if(s[i].charAt(0)=='B')start++;
      else if(s[i].charAt(s[i].length()-1)=='A')last++;
    }
    if(both==0)cnt+=Math.min(last,start);
    else if(start+last==0)cnt+=both-1;
    else if(start+last>0)cnt+=both+Math.min(start,last);
    System.out.println(cnt);
  }
}


Measured memory_bytes: 32772
#include<bits/stdc++.h>
using namespace std; 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
 
typedef long long int ll; 
typedef long double ld; 

int main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll D, T, S;
	cin>>D>>T>>S;
	
	(((D+0.0L)/S)<=T)?cout<<"Yes":cout<<"No";
	
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
int main(){
    map<string,int> mp;
    int n,m;
    cin >> n;
    REP(i,n){
        string s;
        cin >> s;
        mp[s]++;

    }
    cin >> m;

    REP(i,m){
         string s;
        cin >> s;
        mp[s]--;

    }
    int max = 0;
    for(const auto &e:mp){
        int v = e.second;
        if (max<v) max = v;

    }
    cout << max << endl;

   /* for(auto x = mp.begin();x!=mp.end();x++){   //その時に言うべき名前を出力
        if (x->second == max){
            cout << x->first << endl;
        }

    }*/




    return 0;




}

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

#define Mod 1000000007

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, N, P[5001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * N * 2);
	for (i = 0; i < N; i++) {
		if (P[i+1] == -1) continue;
		d[i*2].v = P[i+1];
		d[i*2+1].v = i + 1;
		d[i*2].next = adj[i+1];
		d[i*2+1].next = adj[P[i+1]];
		adj[i+1] = &(d[i*2]);
		adj[P[i+1]] = &(d[i*2+1]);
	}
	
	list *p;
	int j, k, K, comp[5001] = {}, q[5001], head, tail, size[5001] = {};
	for (i = 1, k = 1; i <= N; i++) {
		if (P[i] != -1) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = adj[q[head]]; p != NULL; p = p->next) {
				if (comp[p->v] == 0) {
					comp[p->v] = k;
					q[tail++] = p->v;
				}
			}
		}
		size[k++] = tail;
	}
	for (i = 1, K = k - 1; i <= N; i++) {
		if (comp[i] != 0) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = adj[q[head]]; p != NULL; p = p->next) {
				if (comp[p->v] == 0) {
					comp[p->v] = k;
					q[tail++] = p->v;
				}
			}
		}
		k++;
	}
	
	long long ans = N - k + 1 + K, dp[5001][5001] = {{1}}, N_pow[5001] = {1}, fact;
	for (i = 1; i <= K; i++) {
		N_pow[i] = N_pow[i-1] * (N - 1) % Mod;
		dp[i][0] = dp[i-1][0] * size[i] % Mod;
		for (j = 1; j <= i; j++) dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] * size[i]) % Mod;
	}
	ans = (ans * N_pow[K] - (dp[K][K-1] - K) * N_pow[K-1] % Mod) % Mod;
	for (i = 2, fact = 1; i <= K; i++, fact = fact * (i - 1) % Mod) {
		ans = (ans + Mod - ((dp[K][K-i] * fact % Mod) * N_pow[K-i] % Mod)) % Mod;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 197388
#include<stdio.h>

int main()
{
    int N,i,j;
    long long int sum=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum=sum+i;
        }
    }
    printf("%lld",sum);
}


Measured memory_bytes: 1732
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_a"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func iabs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func solve(n int, heights []int) int {
	t := make([]int, n+1, n+1)
	for i := range t {
		t[i] = math.MaxInt64
	}

	t[0] = 0
	for i := 1; i < n; i++ {
		if v := t[i-1] + iabs(heights[i]-heights[i-1]); v < t[i] {
			t[i] = v
		}
		if 1 < i {
			if v := t[i-2] + iabs(heights[i]-heights[i-2]); v < t[i] {
				t[i] = v
			}
		}
	}

	return t[n-1]
}

func main() {
	sc := newScanner(os.Stdin)
	n := sc.Int()
	heights := sc.IntSlice(n)
	ans := solve(n, heights)
	fmt.Println(ans)
}


Measured memory_bytes: 3812
#include<iostream>
using namespace std;
int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int x=sx,y=sy;
	while(++y<=ty)cout<<"U";y--;
	while(++x<=tx)cout<<"R";x--;
	while(--y>=sy)cout<<"D";y++;
	while(--x>=sx)cout<<"L";x++;
	cout<<"L",x--;
	while(++y<=ty+1)cout<<"U";y--;
	while(++x<=tx)cout<<"R";x--;
    cout<<"D";y--;cout<<"R";x++;
    
    while(--y>=sy-1)cout<<"D";y++;
	while(--x>=sx)cout<<"L";x++;
	cout<<"U";
	return 0;
} 

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def dfs(n, used):
        if n > N:
            return 0
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 5, 7)):
            ans += dfs(10 * n + d, used | (1 << i))
        return ans

    print(dfs(0, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 75340
program abc148e
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n
    integer(int64):: div,ans

    read*, n
    if (n < 10) then
        print'(i0)', 0
        stop
    end if

    if (mod(n,2_8) == 1) then
        print'(i0)', 0 
        stop
    end if
    div=10
    ans=0
    do while (div <= n)
        ans = ans + n/div
        div=div*5
    end do
    print'(i0)', ans
end program abc148e

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

const int N = 505;
typedef long long ll;
ll n, m, h, w, d;
ll a[N][N], ans;

int main() {
    cin >> n >> m >> h >> w;
    d = 1000;
    rep(i, 1, n) {
        rep(j, 1, m) {
            if (i % h == 0 && j % w == 0) a[i][j] = -((h * w - 1) * d) - 1;
            else a[i][j] = d;
            ans += a[i][j];
        }
    }
    if (ans < 0) return puts("No"), 0;
    puts("Yes");
    rep(i, 1, n) {
        rep(j, 1, m) printf("%lld ", a[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 5740