akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int X(int a) { return 0 + a; }
int Y(int a) { return 100000 + a; }

ll ans = 0;
vector<int> g[200005];
bool vis[200005];

void dfs(int x) {
	queue<int> q;
	vis[x] = 1;
	q.push(x);
	vector<int> comp;
	int e = 0;
	while (!q.empty()) {
		int n = q.front(); q.pop();
		comp.push_back(n);
		for (int c : g[n]) {
			e++;
			if (!vis[c]) { vis[c] = 1; q.push(c); }
		}
	}
	ll ca = 0, cb = 0;
	for (int h : comp) if (h <= 100000) ca++; else cb++;
	//for (int h : comp) cout << h << " ";
	cout << endl;
	ans += ca * cb - e / 2;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	rep(i, 0, n) {
		int x, y; read(x, y);
		g[X(x)].push_back(Y(y));
		g[Y(y)].push_back(X(x));
	}

	rep(i, 0, 200005) if (!vis[i] && sz(g[i])) {
		dfs(i);
	}
	die(ans);
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
ll k;
ll a[100005], b[100005];
void solve() {
    cin >> n >> k;
    rep(i, n) cin >> a[i] >> b[i];

    ll ans = 0;
    rep(i, n) {
        bool ok = true;
        rep(j, 32) {
            if (((a[i] >> j) & 1) == 1 && ((k >> j) & 1) != 1) {
                ok = false;
                break;
            }
        }

        if (ok) ans += b[i];
    }

    reps(i, 32) {
        if (((k >> i) & 1) != 1) continue;

        ll res = 0;
        rep(j, n) {
            bool ok = true;
            rep(l, 32) {
                if (i == l && ((a[j] >> l) & 1) == 1 || l > i && ((a[j] >> l) & 1) == 1 && ((k >> l) & 1) == 0) {
                    ok = false; break;
                }
            }

            if (ok) res += b[j];
        }

        maxs(ans, res);
    }

    cout << ans << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 1916
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){

  int i,n,sum=0;
  cin >> n;
  vector<int> l(2*n);
  for(i=0;i<2*n;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  for(i=0;i<2*n;i++){
    if(i%2==0)
      sum+=l[i];
  }
  cout << sum << endl;
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	double n, t, a;
	cin >> n >> t >> a;
	double mi = 10000000;
	double h[10000];
	int s = 0;
	for (int i = 1; i < n+1; i++) {
		cin >> h[i];
		double d = t*1000 - h[i] * 6 - a*1000;
		if (d < 0)d = -1 * d;
		if (mi > d) mi=d, s = i;
	}
	cout << s << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
ab.sort(reverse = True)

bridge = [float("inf")]
for i in range(m):
    if ab[i][0] <= min(bridge) < ab[i][1]:
        continue
    else:
        bridge.append(ab[i][0])
print(len(bridge) - 1)

Measured memory_bytes: 27868
#include<iostream>
#include<vector>
int main(){
    int N, K, d;
    std::cin >> N >> K;
    std::vector<int> vec;
    for(int i=0; i<N; i++){
        vec.push_back(i+1);
    }
    for(int i=0; i<K; i++){
        int tmp;
        std::cin >> d;
        for(int j=0; j<d; j++){
            std::cin >> tmp;
            vec.erase(std::remove(vec.begin(), vec.end(), tmp), vec.end());
        }
    }
    printf("%d\n", (int)vec.size());
    return 0;
}

Measured memory_bytes: 3212
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

dxdy = [[1,0],[0,1]]

# @njit
def solve(h,w,board):
  sharp_count = sum(x.count("#") for x in board)
  def dfs(y,x,gy,gx,cnt=1):
    if y == gy and x == gx:
      return cnt

    if not 0 <= y < h or not 0 <= x < w:
      return 0
    if board[y][x] == ".":
      return 0
    return  dfs(y+1,x,gy,gx,cnt+1) + dfs(y,x+1,gy,gx,cnt+1)
  
  return dfs(0,0,h-1,w-1) == sharp_count



def main():
  H,W = map(int,input().split())
  board = [input() for _ in range(H)]
  print("Possible" if solve(H,W,board) else "Impossible")
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9228
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
  int max,min,dif,t,count;

  cin>>count;

  for(t = 0;t < count;++t){
    string v;

    max = 0;
    min = 0;

    cin>>v;

    sort(v.begin(),v.end());
    min = atoi(v.c_str());

    reverse(v.begin(),v.end());
    max = atoi(v.c_str());

    dif = max - min;
    cout<<dif<<endl;
  }

  return 0;
}

Measured memory_bytes: 3156
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextDouble();
		double B = sc.nextDouble();
		if(((double)Math.abs(A - B)) % 2 == 0) {
			System.out.println((int)(Math.max(A, B) - Math.abs(A - B) / 2));
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N,S;
  cin>>N>>S;
  lint X[N],P[N];
  REP(i,N)cin>>X[i]>>P[i];
  
  int l=0;
  int r=N-1;
  stack<lint> s;
  while(1){
    if(X[l]>S){
      s.push(r);
      break;
    }
    if(X[r]<S){
      s.push(l);
      break;
    }
    if(P[l]>=P[r]){
      P[l]+=P[r];
      s.push(r);
      r--;
    }else{
      P[r]+=P[l];
      s.push(l);
      l++;
    }
  }
  lint ans=0;
  lint B=S;
  while(!s.empty()){
    lint T=X[s.top()];
    s.pop();
    // cerr<<T+1<<" "<<ans<<endl;
    ans+=max(B-T,T-B);
    B=T;
  }
  cout<<ans<<endl;
  return 0;
}


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

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        int s=0;
        char c[]=sc.getCharSet();
        char d[]=sc.getCharSet();
        for (int i = 0; i < d.length; i++) {
			if(c[i]!=d[i])s++;
		}
        out.println(s);
     	out.flush();
    }
        
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x,y,c;
	P(int  x, int y, int c) {
	  this.x=x;
	  this.y=y;
	  this.c=c;
	}
}

