akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else  return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
    return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left == NIL || z->right == NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left != NIL) x=y->right;
  else x=y->right;
  if(x != NIL) x->parent=y->parent;
  if(y->parent == NIL) root=x;
  else if(y == y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y != z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
    z->parent=y;
    if(y == NIL) root = z;
    else if(z->key < y->key) y->left=z;
    else y->right=z;
  
}

void inorder(Node u){
  if(u != NIL){
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  }  
}
  
void preorder(Node u){
  if(u != NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}



Measured memory_bytes: 25184
n,k = map(int,input().split())
ans = [i for i in range(1,n+1)]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in a:
        if j in ans:
            del ans[(ans.index(j))]
print(len(ans))

Measured memory_bytes: 9160
n = int(input())
nums = list(map(int, input().split()))
count = 0
for i in range(1,n-1):
    a = nums[i-1]
    b = nums[i]
    c = nums[i+1]
    if ((a < b) and (b < c)) | ((a > b) and (b > c)):
        count += 1

print(count)

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

root_N = pow(N,1/2)

ans = 1000
for i in range(int(root_N)+1):
	A = i+1
	if N%A == 0:
		B = N//A
		ans_l = max(len(str(A)), len(str(B)))
		ans = min(ans,ans_l)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int A,B,a[1000010],b[1000010];
map<int,int> mpa,mpb;

int main(void){
    cin >> A;
    for(int i = 0;i < A;i++){
          cin >> a[i];
    }
    cin >> B;
    for(int i = 0;i < B;i++){
          cin >> b[i];
    }
    for(int i = 0;i < A;i++){
          mpa[a[i]]++;
    }
    for(int i = 0;i < B;i++){
          mpb[b[i]]++;
    }
    for(int i = 0;i < B;i++){
          if(mpb[b[i]] > mpa[b[i]]){
                cout << "NO" << endl;
                return 0;
          }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 23840
package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func GCD(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return GCD(a%b, b)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	N := nextInt()
	S := nextString()
	var Leftidx [10]int
	var Rightidx [10]int
	var numnums [10]int
	var num int
	for i := 0; i < 10; i++ {
		Leftidx[i] = 50000
		Rightidx[i] = 0
		numnums[i] = 0
	}

	for i := 0; i < N; i++ {
		num = int(S[i] - '0')
		Leftidx[num] = int(math.Min(float64(Leftidx[num]), float64(i)))
		Rightidx[num] = int(math.Max(float64(Rightidx[num]), float64(i)))
		numnums[num]++
	}
	ans := 0
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			for k := 0; k < 10; k++ {
				if i == j && j == k {
					if numnums[i] >= 3 {
						ans++
					}
				} else {
					for m := Leftidx[i] + 1; m < Rightidx[k]; m++ {
						if int(S[m]-'0') == j {
							ans++
							break
						}
					}
				}
			}
		}
	}
	//fmt.Printf("%d %d %d\n", R, G, B)
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 768
#156D
p=7+10**9
def comb(n,r):
  bunshi = 1
  for i in range(n-r+1, n+1):
    bunshi =bunshi * i % p
  bunbo = 1
  for i in range(1, r+1):
    bunbo = bunbo * i % p
  return bunshi * pow(bunbo, p-2, p)
n,a,b=map(int,input().split())
s=-1+pow(2,n,p)-comb(n,a)-comb(n,b)
print(s%p)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

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

	ll n ; cin >> n;
	long double m; cin >> m;

	ll m1 = round( 100*m );

	ll ans = m1*n/100;

	cout << ans << endl;
}


Measured memory_bytes: 3716
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int k;
	std::cin >> k;
	std::string ans;
	int t=0;
	auto dfs = [&] (auto f, int i, int d) -> void {
		if(d==1) {
			t++;
			if(t==k) ans+=(char)(i+'0');
			return ;
		}
		for(int di=-1;di<=1;di++) {
			if(di+i<0 || di+i>9) continue;
			f(f,di+i,d-1);
			if(t==k) {
				ans+=(char)(i+'0');
				return ;
			}
		}
	};
	for(int d=1;d<=11;d++) {
		for(int s=1;s<10;s++) {
			dfs(dfs,s,d);
			debug(d,s,t);
			if(t==k) {
				std::reverse(all(ans));
				print(ans);
				return 0;
			}
		}
	}
	return 0;
}


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

