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

int main()
{
    int N,Y;
    cin >> N >> Y;
    
    bool answerExists = false;

    for(int a=0;a<=N;a++){
        for(int b=0;b<=N-a;b++){
            int c = N - a - b;
            if(a*10000 + b*5000 + c*1000 ==Y){
                cout << a << " " << b << " " << c << endl;
                answerExists = true;
                break;
            }
        }
        if(answerExists) break;
    }

    if(!answerExists) cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N, W = map(int, input().split())
    max_val = 10 ** 5
    dp = [[float('inf')]*(max_val + 1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(1, N+1):
        w, v = map(int, input().split())
        for j in range(max_val + 1): # 価値がj以上になるときの最小の重さを選ぶ
            if j - v < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min([
                    dp[i-1][j-v] + w,
                    dp[i-1][j]
                ])

    for i, w in enumerate(reversed(dp[-1])):
        if w <= W:
            print(max_val - i)
            exit()


if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define debug 1

struct num {
	char c[100];
	
	void operator +=(const num a) {
		for(int i=0;i<100;i++) {
			c[i]+=a.c[i];
			while(c[i]>=10) {
				c[i]-=10;
				c[(i+1)]+=1;
			}
		}
	}
	
	num operator *(num a) const{
		num ans;
		memset(&ans,0,sizeof(ans));
		int l=99,la=99;
		while(c[l]==0) l--;
		while(a.c[la]==0) la--;
		for(int i=0;i<=l;i++)
			for(int j=0;j<=la;j++) {
				int now=c[i]*a.c[j];
				ans.c[i+j]+=now%10;
				while(ans.c[i+j]>10) {
					ans.c[i+j]-=10;ans.c[i+j+1]++;
				}
				ans.c[i+j+1]+=now/10;
				while(ans.c[i+j+1]>10) {
					ans.c[i+j+1]-=10;
					ans.c[i+j+2]+=1;
				}
			}
		return ans;
	}
};

num change(long long n) {
	num ans;
	memset(&ans,0,sizeof(ans));
	int m=0;
	
	while(n) {
		ans.c[m]+=(n%10);
		n/=10;
		m++;
	}
	return ans;
}

int main() {
	int k,a,b;
	cin>>k>>a>>b;
	
	if(a-k<=(-1) && b-a>2) {
		int c=b-a;
		num cc=change(c);
		num now=change(a);
		int i=k-(a-1);
		num mul1=change(i/2);
		num mul=mul1*cc;
		now+=mul;
		if(i%2==1) {
			num one=change(1);
			now+=one;
		}
		int m=99;
		while(now.c[m]==0) m--;
		while(m>=0) {
			cout<<(int)now.c[m];
			m--;
		}
		cout<<endl;
	}
	else cout<<(k+1)<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll e = b/c - (a-1)/c;
  ll f = b/d - (a-1)/d;
  ll lcm = (c*d)/gcd(c,d);
  ll g = b/lcm - (a-1)/lcm;
  ll h = e+f-g;
  //printf("%d %d %d %d\n",e,f,g,h);
  cout << b-a+1-h << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll K,N;
ll ans;
string S;
ll a;
ll A[100001];
ll H,M,HH,MM;
ll now;
ll INF = 1e18;
 
int main(){
    cin >> N;
    ans = 1;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i=0;i<N;i++){
        if(A[i]>INF/ans){
            cout << -1 << endl;
            return 0;
        }else{
            ans*=A[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000009;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

Vi v[200002];
int a[200002];
int ans[200002];
Vi vv;
void dfs(int N,int p=-1)
{
	int t=lower_bound(ALL(vv),a[N])-vv.begin(),pre=-1;
	bool ok=0;
	if(t==vv.size())
	{
		ok=1;
		vv.pb(a[N]);
	}
	else
	{
		pre=vv[t];
		vv[t]=a[N];
	}
	ans[N]=vv.size();
	for(int next:v[N])
	{
		if(next==p)continue;
		dfs(next,N);
	}
	if(ok)vv.pop_back();
	else vv[t]=pre;
}
int main() {
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%d",a+i);
	fup(i,1,n-1,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1);
	fup(i,1,n,1)printf("%d\n",ans[i]);
}

Measured memory_bytes: 30608
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((a (read))
         (b (read))
         (c (read))
         (x (read))
         (y (read)))
    (declare (uint31 a b c x y))
    (println
     (loop for r from 0 to (* 2 (max x y))
           for p = (max 0 (- x (floor r 2)))
           for q = (max 0 (- y (floor r 2)))
           minimize (+ (* a p) (* b q) (* c r)) of-type fixnum))))

#-swank(main)


Measured memory_bytes: 18400
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;

const int N=105;
const int inf=1000000000;

struct node{
	int x,y,b;
	node(){}
	node(int x,int y,int b):x(x),y(y),b(b){}
};
int n,m;
int dp[N][N][2],dx[2]={1,0},dy[2]={0,1};
char c[N][N];
deque<node> q;

void solve(){
	int i,j,x,y; node now;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++) dp[i][j][0]=dp[i][j][1]=inf;
	if (c[1][1]=='.'){
		dp[1][1][0]=0;
		q.push_front(node(1,1,0));
	}
	else{
		dp[1][1][1]=1;
		q.push_back(node(1,1,1));
	}
	while (!q.empty()){
		now=q.front(); q.pop_front();
		for (i=0;i<2;i++){
			x=now.x+dx[i]; y=now.y+dy[i];
			if (x<1||x>n||y<1||y>m) continue;
			if (c[x][y]=='.'&&dp[x][y][0]>dp[now.x][now.y][now.b]){
				dp[x][y][0]=dp[now.x][now.y][now.b];
				q.push_front(node(x,y,0));
			}
			if (c[x][y]=='#'){
				if (now.b==1&&dp[x][y][1]>dp[now.x][now.y][now.b]){
					dp[x][y][1]=dp[now.x][now.y][now.b];
					q.push_front(node(x,y,1));
				}
				if (now.b==0&&dp[x][y][1]>dp[now.x][now.y][now.b]+1){
					dp[x][y][1]=dp[now.x][now.y][now.b]+1;
					q.push_back(node(x,y,1));
				}
			} 
		}
	}
}

int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%s",c[i]+1);
	solve();
	printf("%d\n",min(dp[n][m][0],dp[n][m][1]));
	return 0;
} 

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, ans = 0; cin >> n;
  string s; cin >> s;
  char c = '-';
  rep(i,n) {
    if (s[i] != c) {
      ans++;
      c = s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
class Node:
    def __init__(self):
        self.child = [None] * 26
        self.counts = [0] * 26

    # def add(self, s, bucket, idx_s):
    #     c = s[idx_s]
    #     if self.child[c] is None:
    #         self.child[c] = Node()
    #     for i, cnt in enumerate(bucket):
    #         if cnt:
    #             self.counts[i] += 1
    #     bucket[c] -= 1
    #     if idx_s >= 1:
    #         self.child[c].add(s, bucket, idx_s - 1)
    #     else:
    #         Leaves.append(self.counts)

    def add(self, s, bucket):
        node = self
        for idx_s, c in zip(range(len(s)-1, -1, -1), s[::-1]):
            if node.child[c] is None:
                node.child[c] = Node()
            for i, cnt in enumerate(bucket):
                if cnt:
                    node.counts[i] += 1
            bucket[c] -= 1
            if idx_s > 0:
                node = node.child[c]
        Leaves.append(node.counts)

    # def get(self, s, idx_s):
    #     c = s[idx_s]
    #     if idx_s > 0:
    #         return self.child[c].get(s, idx_s-1)
    #     else:
    #         return self.counts[c]

Leaves = []
trie = Node()
N = int(input())
S = [[ord(c)-97 for c in input()] for _ in range(N)]
for s in S:
    b = [0] * 26
    for c in s:
        b[c] += 1
    trie.add(s, b)
ans = -N
# for s in S:
#     ans += trie.get(s, len(s)-1)
for s, l in zip(S, Leaves):
    ans += l[s[0]]
print(ans)


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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int tmp = i;
        int sum = 0;
        while (tmp != 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (A <= sum && sum <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,x; cin>>n;
	vector<map<int,int>> ct(2);
	for (int i=0; i<n; i++)
		cin>>x,
		ct[i%2][x]++;
	vector<priority_queue<ii>> pq(2);
	for (int i=0; i<2; i++)
		for (auto it : ct[i])
			pq[i].push({it.second, it.first});
	vector<vector<ii>> a(2);
	for (int i=0; i<2; i++) {
		while(!pq[i].empty())
			a[i].push_back(pq[i].top()), pq[i].pop();
		a[i].push_back({0, -1});
	}

	if(a[0][0].second!=a[1][0].second)
		cout << n-a[0][0].first-a[1][0].first << endl;
	else
		cout << n-max(a[0][0].first+a[1][1].first, a[0][1].first+a[1][0].first) << endl;
	return 0;
}


Measured memory_bytes: 6908
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int j,k,l;
    j=a+b;
    k=b+c;
    l=a+c;
    if(j<=k&&j<=l)
    {
        printf("%d",j);
    }
    else if(k<=j&&k<=l)
    {
        printf("%d",k);
    }
    else
    {
        printf("%d",l);
    }
}


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

ll n,k,a;
vector<ll> V;

bool solve(ll z) {
    ll cnt=0;
    for (auto e : V) {
        cnt+=((e-1)/z);
    }
    if (cnt<=k) return true;
    return false;

}

int main() {
    ll lo=1,hi=1000000001,mid;
    cin >> n >> k;
    for (ll i=0;i<n;i++) {
        cin >> a;
        V.push_back(a);
    }

    while(lo<hi) {
        mid=(lo+hi)/2;
        if (!solve(mid)) {lo=mid+1;}
        else {hi=mid;}
    }

    if (solve(lo)) {cout << lo;}
    else {cout << lo+1;}
//    cout << lo << endl;



}


Measured memory_bytes: 5276
package main

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

func main() {
	W := readf()
	H := readf()
	x := readf()
	y := readf()

	var ans float64 = W * H / 2
	if W/2 == x && H/2 == y {
		fmt.Printf("%f %d\n", ans, 1)
		return
	}
	fmt.Printf("%f %d\n", ans, 0)
}

/*-------------------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 permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

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

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

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

/*-------------------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: 640
n = int(input())
d=[]

for i in range(n):
    s,p = input().split()
    p = int(p)
    d.append([s,p,i])

d_ = sorted(d, key=lambda x:(x[0], -x[1]))

for i in range(n):
    print(d_[i][2]+1)

Measured memory_bytes: 3060
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	// ans := solve(n)
	ans := solve2(n)
	io.Println(ans)
}

// O(n^2 log n) -> TLE

// O(n log n)
func solve2(n int) (ans int) {
	counts := make([]int, n+1)
	for i := 1; i <= n; i++ {
		for j := i; j <= n; j += i {
			counts[j]++
		}
	}
	for i, v := range counts {
		ans += i * v
	}
	return ans
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 82508
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include <numeric>
#include<vector>

#define LL long long
#define MOD 1000000007

using namespace std;

LL gcd(LL C, LL D) {
	if (C < D) gcd(D, C);

	if (C%D == 0)return D;
	else gcd(D, C%D);
}


int main() {

	int N;
	cin >> N;
	vector<LL> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	for (int i = 0; i < N-1; i++) {
		if (A[i] == A[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}





Measured memory_bytes: 1792
#include <stdio.h>
int main(){
    int c1,c5,c10,c50,c100,c500;
    int daikin,oturi,maisuu;
    while(1){
    scanf("%d\n",&daikin);
    if(daikin==0)break;
    
    oturi=1000-daikin;
    
    c500=oturi/500;
    c100=oturi%500/100;
    c50 =oturi%500%100/50;
    c10 =oturi%500%100%50/10;
    c5  =oturi%500%100%50%10/5;
    c1  =oturi%500%100%50%10%5;
    
    maisuu=c1+c5+c10+c50+c100+c500;
    
    printf("%d\n",maisuu);
    }
    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < w+2; ++i) {
        cout << '#';
        if(i == w+1) cout << endl;
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(j == 0) cout << '#';
            cout << a[i][j];
            if(j == w-1) cout << '#' << endl;
        }
    }
    for (int i = 0; i < w+2; ++i) {
        cout << '#';
        if(i == w+1) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
https://atcoder.jp/contests/abc131/submissions/6085086
*/
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

ll f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main() {
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

string s;

int main() {
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>s;
    if(s == "AAA" || s == "BBB") {
    	cout<<"No"<<endl;
	}else {
		cout<<"Yes"<<endl;
	}
    /* end code */
	return 0;
}

Measured memory_bytes: 768
S=list(input())

ans = 'AC'

#条件１
if S[0] != 'A':
    ans = 'WA'

#条件2
C_cnt=0
for s in S[2:-1]:
    if s=='C':
        C_cnt+=1
    
if C_cnt != 1:
    ans = 'WA'
    
#条件3
Up_cnt=0
for s in S:
    if s.isupper()==True:
        Up_cnt+=1
if Up_cnt != 2:
    ans = 'WA'
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n,x;cin>>n>>x;
	int a[n];

	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int cnt=0;
	for(int i=0;i<n;i++){
		x-=a[i];
		cnt++;
		if(x<0) {
			cnt--;
			break;
		}
		if(i==n-1&&x>0){
			cnt--;
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL int
#define int long long
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
int n,x,y,ans,sum,ff;
signed main(){
	n=read();sum=1e15;ff=0;
	for (int i=1;i<=n;i++){
		x=read();y=read();if (x!=y)ff=1;ans+=x;if (x>y)sum=min(sum,y);
	}if (!ff)writeln(0);else writeln(ans-sum);
}

Measured memory_bytes: 256
import Data.Functor
import Data.List
import Data.Maybe

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print $ solve n s

solve :: Int -> String -> Int
solve n s = fromMaybe n m
  where
    m = snd <$> find ((== "xx") . fst) (zip (zipWith (\a b -> [a, b]) s (tail s)) [1..])

Measured memory_bytes: 8064
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

long[9] cost = [2, 5, 5, 4, 5, 6, 3, 7, 6];
bool[9] canuse;
void main()
{
    long N, M;
    scan(N, M);
    auto A = aryread();
    foreach (a; A)
        canuse[a - 1] = true;
    foreach (i; 0 .. 9)
        foreach (j; 0 .. i)
            if (canuse[i] && cost[i] == cost[j])
                canuse[j] = false;
    writeln(solve(N));
}

string solve(long N)
{
    // writeln(N);
    if (N == 0)
    {
        return null;
    }
    if (N < 2)
    {
        return "e";
    }
    string result = "0";
    loop: foreach (i; 0 .. 9)
        if (canuse[i] && 0 <= N - cost[i])
        {
            string t = memoize!solve(N - cost[i]);
            // writeln(t);
            if (t != "e")
            {
                string s = cast(char)(i + '1') ~ t;
                if (result.length < s.length)
                {
                    result = s;
                    continue loop;
                }
                if (result.length == s.length)
                {
                    if (result[0] < s[0])
                    {
                        result = s;
                        continue loop;
                    }
                    if (BigInt(result) < BigInt(s))
                    {
                        result = s;
                    }
                }
                // auto b = BigInt(s);
            }
        }
    return result == "0" ? "e" : result.to!string;
}


Measured memory_bytes: 84988
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    string s; cin >> s;
    string first ;
    string last;
    rep(i,n/2) {
        first += s[i];
    }
    FOR(i,n/2,n-1){
        last += s[i];
    }
    if (first == last) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main()
{
  int N,K;
  cin>>N>>K;
  int a=1;
  int A;
  for(int i=0;i<N;i++){
    a*=2;
    if(a>K){
      A=i+1;
      break;
    }
    A=i+1;
  }
  for(int i=0;i<N-A;i++){
    a+=K;
  }
  cout<<a;
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var A = s[0];
            var B = s[1];
            var K = s[2];

            if (K < A)
            {
                Console.WriteLine("{0} {1}", A - K, B);
            }
            else if (A <= K && K < A + B)
            {
                Console.WriteLine("{0} {1}", 0, B - (K - A));
            }
            else if (A + B <= K)
            {
                Console.WriteLine("0 0");
            }
        }
    }
}


Measured memory_bytes: 13268
function kanashimi(N,A,b)
  
  ret = 0
  
  for i in 1:N
  	ret += abs(A[i] - (b+i)) 
  end
  
  return ret

end

function main()
  
  N = parse(Int,readline())
  A = map(x -> parse(Int,x), split(readline()))
  A2 = zeros(Int,N)
  for i in 1:N
    A2[i] = A[i]
  end
  B = zeros(Int,N)
  
  for i in 1:N
    B[i] = A[i] - i
  end
  
  b = median(B)

  println(Int(kanashimi(N,A,b)))
  
end

main()

Measured memory_bytes: 154556
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <deque>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    long long A, B, K;
    cin >> A >> B >> K;

    long long ansA = max(0LL, A - K);
    long long ansB = max(0LL, min(B, (A + B) - K));

    cout << ansA << ' ' << ansB << endl;

    return 0;
}


Measured memory_bytes: 888
n = int(input())
h = [int(i) for i in input().split()]

dp = [0, abs(h[1] - h[0])] + [float('inf')] * (n - 2)

for i in range(2, n):
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]))

print(dp[n - 1])


Measured memory_bytes: 13928
import math
import copy




def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l

a=nCast(input())
b=nCast(input().split())


def help(max):
    count=0
    tmp=0
    for idx in range(0,len(b)):
        if b[idx]==max:
            b[idx]=b[idx]-1
            if tmp==0:
                tmp=1
        else:
            if tmp==1:
                tmp=0
                count+=1

    return tmp+count

def func():
    result=0
    max=100
    while max!=0:
        result+=help(max)
        max-=1
    return result
print(func()) 







Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
string s,t;
long long n,m,l;
int main()
{
	cin>>n>>m>>s>>t;
	l=n*m/__gcd(n,m);
	for(int i=0;i<n;i++)
		if(i*m%n==0&&s[i]!=t[i*m/n])
		{
			cout<<-1;
			return 0;
		}
	cout<<l;
	return 0; 
}

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

using namespace std;

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

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

    if ((A <= C && C <= B) || (A >= C && C >= B))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,k;
  cin >> n >> k;
  int sum = (n-2)*(n-1)/2;
  vector<vbool> ans(n,vbool(n));
  rep(j,1,n){
    ans[0][j] = true;
  }
  if(k > (n-2)*(n-1)/2){
    cout << -1 << endl;
    return 0;
  }
  int num = 1;
  int plus = 1;
  int time = sum - k;
  while(time > 0 && num != n){
    // cout << num << " " << plus << endl;
    ans[num][num+plus] = true;
    plus++;
    time--;
    if(num + plus == n){
      num++;
      plus = 1;
    }
  }
  int aaa = 0;
  rep(i,0,n) rep(j,0,n) if(ans[i][j]) aaa++;
  cout << aaa << endl;
  rep(i,0,n){
    rep(j,0,n){
      if(ans[i][j]) cout << i + 1 << " " << j + 1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
#define mod 1000000007
#define int long long
using namespace std;

int S[100001];//n!をiで割った数
int T[100001];//累積和
int p(int a, int b) {//xのy乗
	int c = 1;
	while (b > 1) {
		if (b & 1) {
			c *= a;
			c %= mod;
		}
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return a*c%mod;
}
signed main() {
	int n; cin >> n;
	int k = 1;
	for (int i = 2; i <= n; i++) {
		k *= i;
		k %= mod;
	}
	for (int i = 1; i <= n; i++) {
		S[i] = k*p(i, mod - 2)%mod;
		T[i] = T[i - 1] + S[i];
		T[i] %= mod;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		ans += a*((T[i + 1] + T[n - i] - T[1]) % mod);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
<?php

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

function c($x, $c)
{
    if ($x % $c == 0) {
        return true;
    } else {
        return false;
    }
}

function b($x, $c, $b)
{
    if (p5($b + $c) - p5($b) == $x) {
        return true;
    } else {
        return false;
    } 
}

function p5($i)
{
    return $i * $i * $i * $i * $i;
}

$sc = new Scanner;

$x = $sc->nextInt();


for ($c = -10001; $c < 10001; $c++) {
    if ($c == 0) {
        for ($b = -10001; $b < 100001; $b++) {
            if (b($x, $c, $b)) {
                $ans_c = 0;
                $ans_b = $b;
                break 2;
            } 
            
        }
        continue;
    }
    if (c($x, $c)) {
        for ($b = -100001; $b < 100001; $b++) {
            if (b($x, $c, $b)) {
                $ans_c = $c;
                $ans_b = $b;
                break 2;
            } 
            
        }
        
    }
}

$ans_a = $ans_c + $ans_b;

$ans = $ans_a . " " . $ans_b;

out::println($ans);



?>

Measured memory_bytes: 16244
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
use std::cmp::min;
#[fastout]
fn main() {
    input! {
        n: isize,
        a: [isize; n]
    }
    let a_sum = a.iter().sum::<isize>();
    let a_ave = a_sum / n - 1;
    let a_pow = a.iter().map(|x| x * x).sum::<isize>();
    let mut score = std::isize::MAX;
    for i in 0..3 {
        score = min(
            score,
            a_pow - 2 * a_sum * (a_ave + i) + n * (a_ave + i) * (a_ave + i),
        );
    }
    println!("{}", score);
}


Measured memory_bytes: 2164
#include <algorithm>
#include <cstring>
#include <vector>
#include <iostream>
#include <complex>
#include <queue>


using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
const int MAXN = 5000;


int main() {
  LL N, M;
  scanf("%lld%lld", &N, &M);
  printf("%lld\n", (1ll << M) * ( 100 * ( N - M ) + 1900 * M));
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  int n;
  cin>>n;
  std::vector<int64_t> a(n);
  int64_t result=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  for(int i=0;i<n;i++){
    if(a[i]%2==1){
      if(i+1<n&&a[i+1]>0){
        result++;
        a[i]--;
        a[i+1]--;
      }
    }
    result+=a[i]/2;
  }
  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int difference = 0;
		    
		    int[] array = new int[N];
		    for( int i = 0; i < N; i++ ) 
		    {
		    	array[i] = scanner.nextInt();
		    }
		    Arrays.sort(array);
		    for(int i = 0; i < N; i++) 
		    {
		    	if( i % 2 == 0 ) 
		    	{
		    		difference = difference + array[N - 1 - i];
		    	}
		    	else 
		    	{
		    		difference = difference - array[N - 1 - i];
		    	}
		    }
		    
		    System.out.println(difference);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 22100
function Main(input) {
  input = input.split("\n");
  const N = input[0];
  const n = N[N.length - 1];

  if (n === '3') {
    console.log('bon');
  } else if (n === '0' || n === '1' || n === '6' || n === '8') {
    console.log('pon');
  } else {
    console.log('hon');
  }

}

// デバッグ用
function debug() {
  var input = document.getElementById("input").value;
  Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30472
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

uf_t = numba.types.UniTuple(i8[:], 2)


@njit((uf_t, i8), cache=True)
def find_root(uf, x):
    root = uf[0]
    while root[x] != x:
        root[x] = root[root[x]]
        x = root[x]
    return x


@njit((uf_t, i8, i8), cache=True)
def merge(uf, x, y):
    root, size = uf
    x, y = find_root(uf, x), find_root(uf, y)
    if x == y:
        return False
    if size[x] < size[y]:
        x, y = y, x
    size[x] += size[y]
    root[y] = root[x]
    return True

@njit((i8, i8, i8[:]), cache=True)
def main(N, Q, TUV):
    root = np.arange(N, dtype=np.int64)
    size = np.ones(N, np.int64)
    uf = (root, size)
    for i in range(Q):
        t, u, v = TUV[3 * i:3 * i + 3]
        if t == 0:
            merge(uf, u, v)
        else:
            same = find_root(uf, u) == find_root(uf, v)
            print(1 if same else 0)

N, Q = map(int, readline().split())
TUV = np.array(read().split(), np.int64)

main(N, Q, TUV)

Measured memory_bytes: 136464
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
class Tree {
public:
	int position;
	int left, right;
	Tree() {};
};
class Point {
public:
	int x, y;
	int id;
	Point(int x, int y, int id) :id(id), x(x), y(y) {};
	Point() {};
};
bool lessX(Point& a, Point& b) {
	return a.x < b.x;
}
bool lessY(Point& a, Point& b) {
	return a.y < b.y;
}
bool lessID(Point& a, Point& b) {
	return a.id < b.id;
}
static int NIL = -1;
const int MAX = 1000000;
Point p[MAX];
Tree t[MAX];
int sit = 0;
int n;
int makeTree(int left, int right, int depth) {
	if ( !(left < right)) {
		return NIL;
	}
	if (depth % 2 == 1 ) {
		sort(p + left, p + right, lessX);
	}
	else {
		sort(p + left, p + right, lessY);
	}
	int midle = (left + right) / 2;
	int k = sit;
	sit++;
	t[k].position = midle;
	t[k].left = makeTree(left, midle,depth+1);
	t[k].right = makeTree(midle + 1, right,depth+1);
	return k;
} 
void find(int k, int sx, int tx, int sy, int ty, int depth,vector<Point>&v) {
	int x = p[t[k].position].x;
	int y = p[t[k].position].y;
	if (x <= tx && sx <= x && y <= ty && sy <= y) {
		v.push_back(p[t[k].position]);
	}
	if (depth % 2 == 1) {
		if (t[k].left != NIL && x >= sx)  find(t[k].left, sx, tx, sy, ty, depth+1, v);
		if(t[k].right != NIL && x <= tx)  find(t[k].right, sx, tx, sy, ty, depth+1, v);
	}
	else {
		if (t[k].left != NIL && y >= sy)  find(t[k].left, sx, tx, sy, ty, depth+1, v);
		if (t[k].right != NIL && y <= ty)  find(t[k].right, sx, tx, sy, ty, depth+1, v);
	}
}
int main(void) {
	scanf("%d", &n);
	int x, y;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x, &y);
		p[i] = Point(x, y, i);
	}
	makeTree(0, n, 0);
	int sx,tx,sy,ty;
	int m;
	scanf("%d", &m);
	vector<Point> v;
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		v.clear();
		find(0, sx, tx, sy, ty, 0, v);
		sort(v.begin(), v.end(), lessID);
		for (int j = 0; j < v.size(); j++) {
			printf("%d\n", v[j].id);
		}
		cout << endl;
	}
}


Measured memory_bytes: 14552
#include<bits/stdc++.h>
using namespace std;
#define inf 2123333333

int fa[1010],in[1010],out[1010],n,h;
bool bo[1010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline int find(int x) { return (x==fa[x])?x:fa[x]=find(fa[x]); }

int main()
{
	n=rd();h=rd();
	for (int i=1;i<=h*2;i++) fa[i]=i;
	for (int i=1;i<=n;i++)
	{
		int h1=rd(),h2=rd(),h3=rd(),h4=rd();
		int x=(!h3)?h1:h3+h,y=(!h4)?h2+h:h4;
		out[x]++;in[y]++;
		int f1=find(x),f2=find(y);
		if (f1!=f2) fa[f1]=f2;
	}
	for (int i=1;i<=h;i++) if (in[i]>out[i]) { puts("NO");return 0; }
	for (int i=h+1;i<=h*2;i++) if (in[i]<out[i]) { puts("NO");return 0; }
	for (int i=1;i<=h*2;i++) if (in[i]^out[i]) bo[find(i)]=true;
	for (int i=1;i<=h*2;i++) if (!bo[find(i)]) if (in[i]||out[i]) { puts("NO");return 0; }
	puts("YES");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
for i in range(0, N) :
  x1,y1,x2,y2,x3,y3,x4,y4 = list(map(float, input().split()))
  s = x2 - x1
  t = y2 - y1
  u = x4 - x3
  v = y4 - y3;
  if (abs(s * v - t * u) < 1e-10) :
    print("YES")
  else :
    print("NO")

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

using namespace std;
typedef long long ll;
int n,s;
ll value[103],weight[103],f[103][100003];

void DP()
{
    f[0][0]=0;
    for(int i=1;i<=n;++i)
    {
        f[i][0]=0;
        for(int j=1;j<=s;++j)
        {
            f[0][j]=0;
            if(j-weight[i]>=0)
            {
                f[i][j]=max(f[i-1][j],f[i-1][j-weight[i]]+value[i]);
            }
            else
            {
                f[i][j]=f[i-1][j];
            }
        }
    }
    printf("%lld",f[n][s]);
}

int main()
{
    scanf("%d%d",&n,&s);
    for(int i=1;i<=n;++i)
    {
        scanf("%lld%lld",&weight[i],&value[i]);
    }
    DP();
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
#define sp(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=2e5+5;

ll a[maxn],h[maxn],n;
ll dp[maxn];
map<ll,ll> ind;

int main(){
	fastio();
	cin>>n;
	fo(i,n) cin>>h[i];
	fo(i,n) cin>>a[i];

	dp[0]=a[0];
	ind[h[0]]=dp[0];
	ll ans=dp[0];

	foo(i,1,n){
		dp[i]=a[i];
		auto it=ind.lower_bound(h[i]);
		if(it!=ind.begin()){
			it--;
			dp[i]+=it->ss;
		}
		ind[h[i]]=dp[i];
		it=ind.upper_bound(h[i]);
		while(it!=ind.end()&&it->ss<dp[i]){
			auto temp=it;
			temp++;
			ind.erase(it);
			it=temp;
		}
		ans=max(ans,dp[i]);
	}

	cout<<ans<<endl;
}


Measured memory_bytes: 20808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    P itv[m];
    rep(i, m)
    {
        cin >> itv[i].second >> itv[i].first;
    }

    sort(itv, itv + m);

    int ans = 0, cur = 0;
    rep(i, m)
    {
        if (cur <= itv[i].second)
        {
            //cout << itv[i].second << endl;
            ans++;
            cur = itv[i].first;
        }
    }
    cout << ans << endl;
}

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

#define MOD 1001
#define MAX 10001

int getfibo(int);
int root(int);
int find(int,int);
void merge(int,int);

int fibo[MAX];
int p[MAX];

int main(void)
{
  fibo[0]=1; fibo[1]=2;
  int a,d,i,j;
  
  while(scanf("%d %d",&a,&d)==2)
    {
      memset(p,-1,sizeof(p));
      
      for(i=1;i<=a;i++)
	{
	  for(j=1;j<=a;j++)
	    {
	      if(abs(getfibo(i)-getfibo(j))<d)
		{
		  if(!find(i,j))merge(i,j);
		}
	    }
	}
      int b[MAX]={0},res,c=0;
      
      for(i=1;i<=a;i++)
	{
	  res=root(i);
	  if(!b[res])
	    {
	      b[res]=1; c++;
	    }
	}
      printf("%d\n",c);
    }
  return 0;
}

int getfibo(int n)
{
  if(n<1)return 1;
  if(fibo[n])return fibo[n];
  return fibo[n]=(getfibo(n-1)+getfibo(n-2))%MOD;
}

int root(int a)
{
  return p[a]<0?a:(p[a]=root(p[a]));
}

int find(int a,int b)
{
  return root(a)==root(b);
}

void merge(int a,int b)
{
  p[root(a)]=root(b);
}

Measured memory_bytes: 500
package main

import (
	"fmt"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	
	left := 1
	right := n
	var l,r int
	for i := 0; i < m; i++ {
		fmt.Scan(&l,&r)
		if left < l {
			left = l
		}
		if r < right {
			right = r
		}
      //fmt.Printf("left=%d,right=%d\n", left, right)
	}
	if left <= right {
		fmt.Println(right - left + 1)
	} else {
		fmt.Println(0)
	}
}


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

int main()
{
    long double A, B;
    cin >> A >> B;

    std::cout << static_cast<ll>(A * B) << endl;
    return 0;
}


Measured memory_bytes: 3720
#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(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    int n;
    cin >> n;
    PRINT(1110-n);
}

Measured memory_bytes: 256