//
//class P implements Comparable<P>{
//	int x,c;long s;
//	P(int  x, int c, long s) {
//	  this.x=x;
//	  this.c=c;
//	  this.s=s;
//	}
//
//    public int compareTo(P p){
//        return Long.signum(s-p.s);
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 37856
import java.util.Scanner;
import java.util.Arrays;
class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			int score[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				score[i] = sc.nextInt();
			}
			Arrays.sort(score);
			int total = 0;
			for (int i = 1; i < n - 1; i++)
			{
				total += score[i];
			}
			System.out.println(total / (n - 2));
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

constexpr int MAX_N = 100;
int N;
char s[MAX_N+1];
char t[MAX_N+1];

void _main() {
  cin >> N >> s >> t;

  int common = 0;
  rep(i, 0, N) {
    bool f = true;
    rep(j, 0, i+1) if (s[N-1-i+j] != t[j]) f = false;
    if (f) common = i + 1;
  }

  int ans = N * 2 - common;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define FT first
#define SD second
#define MP make_pair
#define INF 0x7fffffff
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>  P;
typedef vector<int> VI;
typedef map<int,int> MII;
const int N = 305, MOD = 7+1e9;
int n, c1[2*N][2*N], c2[2*N][2*N];
int sg[] = {-1, 1};
void init(int D, vector<P>& V)
{
    V.clear();
    for(int i = 0;i * i <= D;i ++)
    {
        int j = sqrt(D - i * i);
        if(j * j + i * i == D)
        {
            V.PB({i, j});
        }
    }
}
bool check(int x, int y)
{
    return x >= 0 && x < 2*n && y >= 0 && y < 2*n;
}
void dfs(int x, int y, const vector<pair<int, int>>& q, int C[][2*N], int cur = 0) 
{
    C[x][y] = cur;
    for (auto p : q) 
    {
        for (int s1 : {-1, 1}) 
        {
            for (int s2 : {-1, 1}) 
            {
                int nx = x + p.first * s1;
                int ny = y + p.second * s2;

                if (nx < 0 || nx >= 2 * n || ny < 0 || ny >= 2 * n) continue;
                if (C[nx][ny] != -1) continue;
                dfs(nx, ny, q, C, !cur);
            }
        }
    }
}
int main()
{
#ifdef YUUKILP
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int d1, d2;
    vector<P> v1, v2;
    cin >> n >> d1 >> d2;
    init(d1, v1);
    init(d2, v2);
    memset(c1, -1, sizeof c1);
    memset(c2, -1, sizeof c2);
    for(int i = 0;i < 2*n;i ++)
    {
        for(int j = 0;j < 2*n;j ++)
        {
            if(c1[i][j] == -1) dfs(i, j, v1, c1, 0);
            if(c2[i][j] == -1) dfs(i, j, v2, c2, 0);
        }
    }
    vector<P> V[4];
    for(int i = 0;i < 2*n;i ++)
    {
        for(int j = 0;j < 2*n;j ++)
        {
            V[(c1[i][j]<<1) + c2[i][j]].PB(MP(i, j));
        }
    }
    for(int i = 0;i < 4;i ++)
    {
        if(V[i].size() >= n*n)
        {
            for(int j = 0;j < n*n;j ++)
                cout << V[i][j].FT << " " << V[i][j].SD << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 46168
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{   int n,k;
cin>>n>>k;
    string s;
    cin>>s;
    vector<pair<int,int>> a;
    vector<pair<int,int>> b;
    if(s[0]=='0'){
        b.push_back({0,0});
    }
    int i=0;
    while(i<s.size()){
        if(s[i]=='0'){
            int z=i;
            i++;
            while(s[i]=='0'){
                i++;
            }
            int x=i;
            a.push_back(make_pair(z,x));
        }
        else{
            int z=i;
            i++;
            while(s[i]=='1'){
                i++;
            }
            int x=i;
            b.push_back(make_pair(z,x));
        }
    }
    b.push_back({0,0});
//    for(int i=0;i<a.size();i++){
//        cout<<a[i].first<<" "<<a[i].second<<endl;
//    }
//    for(int i=0;i<b.size();i++){
//        cout<<b[i].first<<" "<<b[i].second<<endl;
//    }
    if(a.size()==0 || a[0].second-a[0].first==s.size() || a.size()<=k){
        cout<<s.size();
        return 0;
    }
    else{
        int m=INT_MIN,o=INT_MIN;
        for(int i=0;i+k<=a.size();i++){
            int l=0;
            for(int j=0;j<k;j++){
                if(!j){
                    l+=(b[i+j].second-b[i+j].first)+(a[i+j].second-a[i+j].first)+(b[i+j+1].second-b[i+j+1].first);
                }
                else{
                    l+=(a[i+j].second-a[i+j].first)+(b[i+j+1].second-b[i+j+1].first);
                }
            }
            m=max(m,l);
        }

        cout<<m;
        return 0;
    }
}

Measured memory_bytes: 1404
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;

	int C[VMAX+1];
	int n,i,j;
	scanf("%d", &n);

	A=malloc(sizeof(short) *n+1);
	B=malloc(sizeof(short) *n+1);

	for(i=0; i <= VMAX ; i++)C[i]=0;

	for(i=0 ; i<n ; i++){
		scanf("%hu", &A[i+1]);
		C[A[i+1]]++;
	}

	for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

	for(j=1;j<=n;j++){
		B[C[A[j]]]=A[j];
		C[A[j]]--;
	}

	for(i=1;i<=n;i++){
		if(i>1)printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");

	return 0;
}

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

int main() {
    int N = 0;
    int l, r;
    int count = 0;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> l >> r;
        count += r -l + 1;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m, c = LI()
    B = LI()

    res = 0
    for _ in range(n):
        A = LI()
        tmp = c
        for i in range(m):
            tmp += A[i] * B[i]
        if tmp > 0:
            res += 1

    return res


print(main())


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
typedef long long ll;

int n, k;
int x[N];
int Abs(int x) {
    return x < 0 ? -x : x;
}
int main() {
    while(~scanf("%d %d", &n, &k)) {
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &x[i]);
        }

        int ans = INF;
        for(int i = 1; i <= n-k + 1; ++i) {
            if(x[i] <= 0 && x[i + k - 1] >= 0) {
                ans = min(ans, min(-x[i], x[i+k-1]) + x[i+k-1] - x[i]);
            } else {
                ans = min(ans, max(Abs(x[i]), Abs(x[i + k - 1])));
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)


int main(void){
    char s1[100],s2[100],s3[100];

    scanf("%s%s%s",s1,s2,s3);

    printf("%c%c%c\n",s1[0] - 32,s2[0] - 32,s3[0] - 32);
    return 0;
}

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

class Cube {
public:
	int f[6];
	Cube() {}
	void roll_z() { roll(1, 2, 4, 3); }
	void roll_y() { roll(0, 2, 5, 3); }
	void roll_x() { roll(0, 1, 5, 4); }
	void roll(int i, int j, int k, int l) {
		int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
};

int getRight(Cube c1, int f1, int f2) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (c1.f[0] == f1 && c1.f[1] == f2)return c1.f[2];
			c1.roll_z();	
		}
		if (i % 2 == 0)c1.roll_y();
		else c1.roll_x();
	}
	return -1;
}

int main()
{
	Cube c;
	int f1, f2;
	
	for (int i = 0; i < 6; i++)cin >> c.f[i];
	int q; cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> f1 >> f2;
		cout << getRight(c, f1, f2) << endl;
	}

    return 0;
}


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

int main()
{
    long long int t=1,n,c=1,i,ans=1;
   // cin>>t;
    //while(t--){
        cin>>n;
        long long int a[n+1];
        for(i=0;i<n;i++){
            cin>>a[i];
            if(a[i]==0){
                    cout<<"0";return 0;
        }
        }
           for(i=0;i<n;i++){

            if(a[i]<=1000000000000000000/ans){
                ans*=a[i];
            }
            else {
                cout<<"-1"<<endl;
                return 0;
            }

            }
            cout<<ans<<endl;
    }



Measured memory_bytes: 4356
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

lst_result = []
lst = [[A, A % 10], [B, B % 10], [C, C % 10], [D, D % 10], [E, E % 10]]
lst_a = []
for i in range(len(lst)):
  if lst[i][1] == 0:
    lst_result.append(lst[i][0])
  else:
    lst_a.append(lst[i])

lst_a = sorted(lst_a, key = lambda x:x[1], reverse = True)


for i in range(len(lst_a)):
  lst_result.append(lst_a[i][0])

answer = 0
for i in range(len(lst_result)):
  if i < 4:
    if lst_result[i] % 10 == 0:
      answer += lst_result[i]
    else:
      tmp = lst_result[i] // 10 + 1
      answer += tmp * 10
  else:
    answer += lst_result[i]
print(answer)

Measured memory_bytes: 3192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class CDistinctOrNot {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        s(n);
        vi a(n);
        set<int> aa;
        f(i,0,n){
            s(a[i]);
            aa.insert(a[i]);
        }
        if(n == aa.size()) out<<"YES"<<endl;
        else out<<"NO"<<endl;
	}
};


integer main() {
	CDistinctOrNot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 11136
#include<iostream>
#define ll long long
using namespace std;
int n;
ll a[300000];
ll ans=0;
ll s[30];
ll p[30];
bool check()
{
    for (int i=0; i<22; ++i)
        if (s[i]>1) return 0;
    return 1;
}

void add(int x,int flag)
{
    for (int i=0; i<22; ++i)
        s[i]+=flag*(((p[i])&x)>0);
}

void print()
{
    for (int i=0; i<5; ++i)
        cout<<s[i]<<' ';
    cout<<endl;
}
int main()
{
    p[0]=1;
    for (int i=1; i<22; ++i)
        p[i]=p[i-1]*2;
    scanf("%d",&n);
    for (int i=1; i<=n; ++i)
        scanf("%lld",&a[i]);
    ll start=0;
    for (int i=1; i<=n; ++i)
    {
        for (int j=start+1; j<=n; ++j)
        {
            add(a[j],1);
        //    print();
            if (check())
            {
                start=j;
            }else
            {
                add(a[j],-1);
                break;
            }
        }
        //cout<<i<<' '<<start<<endl;
        ans+=(start-i+1);
        add(a[i],-1);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1792
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
s=0
for i in range(n+1):
  s+=abs(a[i+1]-a[i])
for i in range(n):
  print(s-abs(a[i]-a[i+1])-abs(a[i+1]-a[i+2])+abs(a[i]-a[i+2]))

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

int main() {
    string a,b,c; cin >> a >> b >> c;
    string ans;
    ans += a[0];
    ans += b[0];
    ans += c[0];
    transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
    cout << ans << endl;
}

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

int main() {
    long long A, B, C; cin >> A >> B >> C;
    long long ans = 0;
    if (A % 2 && B % 2 && C % 2) {
        ans = min({(A % 2) * B * C, A * (B % 2) * C, A * B * (C % 2)});
    }
    cout << ans << endl;
}

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


/*#### modular_arithmetic */
class modular_arithmetic{
public:
	int mod;
	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	void set_mod(int _mod){mod = _mod;}
	int add(int x,int y){return (x+y)%mod;}
	int sub(int x,int y){return (x-y+mod)%mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
	int pw(int x,int y){
		int r = 1;
		while(1){
			if(y&1)r=mul(r,x);
			if(y>>=1)x=mul(x,x);else
				break;
		}
		return r;
	}
	//mod must be a prime.
	int inv(int x){
		return pw(x, mod-2);
	}
};
/*####*/

modular_arithmetic ma;

#define ran 1000010
int fac[ran],ifac[ran],n;

int main(){
	scanf("%d",&n);
	fac[0] = 1;
	for(int i=0; i<n; i++)
		fac[i+1] = ma.mul(fac[i], i+1);
	ifac[n] = ma.inv(fac[n]);
	for(int i=n-1; i>=0; i--)
		ifac[i] = ma.mul(ifac[i+1], i+1);
	int cur = fac[(n+1)/2], step = (n+1)/2;
	int res = ma.mul(cur, step);
	int lst = cur;
	while(step < n-1){
		++step;
		int d = n - step;
		cur = ma.mul(cur, fac[n-d]);
		cur = ma.mul(cur, fac[n-2*d-2]);
		cur = ma.mul(cur, ifac[n-2*d]);
		cur = ma.mul(cur, ifac[n-d-2]);
		res = ma.add(res, ma.mul(ma.sub(cur,lst), step));
		lst = cur;
	}
	printf("%d\n",ma.mul(res, fac[(n-1)/2]));
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

string foo[4] = {"dream", "dreamer", "erase", "eraser"};
bool dp[100050];

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

    string s;
    cin >> s;
    int n = s.length();
    dp[0] = true;
    for(int i = 0; i < n; ++i){
        if(!dp[i])  continue;
        for(int j = 0; j < 4; ++j){
            int len = foo[j].length();
            if(s.substr(i, len) == foo[j])  dp[i + len] = true;
        }
    }
    if(dp[n])   cout << "YES\n";
    else    cout << "NO\n";
}

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

int main() {
	int N;
	vector<long> LN(87);
	LN.at(0)=2;
	LN.at(1)=1;
	for (int i=2; i<87; i++)
		LN.at(i)=LN.at(i-1)+LN.at(i-2);
	cin >>N;
	cout <<LN.at(N) <<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define nrep(i,n) for(int i=1;i<=(n);i++)
#define FST first
#define SEC second
using namespace std;

int stoi(string str){
  int ret;
  stringstream ss;
  ss << str;
  ss >> ret;
  return ret;
}

string itos(int val){
  stringstream ss;
  ss << val;
  string str = ss.str();
  return str;
}

int main(){
  int Q;
  scanf("%d",&Q);
  while(Q-->0){
    string N;
    cin >> N;

    if(stoi(N)<10){
      puts("0");
      continue;
    }

    set <int> s;    
    int count=1;
    for(;;){
      int max=0;
      for(int i=1;i<N.size();i++){
	string N1 = N.substr(0,i);
	string N2 = N.substr(i,N.size());
	int mul=stoi(N1)*stoi(N2);
	if(mul>max)
	  max=mul;
	// cout << N1 << " " << N2 << endl;
      }
      // cout << "max is :" << max << endl;
      if(max<10)
	break;
      if(s.count(max)){
	count = -1;
	break;
      }
      s.insert(max);

      N=itos(max);
      count++;
    }
    printf("%d\n",count);

  }
}

Measured memory_bytes: 1308
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	ll ans = 0;
	ll maxSize = 0;
	rep(i, n) {
		ans += max((ll)0, maxSize - a[i]);
		maxSize = max(maxSize, a[i]);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 5148
def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

n, x = map(int, input().split())
town = map(int, input().split())

distance = (abs(x-y) for y in town)
res = next(distance)
for d in distance:
    res = gcd(res, d)

print(res)


Measured memory_bytes: 11100
#include <iostream>
#include <cmath>

using namespace std;
int a,b;

int main()
{
    cin>>a>>b;
    int c=b;
    int t=0;
    while(c)
    {
        t++;
        c/=10;
    }

    double p=pow(10,t);


    a=a*p+b;

    if((int)sqrt(a)*(int)sqrt(a)==a) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main() {
int k;
while(cin >> k, k) {
int sum;
sum = 0;
for(int i = 0; i < k*(k-1)/2; i++) {
int a;
cin >> a;
sum += a;
}
cout << sum / (k-1) << endl;
}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int a[1005];
int n;

int dp[100005];

int win(int k){
	if(k < a[0]){
		return 0;
	}
	int &ans = dp[k];
	if(ans != -1)
		return ans;
	
	dp[k] = 0;
	
	for(int i = 0; i < n; i++){
		if(a[i] <= k){
			if(!win(k-a[i])){
				return dp[k] = 1;
			}
		}
	}
	return dp[k] = 0;
	
}

int32_t main(){
	int k;
	cin >> n >> k;
	
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	sort(a,a+n);
	
	memset(dp,-1,sizeof dp);
	
	
	if(win(k)){
		cout << "First\n";
	}
	else{
		cout << "Second\n";
	}


	return 0;
}



Measured memory_bytes: 4096
use std::cmp;
use std::collections::BTreeMap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let r: usize = sc.read();
    let p: Vec<usize> = sc.vec::<usize>(n).into_iter().map(|x| x - 1).collect();

    let mut used = vec![0; n];
    let mut cur = 1;
    for i in 0..n {
        if used[i] != 0 {
            continue;
        }
        let mut pos = i;
        while used[pos] == 0 {
            used[pos] = cur;
            pos = p[pos];
        }
        cur += 1;
    }

    let count = used
        .into_iter()
        .fold(BTreeMap::new(), |mut map, x| {
            *map.entry(x).or_insert(0) += 1;
            map
        })
        .into_iter()
        .fold(BTreeMap::new(), |mut map, (_, count)| {
            *map.entry(count).or_insert(0) += 1;
            map
        });

    let r = cmp::min(r, n - r);
    let mut dp = vec![-1; r + 1];
    dp[0] = 0;
    for (a, m) in count.into_iter() {
        for j in 0..(r + 1) {
            if dp[j] >= 0 {
                dp[j] = m;
            } else if j < a || dp[j - a] <= 0 {
                dp[j] = -1;
            } else {
                dp[j] = dp[j - a] - 1;
            }
        }
    }

    if dp[r] >= 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 17292
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
		}
		for(int i=n-1; i>0; i--){
			if(a[i-1]-a[i]>1){
				System.out.println("No");
				return;
			}
			if(a[i-1]-a[i]==1){
				a[i-1]--;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 62608
#include <iostream>
#include <vector>
constexpr int P = 1'000'000'007;
int n, k;
std::vector<int> a;
std::vector<std::vector<int>> c, dp;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> k;
    a.resize(k);
    for (int i = 0; i < k; ++i)
        std::cin >> a[i];
    c.assign(n + 1, std::vector<int>(n + 1));
    for (int i = 0; i <= n; ++i) {
        c[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % P;
    }
    dp.assign(k + 1, std::vector<int>(n + 1));
    dp[0][0] = 1;
    for (int i = 0; i < k; ++i)
        for (int j = 0; j <= n; ++j)
            for (int l = 0; l <= n - j && l <= a[i]; ++l)
                dp[i + 1][j + l] = (dp[i + 1][j + l] + 1LL * dp[i][j] * c[n - j][l] % P * c[n - l][a[i] - l]) % P;
    std::cout << dp[k][n] << "\n";
    return 0;
}

Measured memory_bytes: 4352
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        BigDecimal[] nums = new BigDecimal[N];
        for (int i = 0; i < N; i++) {
            nums[i] = new BigDecimal(sc.next());
        }
        final BigDecimal limit = new BigDecimal("1000000000000000000");
        Arrays.sort(nums);
        BigDecimal ans = nums[0];
        if (ans.longValue() == 0) {
            System.out.println(0);
        } else {
            boolean over = false;
            for (int i = 1; i < N; i++) {
                ans = ans.multiply(nums[i]);
                if (limit.compareTo(ans) < 0) {
                    System.out.println(-1);
                    over = true;
                    break;
                }
            }
            if (!over) {
                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 66376
import sys
if __name__ == "__main__":
    A, B, C, X, Y = list(map(int, (input().split(' '))))
    cost_A = A * X
    cost_B = B * Y
    least_cost = cost_A + cost_B
    max_cnt = 0
    if X >= Y:
        max_cnt = X
    else:
        max_cnt = Y
    for i in range(0, 2*max_cnt+1, 2):
#        print(i)
        buf_cost_A = 0
        buf_cost_B = 0
        buf_cost = C * i
        if (X - i*0.5) > 0:
            buf_cost_A = (X - i*0.5) * A
        if (Y - i*0.5) > 0:
            buf_cost_B = (Y - i*0.5) * B
#        print(buf_cost+buf_cost_A+buf_cost_B)
        if least_cost > (buf_cost + buf_cost_A + buf_cost_B):
            least_cost = buf_cost + buf_cost_A + buf_cost_B
    print(int(least_cost))

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
typedef vector<ll> lvec;typedef vector<double> dvec;typedef vector<string> svec;
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll d, n;
  cin>>d>>n;
  ll ans=pow(100,d)*n;
  if(n==100) ans=pow(100,d)*101;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, Q;
    bool mark[100001];
    int tree[100001];
    while (1) {
        cin >> N >> Q;
        if (N == 0 && Q == 0) {
            break;
        }

        memset(mark, false, sizeof(mark));
        mark[1] = true; 
        tree[1] = 0;
        for (int i=2; i<=N; ++i) {
            cin >> tree[i];
        } 

        long long sum = 0;
        for (int i=0; i<Q; ++i) {
            char ope;
            int v;
            cin >> ope >> v;
            if (ope == 'Q') {
                for (int j=v; j>=1; j=tree[j]) {
                    if (mark[j] == true) {
                        sum += j;
                        break;
                    }
                }
            } else if (ope == 'M') {
                mark[v] = true;
            }
        }
        cout << sum << "\n";
    }
    return 0;
}

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

using namespace std;

int main()
{
	int N,T,A,H[1000];

	cin >> N >> T >> A;

	double ans = 1e18;

	for(int i=0; i<N; i++){
		cin >> H[i];
		ans = min(ans, abs(A - (T - H[i] * 0.006)));
	}

	for(int i=0; i<N; i++){
		if(ans == abs(A - (T - H[i] * 0.006))){
			cout << i+1;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  string S;
  cin >> S;

  if(S[0]=='7' || S[1]=='7' || S[2]=='7'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3624
def main():
    n = int(input())
    a = list(map(int, input().split()))
    mx = max(a)
    ans = [0] * (mx + 2)
    for i, aa in enumerate(a):
        if aa != 0:
            ans[aa - 1] += 1
        ans[aa] += 1
        ans[aa + 1] += 1
    print(max(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 13964
#include<stdio.h>
int main(void){
char s[5];
  scanf("%s",&s);
if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]||
   s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]||
   s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1])
  printf("Yes");
    else printf("No");
    return 0;
  }
              

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



struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

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

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

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


}

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

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


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else{
    if(y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }
  if(y != z) z->key = y->key;
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;
  

  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
  else y->right = z;
  }
}

Node find(Node x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

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

  return 0;
}



Measured memory_bytes: 20492
N,M = (int(x) for x in input().split())
A_list = [int(x) for x in input().split()]
A_sum = sum(A_list)
Bool_list = []
for A in A_list:
    if A >= (A_sum/(4*M)):
        Bool_list.append("True")
        
if (len(Bool_list)) >= M:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 A[101010], B[101010];

vector<pair<i64, int>> los, his;

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld%lld", A + i, B + i);

	i64 ret = 0;
	for (int i = 0; i < N; ++i) ret += A[i];

	i64 tmp = 0;
	for (int i = 0; i < N; ++i) tmp += B[i];
	ret = min(ret, tmp);

	for (int i = 0; i < N; ++i) if (A[i] > B[i]) swap(A[i], B[i]);
	i64 curr = 0;
	for (int i = 0; i < N; ++i) curr += A[i];

	for (int i = 0; i < N; ++i) {
		los.push_back({A[i], i});
		his.push_back({B[i], i});
	}
	sort(los.begin(), los.end());
	sort(his.begin(), his.end());
	reverse(los.begin(), los.end());

	if (los[0].second == his[0].second) {
		ret = min(ret, curr + min(-los[0].first + his[1].first, -los[1].first + his[0].first));
	} else {
		for (int i = 0; i < N; ++i) {
			curr += his[i].first - los[i].first;
			ret = min(ret, curr);
		}
	}
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 5100
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;

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

    int res = 0;
    res += (n/500) * 1000;
    n %= 500;

    res += (n/5) * 5;

    cout << res << endl; 

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int MAX_N = 1000001;
int main(){
  
  vector<int> prime(MAX_N,1);
  prime[0]=0;prime[1]=0;
  for(int i = 2;i*i<MAX_N;i++){
    if(prime[i])
      for(int j = i*i;j<MAX_N;j+=i){
	if(prime[j] && j%i == 0)prime[j] = 0;
      }
  }
  int a,n,d;
  while(cin>>a>>d>>n){
    if(!a&&!d&&!n)break;
    int ct = 0;
    REP(i,MAX_N){
      if(prime[a+(i)*d])
	ct++;
      if(ct==n){
	cout << a+(i)*d << endl;
	break;
      }
    }
  }     
  return 0;
}

Measured memory_bytes: 6528
N = int(input())
cnt = 0
tmp_m = 0
for n in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        tmp_m += 1
    else:
        cnt = max(cnt, tmp_m)
        tmp_m = 0
cnt = max(cnt, tmp_m)
if cnt >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62464
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut it = buf.split_whitespace();
    let a: i32 = it.next().unwrap().parse().unwrap();
    let b: i32 = it.next().unwrap().parse().unwrap();
    if b >= a {
        println!("{}", a);
    } else {
        println!("{}", a-1);
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int s[110];
    rep(i, N) cin >> s[i];
    int sum = 0;
    rep(i, N) sum += s[i];
    sort(s, s + N);
    if(sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    rep(i, N) {
        if (s[i] % 10 != 0) {
            cout << sum - s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;

    return 0;
}


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(int i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(int i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(int i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n,k;
int dp[100005];
ll a[101];
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n>>k;
    memset(dp,-1,sizeof(dp));
    repA(i,1,n) {cin>>a[i]; dp[a[i]]=1;}
    for(ll i=0;i<a[1];i++) dp[i]=0;
    for(ll i=0; i<=k;i++)
    {
        if(dp[i]==-1)
        {
            int temp=1;
            for(ll j=1;j<=n;j++)
            {
                if(i-a[j]>=0)
                {
                    temp=temp & dp[i-a[j]];
                }
                else break;
            }
            dp[i]=!(temp);
        }
    }
    if(dp[k]==1) cout<<"First\n";
    else cout<<"Second\n";
    return 0;
}


Measured memory_bytes: 640