akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


const int six_dx[]={1,1,0,-1,-1,0};
const int six_dy[]={1,0,-1,-1,0,1};

int main()
{
    int t,n;
    while(cin>>t>>n,t!=0 || n!=0){
        vector<int> x(n),y(n);
        for(int i=0;i<n;i++) cin>>x[i]>>y[i];
        
        int x0,y0;
        cin>>x0>>y0;
        
        queue<pair<int,int> > q;
        map<pair<int,int>,int> vis;
        q.push(make_pair(x0,y0));
        vis[make_pair(x0,y0)]=0;
        long long res=1;
        
        while(!q.empty()){
            pair<int,int> pos=q.front();
            q.pop();
            
            if(vis[pos]==t) continue;
            
            for(int j=0;j<6;j++){
                int nx=pos.first+six_dx[j];
                int ny=pos.second+six_dy[j];
                
                bool ok=true;
                for(int k=0;k<n && ok;k++) ok=!(nx==x[k] && ny==y[k]);
            
                if(vis.find(make_pair(nx,ny))==vis.end() && ok){
                    vis[make_pair(nx,ny)]=vis[pos]+1;
                    res++;
                    q.push(make_pair(nx,ny));
                }
            }
        }
        cout<<res<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1372
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		int result = -1;
		for (int i = 1; i <= 1000; i++) {
			if (a == Math.floor(i * 0.08) && b == Math.floor(i * 0.10)) {
				result = i;
				break;
			}
		}

		System.out.println(result);
		scan.close();
	}
}

Measured memory_bytes: 22100
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
#define MAXN 500000
#define MAXM 1000000
int n,m,s,t;
struct Edge
{
    int to,next,flow,cap;
} e[2*MAXM+100];
int head[MAXN+100];
void addEdge(int from,int to,int cap)
{
    static int c=1;
    e[++c]=(Edge)
    {
        to,head[from],0,cap
    };
    head[from]=c;
    e[++c]=(Edge)
    {
        from,head[to],0,0
    };
    head[to]=c;
}
bool vis[MAXN+100];
int dis[MAXN+100];
int cur[MAXN+100];
bool BFS()
{
    memset(vis,true,sizeof(vis));
    queue<int> q;
    q.push(s);
    dis[s]=0;
    vis[s]=false;
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=head[x]; i!=0; i=e[i].next)
        {
            if (vis[e[i].to] && e[i].cap>e[i].flow)
            {
                vis[e[i].to]=false;
                dis[e[i].to]=dis[x]+1;
                q.push(e[i].to);
            }
        }
    }
    return !vis[t];
}
int dfs(int x,int a)
{
    if(x==t || a==0) return a;
    int flow=0,f;
    for(int &i=cur[x]; i!=0; i=e[i].next)
    {
        if (dis[x]+1==dis[e[i].to] && (f=dfs(e[i].to,min(e[i].cap-e[i].flow,a)))>0)
        {
            e[i].flow+=f;
            e[i^1].flow-=f;
            flow+=f;
            a-=f;
            if (a==0) break;
        }
    }
    return flow;
}
int dinic()
{
    int flow=0;
    while(BFS())
    {
        memcpy(cur,head,sizeof(cur));
        flow+=dfs(s,INT_MAX/3);
    }
    return flow;
}

void solve(long long N, vector<long long> a, vector<long long> b, vector<long long> c, vector<long long> d){
	int ans=0;
	n=2*N+2;
	s=2*N+1;
	t=2*N+2;
	for(int i=0; i<N; ++i) {
		for(int j=0; j<N; ++j) {
			if (a[i]<c[j] && b[i]<d[j]) {
				addEdge(i+1,j+1+N,1);
			}
		}
	}	
	for(int i=1; i<=N; ++i) {
		addEdge(s,i,1);
	}
	for(int i=1; i<=N; ++i) {
		addEdge(i+N,t,1);
	}
	ans=dinic();
	cout<<ans<<endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> d(N-1+1);
	vector<long long> b(N-1+1);
	vector<long long> c(N-1+1);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&c[i]);
		scanf("%lld",&d[i]);
	}
	solve(N, a, b, c, d);
	return 0;
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define in_range(x,y,w,h) (0<=x && x<=w && 0<=y && y<h)