int main() {
  int h1, m1, h2, m2, k;
  cin>>h1>>m1>>h2>>m2>>k;
  int tmp = h2 * 60 + m2 - h1 * 60 - m1;
  cout<<tmp - k<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
vector<int>G[maxn];
int n,sz[maxn],vis[maxn];
char s[maxn];
void adde(int x,int y){
  if(x>n || y>n)return;
  G[x].push_back(y);
  G[y].push_back(x);
}
void dfs(int x,int y){
  sz[x]=1;
  for(int v:G[x])if(v!=y){
    dfs(v,x);
    vis[sz[v]]=1;
    vis[n-sz[v]]=1;
    sz[x]+=sz[v];
  }
}
int main(){
  //freopen("aa.in","r",stdin);
  scanf("%s",s+1);
  n=strlen(s+1);
  int tot=2;
  int x=2;
  adde(1,2);
  if(s[1]=='0')return puts("-1"),0;

  for(int i=2;i<=n;){
    if(s[i]=='1'){
      int j=i;
      for(;j<=n && s[j]=='1';j++){
        adde(x,++tot);
        x=tot;
      }
      i=j;
    }else{
      int j=i;
      for(;j<=n && s[j]=='0';j++){
        adde(x,++tot);
      }
      i=j;
    }
  }
      dfs(1,0);
      // for(int i=1;i<=n;i++){
      //   printf("vis %d %d\n",i,vis[i]);
      // }
    for(int i=1;i<=n;i++){
      if(s[i]-'0'!=vis[i])return puts("-1"),0;
    }
    for(int i=1;i<=n;i++){
      for(int v:G[i])if(v>i){
        printf("%d %d\n",i,v);
      }
    }
  return 0;
}

Measured memory_bytes: 13952
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
namespace io
{
#define SIZ (1 << 21 | 1)
#define gc() (io::iS == io::iT ? (io::iT= (io::iS= io::ibuff) + fread(io::ibuff, 1, SIZ, stdin), (io::iS == io::iT ? EOF : *io::iS++)) : *io::iS++)
#define putc(x) (io::oS == io::oT ? (fwrite(io::obuff, 1, io::oS - io::obuff, stdout), io::oS= io::obuff, (*io::oS++= x)) : *io::oS++= x)
#define exit                                          \
	fwrite(io::obuff, 1, io::oS - io::obuff, stdout); \
	return 0;
	char *iS, *iT, ibuff[SIZ], obuff[SIZ], *oS= obuff, *oT= oS + SIZ - 1, fu[110], c;
	int fr;
	template <class Type>
	inline void read(Type &x)
	{
		x= 0;
		Type y= 1;
		for(c= gc(); (c > '9' || c < '0') && c != '-'; c= gc())
			;
		c == '-' ? y= -1 : x= (c & 15);
		for(c= gc(); c >= '0' && c <= '9'; c= gc()) x= x * 10 + (c & 15);
		x*= y;
	}
	inline void reads(char *x)
	{
		for(c= gc(); c == ' ' || c == '\n'; c= gc())
			;
		for(; c != ' ' && c != '\n' && c != EOF; *x= c, c= gc(), ++x)
			;
	}
	template <class Type>
	inline void print(Type x, char text= '\n')
	{
		if(x < 0) putc('-'), x*= -1;
		if(x == 0) putc('0');
		while(x) fu[++fr]= x % 10 + '0', x/= 10;
		while(fr) putc(fu[fr--]);
		putc(text);
	}
	inline void prints(char *x, char *y= NULL, char text= '\n')
	{
		for(; *x && x != y; ++x) putc(*x);
		putc(text);
	}
}  // namespace io
using io::print;
using io::prints;
using io::read;
using io::reads;
int a, b;
signed main()
{
	read(a), read(b);
	if((long long)a * b <= 0)
		printf("Zero");
	else if(a > 0)
		printf("Positive");
	else if(b < 0)
		if((b - a + 1) & 1)
			printf("Negative");
		else
			printf("Positive");
	else if((0 - a) & 1)
		printf("Negative");
	else
		printf("Positive");
	putc('\n');
	exit;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  vector<vector<int>> memo(10, vector<int>(10, 0));
  string tmp_n;
  int tmp_i, tmp_j;
  REPI(i, 1, N + 1) {
    tmp_n = to_string(i);
    tmp_i = tmp_n.front() - '0';
    tmp_j = tmp_n.back() - '0';
    ++memo.at(tmp_i).at(tmp_j);
  }

  int ans = 0;

  REPI(i, 1, 10) {
    REPI(j, 1, 10) { ans += memo.at(i).at(j) * memo.at(j).at(i); }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

// FAIL
void fail(){ print(-1); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

ld dist(const std::vector< std::pair<ld, ld> >& vp, int i, int j) {
  ld dx = vp[i].first  - vp[j].first;
  ld dy = vp[i].second - vp[j].second;
  return std::pow(dx * dx + dy * dy, 0.5);
}

int main()
{
  // 特定のボールが隣り合うようにした並べ方(A, B を隣り合うようにする場合)
  // [A - B] - C - D    ---> (N-1)!
  // [B - A] - C - D    ---> (N-1)!
  // なので、
  //  (N-1)! + (N-1)! = 2 * (N-1)! 通り
  //
  // 全部の通り数が N! なので、2 * (N-1)! / N! = 2 / N が平均。
  // 全部の隣り合う経路の長さに対して 2 / N を掛ければ良い。
  ll N;
  std::cin >> N;
  std::vector< std::pair<ld, ld> > vp(N);
  for (ll i = 0; i < N; i++) {
    std::cin >> vp[i].first >> vp[i].second;
  }

  ld ans = 0.0;
  for (ll i = 0; i < N; i++) {
    for (ll j = i+1; j < N; j++) ans += dist(vp, i, j) * 2 / N;
  }

  std::cout << std::setprecision(12);
  print(ans);
  return 0;
}


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

int main(){

    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]-=(i+1);
    }

    sort(a.begin(),a.end());

    ll ans=0;
    ll t=n/2;

    rep(i,n){
        ans+=abs(a[i]-a[t]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        if (cin.nextint * cin.nextint % 2 == 0)
        {
            WriteLine("Even");
        }
        else
        {
            WriteLine("Odd");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13140
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Change
public class Main{
	Scanner sc=new Scanner(System.in);

	long M;
	int rD, rR;
	long cD, cR;

	void run(){
		M=sc.nextLong();
		rD=sc.nextInt();
		rR=sc.nextInt();
		cD=sc.nextLong();
		cR=sc.nextLong();
		solve();
	}

	void solve(){
		long max=-1;
		long D0=(100*cD+rD-1)/rD, C0=(100*cR+rR-1)/rR;
		for(int i=0; i<100; i++){
			for(int j=0; j<100; j++){
				long changeD=D0+i, changeR=C0+j;
				long jpn=M-changeD-changeR;
				if(jpn<0){
					continue;
				}
				long remD=changeD*rD/100-cD;
				long remR=changeR*rR/100-cR;
				jpn+=remD*100/rD+remR*100/rR;
				max=max(max, jpn);
			}
		}
		println(max+"");
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		int sum = 0, e_sum[10] = {0};
		for (int i = 0; i < n; i++){
			int num;
			int r_sum = 0;
			for (int j = 0; j < n; j++){
				scanf("%d", &num);
				r_sum += num;
				e_sum[j] += num;
				printf("%5d", num);
			}
			sum += r_sum;
			printf("%5d\n", r_sum);
		}

		for (int i = 0; i < n; i++){
			printf("%5d", e_sum[i]);
		}
		printf("%5d\n", sum);
	}

	return (0);
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int count = 0;
  int sum = 0;
  
  if(B != 1){
  for(int i = 1;;i++){
    sum+=A;
    count++;
    if(sum>=B){
      break;
    }
    else{
      sum--;
    }
  }
  cout<<count<<endl;
  }
  
  else{
    cout<<0<<endl;
  }
    
    return 0;
}

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

int main(){
  int x,y;cin>>x>>y;
  bool flag = false;
  for (int i = 0; i <= x; i++) {
    int kame = i;
    int turu = x - i;
    if (kame * 4 + turu * 2 == y)
    {
      flag = true;
    }
  }
  cout << (flag? "Yes":"No") << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int N;
struct cord {
	long x; long y;
	long double r;
	int idx;
	struct cord operator + (struct cord obj) {
		struct cord pl;
		pl.x = this->x + obj.x;
		pl.y = this->y + obj.y;
		return pl;
	}
	struct cord operator - (struct cord obj) {
		struct cord pl;
		pl.x = this->x - obj.x;
		pl.y = this->y - obj.y;
		return pl;
	}
	long operator * (struct cord obj) {
		return this->x*obj.x+this->y*obj.y;
	}
};
struct cord A[100];
struct cord mlmax[100];

long double vlen(struct cord);
long double rad(struct cord);

int v_cmp(const void *a, const void *b) {
	struct cord *pa, *pb;
	pa = (struct cord *)a; pb = (struct cord *)b;
	if (pa->r > pb->r) return 1;
	else if (pa->r < pb->r) return -1;
	return 0;
}

long double pi;
int main()
{
	int i;
	int from,to,end;
	long double lmx,ll,lp;
	struct cord pos;
	struct cord lmax();

	pi = atan2(0, -1);

    cin >> N;
	for (i=0; i<N; i++) {
		cin >> A[i].x >> A[i].y;
		A[i].r = rad(A[i]);
		A[i].idx = i;
//printf("(%ld,%ld)/%Lf\n", A[i].x, A[i].y, A[i].r);
	}

	qsort(A, N, sizeof(struct cord), v_cmp);
//	for (i=0; i<N; i++) printf("(%ld,%ld)/%Lf (%d)\n", A[i].x, A[i].y, A[i].r,A[i].idx);

	lmx = 0; lp = 0;
	pos.x=0; pos.y=0;

	for (from=0; from<N; from++) {
		pos.x=0; pos.y=0;
		lp = 0;
		for (to=from; to<from+N; to++) {
			pos = pos + A[to%N];
			ll = vlen(pos);
			if (ll<lp) break;
#ifdef DEBUG
printf("(%ld,%ld) ", pos.x, pos.y);
#endif
			lp = ll;
		}
		if (lp > lmx) lmx = lp;
#ifdef DEBUG
printf("pos.len=%Lf [%d]\n", lp, from);
#endif
	}

//    cout << sqrt((long double)lmax(0, A[0])) << endl;
    printf("%.40Lf\n", lmx);
    return 0;
}

long double rad(struct cord v) {
	long double ret = atan2((long double)v.y, (long double)v.x);
	if (ret < 0) 
		return pi*2 + ret;
	else
		return ret;
}
long double _rad(struct cord v) {
	if (v.x > 0) {
		if (v.y > 0) { // 第1象限
			return v.y/vlen(v);
		} else if (v.y < 0) { // 第4象限
			return 4 + v.y/vlen(v);
		}
		return 0; // 第1象限と第4象限の間のX軸上
	}
	if (v.x == 0) {
		if (v.y > 0) { // 第1象限と第2象限の間のY軸上
			return 1;
		} else if (v.y < 0) { // 第3象限と第4象限の間のY軸上
			return 3;
		}
		return 0; // 原点
	}
	if (v.x < 0) {
		if (v.y == 0) return 2; // 第2象限と第3象限の間のY軸上
		// 第2象限 or 第3象限
		return 2 - v.y/vlen(v);
	}
}

struct cord lmax() {
	long vs;
	long lm;

	lm = 0;
	for (int i=0; i<N; i++) {
#ifdef DEBUG
	printf("vsum(%d) = %ld (%ld)\n", i, vs, lm);
#endif
		if (vs>lm) lm = vs;
	}
//	return lm;
}
long double vlen(struct cord pos) {
	long double vlen2;
	vlen2 = pos.x*pos.x+pos.y*pos.y;
	return sqrt(vlen2);
}
/*
  A[i]に対して内積が正の物だけの合計が、A[i]を使った最大値となる
*/


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int i,j;
  int n;
  int a[100];
  int min,max;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  min=a[0];max=a[0];
  for(i=1;i<n;i++){
    if(min>a[i])
      min=a[i];
    if(max<a[i])
      max=a[i];
  }
  printf("%d\n",max-min);
  return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

bool check(int v) {
  stringstream ss;
  ss << v;
  string tmp;
  ss >> tmp;
  REP(i,1,(int)tmp.size()) {
    if( tmp[i-1]+1 != tmp[i] ) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N) cin >> vec[i];
  int maxi = -1;
  rep(i,N) {
    REP(j,i+1,N) {
      int tmp = vec[i] * vec[j];
      if( check(tmp) ) {
        maxi = max(maxi,tmp);
      }
    }
  }
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 3184
///
// File:  alds1_11_d.cpp
// Author: ymiyamoto
//
// Created on Wed Oct 18 01:18:32 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

#define SIZE 100000
static vector<uint32_t> graph[SIZE];
static vector<int32_t> colors(SIZE, -1);

static void dfs(uint32_t index, uint32_t color)
{
  colors[index] = color;

  for (uint32_t i = 0; i < graph[index].size(); i++) {
    uint32_t to = graph[index][i];
    if (colors[to] == -1) {
      dfs(to, color);
    }
  }
}

int32_t main()
{
  uint32_t n, m;
  cin >> n >> m;

  for (uint32_t i = 0; i < m; i++) {
    uint32_t from, to;
    cin >> from >> to;
    graph[from].push_back(to);
    graph[to].push_back(from);
  }

  for (uint32_t i = 0; i < n; i++) {
    if (colors[i] == -1) {
      dfs(i, i);
    }
  }

  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    uint32_t from, to;
    cin >> from >> to;
    if (colors[from] == colors[to]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 0 and !(a % 3 == 0 or a % 5 == 0)) {
            puts("DENIED");
            return 0;
        }
    }
    puts("APPROVED");
    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N = r.i();
        int[] A = r.ii();
        long sum = 0;
        int min = Integer.MAX_VALUE;
        int minus = 0;
        for(int a : A){
            if(a < 0){
                minus++;
                a = -a;
            }
            sum += a;
            if(a < min)
                min = a;            
        }
        println(minus%2 == 0 ? sum : sum-2*min);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

using namespace std;

int i;
char s[105];

int main(){
	scanf("%s", s);
	int l = strlen(s);
	
	int cnt = 0;
	for(i = 0; i < l; i++){
		if(cnt == 0 && s[i] == 'C')
		cnt++;
		if(cnt == 1 && s[i] == 'F')
		cnt++;
	}
	
	if(cnt == 2)
	printf("Yes\n");
	else
	printf("No\n");
	 
}


Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let n = match iter.next().unwrap().parse::<i32>() {
		Ok(m) => m,
		_ => panic!(""),
	};
	let k = match iter.next().unwrap().parse::<i32>() {
		Ok(m) => m,
		_ => panic!(""),
	};
	
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	//let mut h = Vec::new();
	let mut cnt = 0;
	for a in 0..n {
		let hi = match iter.next().unwrap().parse::<i32>() {
			Ok(m) => m,
			_ => panic!(""),
		};
		if hi >= k {
			cnt = cnt + 1;
		}
	}
	println!("{}", cnt);
	
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

constexpr int MAX_N = 50;

int dist[MAX_N][MAX_N];

int base_dist[MAX_N];
vector<int> ans;

void rec(const vector<int> &nodes, bool is_root = true) {
	if(nodes.size() == 1) {
		if(is_root) --base_dist[nodes.front()];
		for(int i = 0; i < base_dist[nodes.front()]; ++i) {
			ans.emplace_back(2);
		}
		return;
	}

	vector<vector<int>> subtree;
	for(const auto &v : nodes) {
		for(auto &vec : subtree) {
			const int u = vec.front();
			const int d = dist[v][u] - (base_dist[v] + base_dist[u]);
			if(d < 0) {
				vec.emplace_back(v);
				goto next;
			}
		}

		subtree.emplace_back(vector<int>{v});
	next:;
	}

	for(const auto &v : nodes) {
		--base_dist[v];
	}

	for(const auto &e : subtree) {
		rec(e, false);
	}

	if(!is_root) ans.emplace_back(subtree.size() + 1);
}

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

	for(int n; cin >> n && n;) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				cin >> dist[i][j];
			}
		}

		const int base = 0;

		vector<int> nodes;
		nodes.reserve(n - 1);

		for(int v = 1; v < n; ++v) {
			base_dist[v] = dist[base][v];
			nodes.emplace_back(v);
		}

		ans.clear();

		rec(nodes);

		sort(ans.begin(), ans.end());
		for(unsigned i = 0; i < ans.size(); ++i) {
			cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int n;
map<int, int> mp;

int main()
{
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        v[i] = make_pair(0, i + 1);
    }
    for (int i = 0; i < n * (n - 1) / 2; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        if (c == d)
            v[a].first++, v[b].first++;
        else if (c < d)
            v[b].first += 3;
        else
            v[a].first += 3;
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < v.size(); i++)
    {
        if (mp[v[i].first] == 0)
        {
            mp[v[i].first] = i + 1;
            a[v[i].second - 1] = i + 1;
        }
        else
            a[v[i].second - 1] = mp[v[i].first];
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//printf("myco\n");//for debug
/*--------------------------------------------*/

int main(){
    int n;cin>>n;
    vector<vector<int>> happy(n,vector<int>(3));
    vector<vector<int>> dp(n,vector<int>(3));
    rep(i,n){
        rep(j,3){
            cin>>happy[i][j];
        }
    }
    //dp[i][j]:i日めにjを選んだときの幸福度のmax
    rep(j,3){
        dp[0][j]=happy[0][j];
    }
    for(int i=1;i<n;i++){
        rep(sentinental,3){
            rep(j,3){
                if(j==sentinental)continue;
                dp[i][j]=max(dp[i-1][sentinental]+happy[i][j],dp[i][j]);
            }        
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 11136
from collections import deque

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

for i in range(q):
    b, m, e = map(int, input().split())
    s = a[b:e]
    a = a[:b] + s[m - b:] + s[:m - b] + a[e:]

print(*a)




Measured memory_bytes: 6204
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  ll x = 0, y = 0;
  for (ll i = 0; i < n; i++){
    ll t, a;
    cin >> t >> a;
    
    if (i == 0){
      x = t;
      y = a;
    }
    else {
      ll m = max((x + t - 1)/t, (y + a - 1)/a);
      x = m*t;
      y = m*a;
    }
  }
  cout << x + y << endl;

  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    x-=z;
    cout << x/(y+z)<<endl;

    return 0;
}

Measured memory_bytes: 256
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	char ch;
	cin>>ch;
	if(ch>='a' && ch<='z')
	{
		cout<<'a'<<endl;
	}
	else
	{
		cout<<'A'<<endl;
	}
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3640
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

struct SegTree(T)
{
	T delegate(const(T), const(T)) f;
	T[] data;
	T init;
    this(T[] _data, T delegate(const(T), const(T)) _f, T _init)
    {
		f = _f; init = _init;
		size_t n = 1; while (n < _data.length) n *= 2; data.length = n*2-1;
		foreach (i; 0.._data.length) data[i+n-1] = _data[i];
		foreach (i; _data.length..n) data[i+n-1] = _init;
		foreach_reverse (i; 0..n-1) data[i] = f(data[i*2+1], data[i*2+2]);
	}
    T query(size_t l, size_t r) const
	{
        size_t n = (data.length+1) / 2; l += n-1; r += n-1; T res = init;
        while (l < r)
		{
            if ((l & 1) == 0) res = f(res, data[l]);
            if ((r & 1) == 0) res = f(res, data[r-1]);
            l = l/2; r = (r-1)/2;
        }
        return res;
    }
	void update(size_t i, T v)
	{
		i += (data.length+1) / 2 - 1; data[i] = v;
		while (i != 0) { i = (i-1)/2; data[i] = f(data[i*2+1], data[i*2+2]); }
    }
}

void main()
{
	auto N = RD;
	auto Q = RD;
	auto a = RDA;
	auto st = new SegTree!(long)(a, (in long x, in long y)=>x+y, 0);
	foreach (i; 0..Q)
	{
		auto t = RD;
		if (t == 0)
		{
			auto p = RD;
			auto x = RD;
			auto last = st.query(p, p+1);
			st.update(p, last+x);
		}
		else
		{
			auto l = RD;
			auto r = RD;
			debug writeln(st.data);
			writeln(st.query(l, r));
		}
	}
	
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 46572
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const double PI=3.14159265358979323846;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    double r;
    cin >> r;

    cout << fixed << setprecision(20) << r * 2 * PI << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int n, k; cin >> n >> k;
  int ma = (n - 1) * (n - 2) / 2;
  if (ma < k) { cout << -1 << '\n'; return; }
  vector<vector<int>> edges(n);
  rep(i, n - 1) {
    edges[0].push_back(i + 1);
  }
  if (ma == k) {
    cout << n - 1 << '\n';
    rep(i, n) each(e, edges[i]) {
      cout << i + 1 << " " << e + 1 << '\n';
    }
    return;
  }
  int m = n - 1;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      edges[i].push_back(j);
      m++, ma--;
      if (k == ma) break;
    }
    if (k == ma) break;
  }
  cout << m << '\n';
  rep(i, n) each(e, edges[i]) {
    cout << i + 1 << " " << e + 1 << '\n';
  }
}


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

using namespace std;

using int64 = long long;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


int main() {
  int H, W;
  cin >> H >> W;
  string S[400];
  for(int i = 0; i < H; i++) cin >> S[i];
  UnionFind uf(H * W);
  const int vy[] = {1, 0, -1, 0};
  const int vx[] = {0, 1, 0, -1};
  int b[400 * 400] = {};
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      for(int k = 0; k < 4; k++) {
        int ni = i + vy[k], nj = j + vx[k];
        if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
        if(S[i][j] != S[ni][nj]) {
          uf.unite(i * W + j, ni * W + nj);
        }
      }
    }
  }

  int64 ret = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      b[uf.find(i * W + j)] += S[i][j] == '#';
    }
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(uf.find(i * W + j) == i * W + j) {

        int a = b[i * W + j];
        int c = uf.size(i * W + j) - a;

        ret += 1LL * a * c;
        //ret += 1LL * c * (a - 1) / 2;

      }
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 1001

int main(int argc, char const *argv[]) {
    int N, i;
    input_i(N);
    int A[N], B[N], C[N - 1];
    for(i= 0; i < N; i++) {
        input_i(A[i]);
        A[i]--;
    }
    for(i= 0; i < N; i++) {
        input_i(B[i]);
    }
    for(i= 0; i < N - 1; i++) {
        input_i(C[i]);
    }
    int ans= 0, buf= -1;
    for(i= 0; i < N; i++) {
        ans+= B[A[i]];
        if(A[i] - buf == 1) ans+= C[buf];
        buf= A[i];
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
"use strict";

const Main = args => {
  const input = args.trim().split("\n");
  const N = input[0].split(" ")[0] - 0
  const L = input[0].split(" ")[1] - 0

  let sList = input.slice(1).sort((a, b) => {
    a = a.toString().toLowerCase();
    b = b.toString().toLowerCase();
    if (a < b) {
      return -1;
    } else if (a > b) {
      return 1;
    }
    return 0;
  });

  console.log(sList.join(''));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <stdio.h>
#define N 100001
typedef long long LL;

int a[N];

int read()
{
	char c;
	while((c = getchar()) < 48 || c > 57);
	int x = c - 48;
	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;
	return x;
}

LL gcd(LL x, LL y)
{
	LL t;
	while(y){
		t = x;
		x = y;
		y = t % y;
	}
	return x;
}

LL lcm(LL l, LL x)
{
	return l / gcd(l, x) * x;
}

int main()
{		
	int n, m, i, x, b, f = 1, y;
	LL l, ans;
	
	n = read(), m = read();
	x = read(), b = 1;
	while(x % 2 == 0) x >>= 1, b <<= 1;
	a[0] = x;
	for(i = 1; i < n; i++){
		x = read();
		if(!f) continue;
		if(x % b) f = 0;
		else if((y = x / b) % 2 == 0) f = 0;
		a[i] = y;
	}
	if(!f){
		puts("0");
		return 0;
	}
	m /= (b / 2), ans = m;
	for(i = 1, l = a[0]; i < n; i++){
		l = lcm(l, (LL)a[i]);
		if(l > m) break;
	}
	ans /= l;
	ans = (ans + 1) >> 1;
	printf("%lld\n", ans);
			
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void){
    long int N;
    long int D;
    long int n;
    double a;
    double b;
    double x,y;
    int c=0;
    int X[1000000];
    int Y[1000000];

    scanf("%ld",&N);
    //printf("%d",N);
    scanf("%ld",&D);
    //printf("%d",D);
    for(n=0;n<=N-1;n++){

        scanf("%d",&X[n]);
        scanf("%d",&Y[n]);
        //printf("X=%d\n",X[n]);
        //printf("Y=%d\n",Y[n]);
    }
    for(n=0;n<=N-1;n++){
        x=X[n];
        y=Y[n];
        a=pow(x,2.0)+pow(y,2.0);
        //printf("a=%lf\n",a);
        b=sqrt(a);
        //printf("b=%lf\n",b);
        if(b<=D){
            c++;
        }
    }
    printf("%d",c);
   return 0;
}

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

using ll = long long;
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << string(b, '0' + a) << endl;
    } else {
        cout << string(a, '0' + b) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define NIL -1
#define MAX 100001

// left-child, right-sibling representation
struct Node {
    int p, l, r;
};

Node T[MAX];
int D[MAX];

// Set depth for each node using recursion
void setDepth(int id, int d) {
    D[id] = d;
    if (T[id].l != NIL) setDepth(T[id].l, d+1);
    if (T[id].r != NIL) setDepth(T[id].r, d); 
}

void printTree(int n) {
    int i, j, c;

    for (i=0; i < n; i++) {
        cout << "node " << i << ": ";
        cout << "parent = " << T[i].p << ", ";
        cout << "depth = " << D[i] << ", ";

        if (T[i].p == NIL) cout << "root, ";
        else if (T[i].l == NIL) cout  << "leaf, ";
        else cout << "internal node, ";

        cout << "[";
        if (T[i].l != NIL) {
            c = T[i].l;
            for (j=0; c != NIL; j++) {
                if (j != 0) cout << ", ";
                cout << c;
                c = T[c].r;
            }
        }
        cout << "]" << endl;
    }
}

int main() {
    int n, id, k, c, pc, r, i, j;

    cin >> n;
    for (i=0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
    
    for (i=0; i < n; i++) {
        cin >> id >> k;
        for (j=0; j < k; j++) {
            cin >> c;
            if (j == 0) {
                T[id].l = c;
            } else {
                T[pc].r = c;
            }
            T[c].p = id;
            pc = c;
        }

    }
    for (i=0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    setDepth(r, 0);
    printTree(n);

    return 0;
}


Measured memory_bytes: 4640