int T, H, W, N, tx, ty, dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
string grid[22], opr, CHS = "URDL^>v<";

void move(int d) {
	int nx = tx + dx[d], ny = ty + dy[d];
	if (!in_range(nx, ny, W, H) || grid[ny][nx] != '.') nx = tx, ny = ty;
	grid[ty][tx] = '.';
	grid[ny][nx] = CHS[d+4];
	ty = ny; tx = nx;
}

void shoot() {
	int d = CHS.find(grid[ty][tx]) - 4;
	int x = tx + dx[d], y = ty + dy[d];
	
	while (in_range(x,y,W,H) && grid[y][x] != '#' && grid[y][x] != '*') {
		x += dx[d];
		y += dy[d];
	}
	
	if (in_range(x,y,W,H) && grid[y][x] == '*') grid[y][x] = '.';
}

void simulate() {
	for_(i,0,N) {
		char c = opr[i];
		if (c == 'S') shoot();
		else move((int)CHS.find(c));
	}
}

int main() {
	cin >> T;
	
	for_(case_num,0,T) {
		cin >> H >> W;
		
		for_(y,0,H) {
			cin >> grid[y];
			for_(x,0,W) if (CHS.find(grid[y][x]) != CHS.npos) tx = x, ty = y;
		}
		
		cin >> N;
		cin >> opr;
		
		simulate();
		
		for_(y,0,H) cout << grid[y] << endl;
		if (case_num < T - 1) cout << endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    while(n--) {
        cout << "ACL";
    }
    return 0;
}

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

using namespace std;

const int N = 1000;

typedef long long LL;



int main(){

	int m , a , b , c;

	cin>>m>>a>>b;

	c = (m - a) / b;

	cout<<m - a - c * b<<endl;

	return 0;

	}

Measured memory_bytes: 256
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
using namespace std;


int main() {
  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int prev = A[0];
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    if (prev > A[i]) {
      ans += prev - A[i];
    } else {
      prev = A[i];
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    int H, N;
    cin >> H >> N;

    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += A.at(i);
    }

    if(sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n;
	vll a;
	a.push_back(0);
	REP(i, n)
	{
		inll a_;
		a.push_back(a_);
	}
	a.push_back(0);

	ll sum = 0;
	FOR(i, 0, n + 1)
	{
		sum += abs(a[i] - a[i + 1]);
	}

	FOR(i, 1, n + 1)
	{
		OUT(sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
	}
}


Measured memory_bytes: 2164
#include<iostream>
using namespace std;
//#include<math>
#include<algorithm>
#include<map>
//#include<pair>
#include<vector>
#include<set>
#include<stack>
#include<queue>
//priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)


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


int main()
{
fast;
//int t=0; cin >> t; while(t--) //testcases
{
    ll n; cin >> n;
    
    string res = "";
    
    while(n>0)
    {
        int rem = n%26;
        if(rem!=0){
            char c = 'a' -1 + rem;
            res = c + res;
            n/=26;
        }
        else{
            res = 'z' + res;
            n/=26; n--; //n reduced!!
        }
    }
    
    cout << res << nl;
}
return 0;

}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

void printCurrent(int a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i != 0) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
}

int selectionSort(int a[], int n) {
    int c = 0;
    for (int i = 0; i < n - 1; i++) {
        int minj = i;
        for (int j = i + 1; j < n; j++) {
            if (a[minj] > a[j]) {
                minj = j;
            }
        }
        if (minj != i) {
            int tmp = a[minj];
            a[minj] = a[i];
            a[i] = tmp;
            c++;
        }
    }
    printCurrent(a, n);
    return c;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int c = selectionSort(a, n);
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int P,Q,R =0;
    vector <int> L(3, 0); //可変長配列 L(要素数, 初期値)
    for(int i=0; i< 3; i++){
        cin >> L[i];
    }
    sort(L.begin(), L.end()); //ソート
    
    cout << L[0] + L[1];
    
}

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

int main() {
  int masume[52][52] = {};
  int H, W;
  cin >> H >> W;
  for (int i = 1; i <= H; ++i){
    string S;
    cin >> S;
    for (int j = 1; j <= W; ++j){
      if ('#' == S.at(j-1)){
        masume[i][j] = -9;	// -9以下の値ならなんでもいい
        masume[i-1][j-1] += 1;
        masume[i  ][j-1] += 1;
        masume[i+1][j-1] += 1;
        masume[i-1][j  ] += 1;
        masume[i  ][j  ] += 1;
        masume[i+1][j  ] += 1;
        masume[i-1][j+1] += 1;
        masume[i  ][j+1] += 1;
        masume[i+1][j+1] += 1;
      }
    }
  }
  
  for (int i = 1; i <= H; ++i){
    for (int j = 1; j <= W; ++j){
      if (masume[i][j] < 0){
        cout << '#';
      }
      else{
        cout << masume[i][j];
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
 
using namespace std;
 
int main(){
    int n, ans = 0;
    cin >> n;
    multiset<long long> ms;
    for(int i = 0; i < n; i++){
        long long x;
        cin >> x;
        ms.insert(x);
    }
    auto itr = --ms.end();
    long long t = 1;
    while(*itr >= t) t <<= 1;
    while(!ms.empty()){
        itr = --ms.end();
        long long x = *itr;
        ms.erase(itr);
        while(2 * x < t) t >>= 1;
        auto itr2 = ms.find(t - x);
        if(itr2 != ms.end()){
            ans++;
            ms.erase(itr2);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9600
#pragma GCC optimize("Ofast")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define SZ(n)       ((int)(n).size())
#define all(n)      (n).begin(), (n).end()
#define anal           '\n'
#define mod         1000000007
#define fst         first
#define sec         second
#define pr(n)       cerr << n  << " ";
#define pfor(a)       for(auto (w) : (a)) pr(w)
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
        freopen("input.in", "r", stdin);
        freopen("output.in", "w", stdout);
#endif 
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
    int n;
    cin >> n;
    if(n >= 30){
        cout << "Yes\n";
    }
    else cout << "No\n";

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



      

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int k = sc.NextInt();

        int[] height = sc.IntArray();

        long answer = long.MaxValue;

        for (int i = 0; i < Math.Pow(2, n); i++)
        {
            long price = 0;

            int count = 0;
            for (int j = 0; j < n; j++)
            {
                if ((1 & (i >> j)) == 1)
                {
                    count++;
                }
            }
            if (count < k)
            {
                continue;
            }

            int min = 0;

            for (int j = 0; j < n; j++)
            {
                if ((1 & (i >> j)) == 1)
                {
                    if (height[j] <= min)
                    {
                        price += min + 1 - height[j];
                    }
                    min = Math.Max(min + 1, height[j]);
                }
                else
                {
                    min = Math.Max(min, height[j]);
                }
            }

            answer = Math.Min(answer, price);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

#define int long long

#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

int n,ans=INF;
string s,t;

signed main(){
    cin>>n>>s>>t;
    int cnt=2*n;
    rep(i,0,n){
        int cnt=2*n;
        rep(j,0,n){
            if(i+j==n)break;
            if(s[i+j]==t[j])cnt--;
        }
        ans=min(ans,cnt);
    }
    
    
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	int c_v,c_h,c_w;
	int n;
	int e_r;
	/*****処理部*****/
	while(1){
		cin >> c_v >> c_w >> c_h;
		if(c_v == 0 && c_w == 0 && c_h == 0)	break;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> e_r;
			if((c_v*c_v + c_w*c_w) < (e_r*2 * e_r*2)){
				//cout << c_v*c_v + c_w*c_w << " " << e_r*2 * e_r*2 << endl;
				cout << "OK" << endl;
			}else if((c_v*c_v + c_h*c_h) < (e_r*2 * e_r*2)){
				//cout << c_v*c_v + c_h*c_h << " " << e_r*2 * e_r*2 << endl;
				cout << "OK" << endl;
			}else if((c_h*c_h + c_w*c_w) < (e_r*2 * e_r*2)){
				//cout << c_h*c_h + c_w*c_w << " " << e_r*2 * e_r*2 << endl;
				cout << "OK" << endl;
			}else{
				//cout << c_v*c_v + c_w*c_w << " " << e_r*2 * e_r*2 << endl;
				cout << "NA" << endl;
			}
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
multiset<int> st;
int main(){int n;scanf("%d",&n);while(n--){int t;scanf("%d",&t);st.insert(t);}scanf("%d",&n);while(n--){int t;scanf("%d",&t);auto itr=st.find(t);if(itr==st.end())return !printf("NO\n");st.erase(itr);}printf("YES\n");}

Measured memory_bytes: 9600
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
ans = 0

for i in range(n):
  temp = sum(a[:i+1])+sum(b[i:n])
  ans = max(ans, temp)
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;

typedef struct Node{
    int key;
    Node *parent;
    Node *lhs, *rhs;
} Node;

typedef struct{
    Node *root;
} BinaryTree;

void init_node(Node *node, int val){
    node->key = val;
    node->parent = nullptr;
    node->lhs = nullptr;
    node->rhs = nullptr;
}

void init_bintree(BinaryTree *T){
    T->root = nullptr;
}

void insert(BinaryTree *T, Node *node){
    Node *parent = nullptr;
    Node *x = T->root;
    while(x != nullptr){
        parent = x;
        if(node->key < x->key) x = x->lhs;
        else x = x->rhs;
    }
    node->parent = parent;
    if(parent == nullptr) T->root = node;
    else if(node->key < parent->key) parent->lhs = node;
    else parent->rhs = node;
}

void print_preorder(Node *n){
    if(n == nullptr) return;
    cout << ' ' << n->key;
    print_preorder(n->lhs);
    print_preorder(n->rhs);
}

void print_inorder(Node *n){
    if(n == nullptr) return;
    print_inorder(n->lhs);
    cout << ' ' << n->key;
    print_inorder(n->rhs);
}

void print(BinaryTree *T){
    print_inorder(T->root);
    cout << endl;
    print_preorder(T->root);
    cout << endl;
}

void find(BinaryTree *T, int val){
    Node *n = T->root;
    while(n != nullptr){
        if(n->key == val){
            cout << "yes" << endl;
            return;
        }
        if(val < n->key) n = n->lhs;
        else n = n->rhs;
    }
    cout << "no" << endl;
    return;
}

Node *get_node(BinaryTree *T, int val){
    Node *n = T->root;
    while(n != nullptr){
        if(n->key == val) return n;
        if(val < n->key) n = n->lhs;
        else n = n->rhs;
    }
    return nullptr;
}

void del_node(BinaryTree *T, Node *n){
    if(n->lhs == nullptr && n->rhs == nullptr){
        if(n->parent == nullptr) T->root = nullptr;
        else if(n->key < n->parent->key) n->parent->lhs = nullptr;
        else n->parent->rhs = nullptr;
        n = nullptr;
    }else if(n->lhs == nullptr || n->rhs == nullptr){
        Node *child = (n->lhs!=nullptr)?(n->lhs):(n->rhs);
        if(n->parent == nullptr){
            T->root = child;
            child->parent = nullptr;
        }else{
            child->parent = n->parent;
            if(n->key < n->parent->key) n->parent->lhs = child;
            else n->parent->rhs = child;
        }
        n = nullptr;
    }else{
        Node *y = n->rhs;
        while(y->lhs != nullptr) y = y->lhs;
        n->key = y->key;
        del_node(T, y);
    }
}

void del(BinaryTree *T, int val){
    del_node(T, get_node(T, val));
}

BinaryTree T;
Node n[500000];

int main(){
    int idx = 0;
    int m, v;

    init_bintree(&T);
    cin >> m;
    for(int i=0;i<m;i++){
        string comm;
        cin >> comm;
        if(comm=="print") print(&T);
        else if(comm=="insert"){
            cin >> v;
            init_node(n+idx, v);
            insert(&T, n+idx);
            idx++;
        }else if(comm=="find"){
            cin >> v;
            find(&T, v);
        }else if(comm=="delete"){
            cin >> v;
            del(&T, v);
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 15572
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- replicateM n readPair
  print $ solve m $ sortOn fst ps
 
solve :: Int -> [Pair] -> Int
solve m = fst . foldl' f e
  where
    e = (0,0)
    f (s,n) (a,b)
      | n == m = (s,n)
      | n+b > m = until ((m==).snd) (\(s,n) -> (s+a,n+1)) (s,n)
      | n+b < m = (s+a*b, n+b)
      | n+b == m = (s+a*b, n+b)
      | otherwise = error ":("

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = do
  [x,y] <- readInts
  return (x,y)

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

using namespace std;

typedef long long ll;

#define mod 1000000007

int main(){
  string s;
  vector<string> ans;
  cin>>s;
  string temp="";
  for(int i=0;i<s.length();i++){
    if(s[i]==','){
      ans.push_back(temp);
      temp="";
    }else{
      temp=temp+s[i];
    }
  }
  ans.push_back(temp);
  
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        string s;
        cin >> s;

        long n = s.size();
        bool ok1 = true, ok2 = true, ok3 = true;
        for (long i = 0; i < n; i++) {
            if (s[i] != s[n-i-1]) {
                ok1 = false;
                break;
            }
        }
        for (long i = 0; i < (n-1) / 2; i++) {
            if (s[i] != s[(n-1) / 2 - i - 1]) {
                ok2 = false;
                break;
            }
        }
        for (long i = (n+3) / 2 - 1; i < n; i++) {
            if (s[i] != s[n-i-1]) {
                ok3 = false;
                break;
            }
        }
        if (ok1 and ok2 and ok3) puts("Yes");
        else puts("No");
    }
}


Measured memory_bytes: 3632
package main

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

func main() {
	fmt.Println(abc173a(os.Stdin))
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func abc173a(r io.Reader) int {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	c := n % 1000
	if c == 0 {
		return c
	}

	return 1000 - c
}


Measured memory_bytes: 1772
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005, INF = 0x3f3f3f3f;
typedef pair<int, int> pii;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 1];

int head[MAX_N], cnt;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

int rt, P[MAX_N];
bool flag;
pii intv[MAX_N];

void dfs(int u, int v, int d) {
  if (P[u] != INF) 
    if (((P[u] & 1) ^ d) != (P[rt] & 1)) flag = 0;
  
  int L = -INF, R = INF;

  for (int i = head[u]; i; i = e[i].nxt) 
    if (e[i].to != v) {
      dfs(e[i].to, u, d ^ 1);
      L = max(L, intv[e[i].to].first - 1);
      R = min(R, intv[e[i].to].second + 1);
    }
  if (L > R) flag = 0;
  if (P[u] != INF) {
    if (L > P[u] || R < P[u]) flag = 0;
    intv[u] = make_pair(P[u], P[u]);
  } else {
    intv[u] = make_pair(L, R);
  }
}

void dfs2(int u, int v) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      if (P[e[i].to] != INF) {
	dfs2(e[i].to, u);
      } else {
	if (P[u] - 1 >= intv[e[i].to].first && P[u] - 1 <= intv[e[i].to].second)
	  P[e[i].to] = P[u] - 1, dfs2(e[i].to, u);
	else
	  P[e[i].to] = P[u] + 1, dfs2(e[i].to, u);
      }
    }
}

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

  for (int i = 1, u, v; i < N; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }

  scanf("%d", &K);
  
  memset(P, 0x3f, sizeof P);
  for (int i = 1, v, p; i <= K; ++i) {
    scanf("%d%d", &v, &p);
    P[v] = p, rt = v;
  }
  
  flag = 1;
  dfs(rt, 0, 0);

  if (!flag) {
    puts("No");
    return 0;
  }

  puts("Yes");

  dfs2(rt, 0);

  for (int i = 1; i <= N; ++i)
    printf("%d\n", P[i]);
  
  return 0;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Input();
            Initialize();

            for (int i = 0; i < Q; i++)
            {
                var x = p[i];
                var y = q[i];
                Console.WriteLine(Count(y, y) - Count(x - 1, y) - Count(y, x - 1) + Count(x - 1, x - 1));
            }
        }

        // L<=x, R<=y を満たす電車区間の個数
        static int Count(int x, int y)
        {
            if (dp[x, y] != -1) return dp[x, y];
            if (x == 0 || y == 0) return 0;

            dp[x, y] = trains[x, y] + Count(x - 1, y) + Count(x, y - 1) - Count(x - 1, y - 1);
            return dp[x, y];
        }

        static int N;
        static int M;
        static int Q;
        static int[,] trains;
        static int[] p;
        static int[] q;
        static int[,] dp;

        static void Input()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = input[0];
            M = input[1];
            Q = input[2];
            trains = new int[N + 1, N + 1];
            p = new int[Q];
            q = new int[Q];

            for (int i = 0; i < M; i++)
            {
                var inputLR = Console.ReadLine().Split().Select(int.Parse).ToArray();
                trains[inputLR[0], inputLR[1]]++;
            }

            for (int i = 0; i < Q; i++)
            {
                var inputPQ = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = inputPQ[0];
                q[i] = inputPQ[1];
            }
        }

        static void Initialize()
        {
            dp = new int[N + 1, N + 1];
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    dp[i, j] = -1;
                }
            }
        }
    }
}


Measured memory_bytes: 20464
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,re,s=0,k;
    cin>>n;
    k=n;
    while(n!=0){
        re=n%10;
        s=s+re;
        n/=10;
    }

    if(k%s == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main() {
  int N; cin >> N;
  vi h(N); rep(i,N) cin >> h.at(i);
  
  int ans = 0;
  int active = 0;
  rep(i,N) {
    if(active >= h[i]) {
      active = h[i];
    }
    else {
      ans += h[i]-active;
      active = h[i];
    }
  }
  cout << ans << endl;
}

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

lst_lucas = [i for i in range(87)]
lst_lucas[0] = 2
lst_lucas[1] = 1

if N == 1 :
    print(lst_lucas[N])
else:
    for i in range(2, N + 1):
        lst_lucas[i] = lst_lucas[i-1] + lst_lucas[i-2]
    print(lst_lucas[N])


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

static const int N = 100001;

int n, m;
int color[N], dist;

vector<int> G[N];

void dfs(int i, int c){
	queue<int> q; q.push(i);
	color[i] = c;

	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = 0; i < G[u].size(); ++i){
			int v = G[u][i];
			if (-1 == color[v]){
				color[v] = c;
				q.push(v);
			}
		}
	}
}


void search(){
	for (int i = 0; i < n; ++i) color[i] = -1;

	int c = 0;
	for (int i = 0; i < n; ++i)	{
		if (color[i] == -1) dfs(i, c++);
	}
}


int main()
{
	cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	search();

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int u, v; cin >> u >> v;
		if (color[u] == color[v]) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

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

#define M_PI 3.14159265358979323846

int main() {
	int n, m, i, total = 0;
	int a[10001];

	scanf("%d", &n);
	scanf("%d", &m);

	for (i = 0; i < m; i++) {
		scanf("%d", &a[i]);
		total += a[i];
	}

	printf("%d\n", (n - total >= 0) ? (n - total) : (-1));

	return 0;
}


Measured memory_bytes: 1768
using System;
using CompLib.Util;

public class Program
{
    private long N, D1, X;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextLong();
        D1 = sc.NextLong();
        X = sc.NextLong();

        // 適当に玉を転がす
        // 状態 玉の個数1つ減らして同じ

        Console.WriteLine(Calc(N, D1, X));
    }

    decimal Calc(long n, decimal d1, decimal x)
    {
        // 移動距離期待値 
        decimal a = (2 * d1 + (2 * n - 1) * x) / 2;
        if (n == 1) return a;

        // 転がした後の玉jの位置期待値

        // けいさんめんどい！！！！
        // jの1次式

        // 右も同様

        decimal nD1;
        {
            // 1を右に転がす
            // 玉2が新しい玉1になる
            decimal t1 = 3 * d1 + 3 * x;

            // 1を左に転がす
            decimal t2 = d1 + 2 * x;

            // それ以外
            decimal t3 = d1;

            nD1 = (t1 + t2 + t3 * (2 * n - 2)) / (2 * n);
        }

        decimal nD2;
        {
            // 1を転がす
            // 2パターン
            decimal t1 = d1 + 3 * x;


            // 2を左に転がす
            // 1
            decimal t2 = 3 * d1 + 6 * x;

            // それ以外
            // 
            decimal t3 = d1 + x;
            nD2 = (t1 * 2 + t2 + t3 * (2 * n - 3)) / (2 * n);
        }

        decimal nX = nD2 - nD1;

        return a + Calc(n - 1, nD1, nX);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 196168
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main(){
	FIO
	
	int a, b, x;
	cin >> a >> b >> x;
	if(x <= a + b && x >= a)puts("YES");
	else puts("NO");
	return 0; 
}


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

num = []
for i in range(10):
    num.append(str(i))
#print(num)

cnt = 0
for i in num:
    for k in num:
        for j in num:
            for a in range(len(S)):
                if i == S[a]:
                    for b in range(a+1,len(S)):
                        if k == S[b]:
                            for c in range(b+1,len(S)):
                                if j == S[c]:
                                    cnt += 1
                                    break
                            break
                    break
print(cnt)

Measured memory_bytes: 42972
#include<stdio.h>
#include<math.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail]  =x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    head = 1; tail = n+1;

    while (head != tail) {
        u = dequeue();
        c = min(u.t, q);
        elaps += c;
        u.t -= c;
        if(u.t > 0){
             enqueue(u);
        }else{
             printf("%s %d\n",u.name,elaps);
        }
    }

    return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
int kq,x,y;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    cin>>x>>y;
    if (x==1)
        kq+=300000;
    else
    if (x==2)
        kq+=200000;
    else
    if (x==3)
        kq+=100000;


    if (y==1)
        kq+=300000;
    else
    if (y==2)
        kq+=200000;
    else
    if (y==3)
        kq+=100000;
    if (x==1&&y==1)
        kq+=400000;
    cout<<kq;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 2000100;
ll inv[MAX],fact[MAX],fi[MAX];
constexpr ll mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

int main(){
	int r1,c1,r2,c2;
	cin >> r1 >> c1 >> r2 >> c2;
	inverse();
	long long ans;
	ans = comb(r2 + c2 + 2,r2 + 1) - comb(r1 + c2 + 1,r1) - comb(r2 + c1 + 1,c1) + comb(r1 + c1,r1);
	while(ans<0) ans += mod;
	ans %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 47104
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n = I()
    sl = [input().rstrip() for _ in range(n)]

    print(len(set(sl)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 35912
#include <iostream>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int mod=1000000007;
    long long fact[100001];
    fact[0]=1;
    for (int i=1; i<=100000; i++){
        fact[i]=fact[i-1]*i%mod;
    }
    if(abs(m-n)>=2){
        cout << 0 << endl;
    }else if(m-n==0){
        cout << 2ll*fact[n]*fact[m]%mod;
    }else {
        cout << fact[n]*fact[m]%mod;
    }
}
            


Measured memory_bytes: 1024
from collections import defaultdict
max = 10 ** 6
sieve = [None] * (max + 1)
for i in range(2, max + 1):
    if sieve[i] == None: # i is prime
        for ki in range(i, max + 1, i):
            sieve[ki] = i
def factors(n):
    while True:
        if sieve[n] is None:
            break
        yield sieve[n]
        n //= sieve[n]
used = defaultdict(lambda:0)

n = int(input())
a = map(int, input().split())
for ai in a:
    for factor in set(factors(ai)):
        used[factor] += 1
pairwise = True
setwise = True
for prime in used:
    if used[prime] > 1:
        pairwise = False
    if used[prime] == n:
        setwise = False
if pairwise:
    print("pairwise coprime")
elif setwise:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 205864
n = int(input())
a = list(map(int,input().split()))
q = int(input())
a_dict = dict()
for i in a:
    if i in a_dict:
        a_dict[i] = a_dict[i] + 1
    else:
        a_dict[i] = 1
a_sum = sum(a)

for i in range(q):
    b,c = map(int,input().split())
    if not b in a_dict:
        print(a_sum)
        continue
    a_sum = a_sum - a_dict[b]*b + a_dict[b]*c
    if c in a_dict:
        a_dict[c] = a_dict[c] + a_dict[b]
    else:
        a_dict[c] = a_dict[b]
    a_dict[b] = 0
    print(a_sum)

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

const int maxn=2e5+10;
int a[maxn];
int b[maxn];

int n;

int bina(int k)
{
    int l=-1,r=n;
    while(r-l>1)
    {
        int mid=l+((r-l)>>1);
        if(b[mid]>=k) r=mid;//返回第一个满足括号内条件的下标
        else l=mid;
    }
    return r;
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    for(int i=0;i<n;++i) scanf("%d",&b[i]);
    int ans=0;
    for(int v=(1<<28);v;v>>=1){
        int tp=0;
        for(int i=0;i<n;++i){
            a[i]&=((v<<1)-1);
            b[i]&=((v<<1)-1);
        }
        sort(a,a+n);
        sort(b,b+n);
        for(int i=0;i<n;++i){//枚举a
//            int v1=lower_bound(b,b+n,v-a[i])-b;
//            int v2=lower_bound(b,b+n,2*v-a[i])-b;
//            int v3=lower_bound(b,b+n,3*v-a[i])-b;
            int v1=bina(v-a[i]);
            int v2=bina(2*v-a[i]);
            int v3=bina(3*v-a[i]);
            tp+=v2-v1+n-v3;
            tp&=1;
        }
        if(tp) ans|=v;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main()
{
    int j,n,count=0;scanf("%d",&n);long long int d;scanf("%lld",&d);long long int p,x[n][2];
    for(j=0;j<n;j++)
    {
        scanf("%lld",&x[j][0]);scanf("%lld",&x[j][1]);
    }
    for(j=0;j<n;j++)
    {
        p=((x[j][0]*x[j][0])+(x[j][1]*x[j][1]));
        if(p<=(d*d))
        {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstring>
const int N=3005;
int n,val[N];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

namespace G{
	int cnt,fir[N];
	bool vis[N],win[N];
	struct edge{
		int to,nx;
	}eg[N<<1];

	inline void add(const int a,const int b){
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
	}

	bool dfs(const int x){
		if(vis[x]) return win[x];
		vis[x]=1;
		for(int i=fir[x]; i; i=eg[i].nx){
			const int y=eg[i].to;
			if(val[y]<val[x]&&!dfs(y)) return win[x]=1;
		}
		return 0;
	}
}

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
	}
	for(int i=1; i<n; ++i){
		const int a=nxi(),b=nxi();
		G::add(a,b);
		G::add(b,a);
	}
	for(int i=1; i<=n; ++i){
		if(G::dfs(i)) printf("%d ",i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 384
import sys
from collections import deque
from functools import lru_cache
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]

def main():
    X, Y, Z, K = read_values()
    A = read_list()
    B = read_list()
    C = read_list()

    AB = sorted([a + b for a in A for b in B], reverse=True)
    C.sort()

    P = []
    for c in C:
        heapq.heappush(P, (-(c + AB[0]), 0))
    
    for _ in range(K):
        s, i = heapq.heappop(P)
        print(-s)
        if i + 1 < len(AB):
            heapq.heappush(P, (s + (AB[i] - AB[i + 1]), i + 1))


if __name__ == "__main__":
    main()



Measured memory_bytes: 172924
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int ans  = 0;
	int n;
	cin>>n;
	map<int,int>f;
	for(int j=2;j*j<=n;j++){
		if(n%j==0){
			while(n%j==0){
				f[j]++;
				n = n/j;
			}
		}
	}
	for(auto i:f){
		int cnt = 1;
		while(i.ss>=cnt){
			ans++;
			i.ss-=cnt;
			cnt++;
		}
	}
	bool ok = (n>1);
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			ok = false;
			break;
		}
	}
	if(ok and f.count(n)==0) ans++;
	cout<<ans;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;

signed main() {
  int a,b;
  cin >> a >> b;
  if (a<10 && b<10) {
    cout << a*b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

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

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    vector< char > te;
    string t;
    cin >> t;
    int po = 0;
    for( int i = 0; i < t.size(); ++i ) {
        if( i - k >= 0 ) {
            if( t[i] == 'r' ) {
                if( te[i - k] != 'p' ) {
                    te.pb('p');
                    po += p;

                } else {
                    te.pb('N');

                }
            }
            if( t[i] == 's' ) {
                if( te[i - k] != 'r' ) {
                    te.pb('r');
                    po += r;

                } else {
                    te.pb('N');

                }
            }
            if( t[i] == 'p' ) {
                if( te[i - k] != 's' ) {
                    te.pb('s');
                    po += s;

                } else {
                    te.pb('N');

                }
            }
        } else {
            if( t[i] == 'r' ) {
                po += p;
                te.pb('p');

            }
            if( t[i] == 's' ) {
                po += r;
                te.pb('r');

            }
            if( t[i] == 'p') {
                po += s;
                te.pb('s');

            }
        }
    }
    cout << po << endl;
    return 0;
}



Measured memory_bytes: 640