akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		long[] v = new long[N];
		for (int i = 0; i < N; i++) {
			v[i] = Long.parseLong(sc.next());
		}
		sc.close();

		long ans = 0;
		int OP = Math.min(K, N);
		for (int a = 0; a <= OP; a++) {
			long sa = 0;
			ArrayList<Long> alist = new ArrayList<Long>();
			for (int i = 0; i < a; i++) {
				sa += v[i];
				if (v[i] < 0) {
					alist.add(v[i]);
				}
			}
			for (int b = 0; b <= OP - a; b++) {
				long sb = sa;
				ArrayList<Long> blist = new ArrayList<Long>();
				for(long n: alist){
					blist.add(n);
				}
				for (int i = N - 1; i > N - 1 - b; i--) {
					sb += v[i];
					if (v[i] < 0) {
						blist.add(v[i]);
					}
				}

				Collections.sort(blist);
				int pop = K - (a + b);
				for (long n : blist) {
					if (pop == 0) {
						break;
					}
					sb += Math.abs(n);
					pop--;
				}
				ans = Math.max(ans, sb);
			}
		}

		System.out.println(ans);

	}

}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
#define INF 1e9
//constexpr ll INF = 1LL << 60;
constexpr int mod = 1e9+7;

int main(){
  string S;
  cin >> S;
  if(S[2] == S[3] && S[4] == S[5]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)

func main() {
    as := make([]int, 3)
    for i := 0; i < 3; i++ {
        fmt.Scan(&as[i])
    }   
    sort.Sort(sort.Reverse(sort.IntSlice(as)))
    var sum int 
    for i := 1; i < len(as); i++ {
        sum += as[i-1] - as[i]
    }   
    fmt.Println(sum)
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static int dp[];
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }



    public static void main(String[] args)throws IOException {
        FastReader fr = new FastReader();
        int n=fr.nextInt();
        int m=fr.nextInt();
        int arr[][]=new int[n][m];
        int mod=1000000007;
        for(int i=0;i<n;i++)
        {
            char s[]=fr.nextLine().toCharArray();
            for(int j=0;j<s.length;j++)
            {
                if(s[j]=='#')arr[i][j]=-1;

            }

        }
        arr[0][0]=1;
        for(int i=1;i<m;i++)
        {
            if(arr[0][i]==-1)
                arr[0][i]=0;
            else
                arr[0][i]=arr[0][i-1];
        }
        for(int i=1;i<n;i++)
        {
            if(arr[i][0]==-1)
                arr[i][0]=0;
            else
                arr[i][0]=arr[i-1][0];
        }


        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
                if(arr[i][j]==-1)arr[i][j]=0;
                else
                arr[i][j]=(arr[i][j-1]+arr[i-1][j])%mod;
            }
        }
        
        System.out.println(arr[n-1][m-1]);

    }
    public static int dfs(HashMap<Integer,ArrayList<Integer>> hm,int v)
    {
        int max=0;
        if(dp[v]!=-1)
            return dp[v];
        if(hm.containsKey(v)){
            for(int i=0;i<hm.get(v).size();i++)
            {
                max=Math.max(max,1+dfs(hm,hm.get(v).get(i)));
            }
        }

        return dp[v]= max;
    }




}


Measured memory_bytes: 43272
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int[] m = new int[n];
		Arrays.setAll(m, i -> Integer.parseInt(sc.next()));
		int sum = Arrays.stream(m).sum();
		Arrays.sort(m);
		System.out.println(n + (x - sum) / m[0]);
	}
}


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

using namespace std;
const int maxn = 1e6 + 5;

int a[maxn];

int main() {
    int n, m, sum = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) scanf("%d", &a[i]), sum += a[i];
    sum = n - sum;
    printf("%d\n", (sum >= 0 ? sum : -1));
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[505][505];
bool U[505][505];
ll x[4] = {0, 1, 0, -1};
ll y[4] = {1, 0, -1, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        REP(j, N) {
            A[i][j] = std::min({i, j, N - 1 - i, N - 1 - j});
        }
    }
    ll ans = 0;
    REP(_, N * N) {
        ll a;
        cin >> a;
        a--;
        pll p(a / N, a % N);
        ll c = A[p.first][p.second];
        ans += c;
        U[p.first][p.second] = true;

        queue<tuple<ll, ll, ll>> q;
        q.push(make_tuple(p.first, p.second, c));
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            ll cost = get<2>(t);
            if (!U[get<0>(t)][get<1>(t)])
                cost++;
            REP(j, 4) {
                ll nx = x[j] + get<0>(t), ny = y[j] + get<1>(t);
                if (nx < 0 || ny < 0 || nx >= N || ny >= N)
                    continue;
                if (A[nx][ny] <= cost)
                    continue;

                A[nx][ny] = cost;
                q.push(make_tuple(nx, ny, A[nx][ny]));
            }
        }

#if false
        cout << "-------------------" << endl;
        REP(j, N) {
            REP(k, N) {
                if (j == p.first && k == p.second)
                    cout << "x ";
                else
                    cout << A[j][k] << " ";
            }
            cout << endl;
        }
#endif
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5824
def main():
    import sys
    input = sys.stdin.readline
    S = input().strip()
    if 'RRR' in S:
        print(3)
    elif 'RR' in S:
        print(2)
    elif 'R' in S:
        print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] strs = new String[n];
		
		for (int i = 0; i < n; i++) {
			strs[i] = sc.next();
		}
		
		Arrays.sort(strs);
		
		for(String str: strs) {
			System.out.print(str);
		}
		System.out.println("");
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i, N)cin >> S[i];
	string ans = "Yes";
	for(int i = 1; i < N; i++){
		if(S[i - 1].at(S[i - 1].size() - 1) != S[i].at(0)){
			ans = "No";
			break;
		}
	}
	SORT(S);
	for(int i = 1; i < N; i++){
		if(S[i - 1] == S[i]){
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
}

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

#define MAX 1010

int memo[MAX][MAX];

int max(int a, int b) {
	if (a >= b)return a;
	else return b;
}

void fill(int p, int q, char X[], char Y[]) {
	if (X[p - 1] == Y[q - 1]) {
		memo[p][q] = memo[p - 1][q - 1] + 1;
	}
	else {
		memo[p][q] = max(memo[p - 1][q], memo[p][q - 1]);
	}
}

int main() {
	int q;
	int x_len, y_len;
	char X[MAX], Y[MAX];

	for (int i = 0; i < MAX; i++) {
		memo[i][0] = 0;
		memo[0][i] = 0;
	}

	scanf("%d", &q);

	for (int i = 0; i < q; i++) {
		scanf("%s%s", X, Y);
		x_len = strlen(X); y_len = strlen(Y);
		for (int p = 1; p <= x_len; p++) {
			for (int q = 1; q <= y_len; q++) {
				fill(p, q, X, Y);
			}
		}
		printf("%d\n", memo[x_len][y_len]);


	}
	return 0;
}


Measured memory_bytes: 5728
//066 
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n; i++)

using namespace std;
int main(void){
    string s,a,b;
    cin >> s;
   
    while(true){
        //cout << s.size() << endl;
        if(s.size()%2==0){               //ランタイムエラー139 添え字が範囲外
            s.erase(s.end()-2, s.end());  //消去(始点、終点)※始点含まず
        }else{
            s.erase(s.end());
        }
        a = s.substr(0, s.size()/2);
        b = s.substr(s.size()/2, s.size()/2);
        if(a==b){
            cout << s.size() << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 300 + 10;
const LL INF = 1e15 + 10;
LL dis[N][N];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            scanf("%lld",&dis[i][j]);
        }
    }
    bool f=true;
    for(int h=1;h<= n;h++) {
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) {
                if(dis[i][h]+dis[h][j]<dis[i][j]) {
                    f = false;
                }
            }
        }
    }
    if(!f) {
        puts("-1");
        return 0;
    }
    LL ans=0;
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            LL minx=dis[i][j];
            LL xmin=INF;
            for(int k=1;k<=n;k++) {
                if(k==i||k==j)    continue;
                xmin=min(xmin,dis[i][k]+dis[k][j]);
            }
            if(minx<xmin) ans+=minx;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

		int[] list = new int[26];
		while (scanner.hasNext()) {
			String a = scanner.nextLine();
			
			for (int i = 0; i < a.length(); i++) {
				int c = a.toLowerCase().codePointAt(i) - 97;
				if (c >= 0)
					list[c]++;
			}
		}

		for (int i = 0; i < list.length; i++) {
			System.out.println(String.format("%s : %d", (char) (i + 97),
					list[i]));
		}

	}
}

Measured memory_bytes: 23920
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int main(){
  while(true){
    int W, Q;
    cin >> W >> Q;

    if(W + Q == 0) break;

    vector<int> e(W, 0);

    REP(i,Q){
      string s;
      cin >> s;
      if(s[0] == 's'){
        int id, w;
        cin >> id >> w; id++;
        REP(j,W) if(j + w <= W && e[j] == 0){
          bool ok = true;
          REP(k,w) if(e[j + k] != 0){
            ok = false; break;
          }
          if(ok){
            printf("%d\n", j);
            REP(k,w) e[j + k] = id;
            goto next;
          }
        }
        puts("impossible");
      next:;
      }else{
        int id;
        cin >> id; id++;
        REP(j,W) if(e[j] == id)
          e[j] = 0;
      }
    }
    puts("END");
  }
  return 0;
}

Measured memory_bytes: 0
use std::io::{BufRead, StdinLock};
use std::str::FromStr;

fn read<T: FromStr>(stdin_lock: &mut StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> T {
    buf.clear();
    let l = stdin_lock.read_until(delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a = read(&mut stdin_lock, &mut buf, b'\n');
    let b = read(&mut stdin_lock, &mut buf, b'\n');
    let c = read(&mut stdin_lock, &mut buf, b'\n');
    let d = read(&mut stdin_lock, &mut buf, b'\n');
    let e = read(&mut stdin_lock, &mut buf, b'\n');
    let k = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(a, b, c, d, e, k));
}

fn solve(a: u8, _: u8, _: u8, _: u8, e: u8, k: u8) -> &'static str {
    if e - a <= k {
        "Yay!"
    } else {
        ":("
    }
}

#[test]
fn example1() {
    assert_eq!("Yay!", solve(1, 2, 4, 8, 9, 15))
}

#[test]
fn example2() {
    assert_eq!(":(", solve(15, 18, 26, 35, 36, 18))
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <bitset>
using namespace std;
typedef long long int ll;

const int NMAX=50050;
const int MMAX=1e5+5;

int n,m,t;
int x[MMAX],y[MMAX];
bitset<NMAX> bs[NMAX];
bool ok[NMAX];
int go[NMAX];
int cnt[NMAX];

void solve1(){
	for(int i=0;i<m;i++){
		bs[x[i]]=bs[y[i]]=bs[x[i]]|bs[y[i]];
	}
	for(int i=0;i<n;i++){
		if(bs[i].count()==n){
			ok[i]=1;
			string ans(m,'^');
			for(int i=m-1;i>=0;i--){
				if(ok[y[i]]){
					ans[i]='v';
				}
				ok[x[i]]=ok[y[i]]=ok[x[i]]|ok[y[i]];
			}
			cout << ans << endl;
			return;
		}
	}
	cout << -1 << endl;
}

void solve2(){
	if(n==2){
		cout << -1 << endl;
		return;
	}
	for(int i=0;i<n;i++){
		go[i]=i;
		cnt[i]++;
	}
	string ans(m,'^');
	for(int i=m-1;i>=0;i--){
		if(cnt[go[x[i]]]>=2){
			ans[i]='v';
			cnt[go[x[i]]]--;
			go[x[i]]=go[y[i]];
			cnt[go[y[i]]]++;
		}else{
			cnt[go[y[i]]]--;
			go[y[i]]=go[x[i]];
			cnt[go[x[i]]]++;
		}
	}
	cout << ans << endl;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m >> t;
	for(int i=0;i<n;i++){
		bs[i][i]=1;
	}
	for(int i=0;i<m;i++){
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}
	if(t==1)solve1();
	else solve2();
}
 

Measured memory_bytes: 307456
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long A, B, C; cin >> A >> B >> C;
	for (long long i = B; i <= C; i++) {
		if (i % A == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

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

using namespace std;
typedef long long ll;
ll n;

ll ts5(ll n) {
	unsigned long long k = n;
	ll ans = 0;
	for (unsigned long long i = 5; k / i != 0; i *= 5)
		ans += k / i;
	return ans;
}
int main() {
	cin >> n;
	if (n < 2 || n % 2 != 0) {
		cout << 0 << endl;
	}
	else {
		cout << ts5(n / 2) << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int C[110][110];
#define INF 1000000
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m),n)
    {
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                C[i][j]=i==j?0:INF;
            }
        }
        for(int i=0;i<m;++i){
            int s;
            scanf("%d",&s);
            if(s){
                int c,d,e;
                scanf("%d%d%d",&c,&d,&e);
                c--;d--;
                if(C[c][d]>e){
                    C[c][d]=e;
                    for(int j=0;j<n;++j){
                        for(int k=0;k<n;++k){
                            C[j][k]=min(C[j][k],C[j][c]+C[c][d]+C[d][k]);
                            C[j][k]=min(C[j][k],C[j][d]+C[d][c]+C[c][k]);
                            C[j][k]=C[k][j]=min(C[j][k],C[k][j]);
                        }
                    }
                }
            }else{
                int a,b;
                scanf("%d%d",&a,&b);
                a--;b--;
                if(C[a][b]==INF)
                    printf("-1\n");
                else
                    printf("%d\n",C[a][b]);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1080
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  ll k, a, b;
	cin >> k >> a >> b;
	ll ans = 1 + k;
	if (b - a > 2) {
		ll x = 1;
		if (x < a) {
			k -= a - x;
			x = a;
		}
		x += (b - a) * (k / 2) + k % 2;
		ans = max(ans, x);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>


using namespace std;

int main(void) {
    long double w,h,x,y;
    cin >> w >> h >> x >> y;
    long double m1,m2;
    m1 = min( x*h, (w-x)*h);
    m2 = min( w*y, w*(h-y));
    // printf("%.14Lf %d\n", max(m1,m2), m1==m2);
    printf("%.14Lf %d\n", w*h/2.0, 2*x==w && 2*y==h);
    // cout << max(m1,m2) << " " << ( m1==m2 ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define repl(i,x,n) for(long long i=(long long)(x);i<(long long)(n);i++)
#define rep(i,x,n) for(long i=long(x);i<long(n);i++)
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long x;
    map<long,long> m;
    rep(i,0,6){
        cin>>x;
        m[x]++;
    }
    vector<long> v;
    for(auto i:m)
        v.push_back(i.second);
    sort(v.begin(),v.end());
    if(v[0]!=1 || v[1]!=1 || v[2]!=2 || v[3]!=2)
        cout<<"NO";
    else
        cout<<"YES";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    vector<bool> used(4, false);
    for(int i=0; i<2; i++){
        int a; cin>>a;
        used[a] = true;
    }
    
    for(int i=1; i<=3; i++){
        if(!used[i]) cout << i << endl;
    }

    return 0;
}

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

void SelectionSort(int *a, int N);
void swap(int *x, int *y);

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    SelectionSort(a,N);

}

void SelectionSort(int *a, int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        swap(a[i],a[minj]);
        if(i != minj) count++;
    }
    for(int i = 0; i < N; i++){
        cout << a[i];
        if(i != N-1) cout << " ";
        else cout << endl;
    }
    cout << count << endl;
    
}

void swap(int *x, int *y){
    int work = *x;
    *x = *y; *y = work;
}


Measured memory_bytes: 3096
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#define LL long long
using namespace std;
int main(){
  LL n,k=0;
  cin>>n;
  for (LL i=1;i * i <= n;i++)
    if (i * i > k)
      k = i * i;
  cout<<k;
  system ("pause");
  return 0;
  }

Measured memory_bytes: 504
import numpy as np

n = int(input())
lst = [[0]*2 for i in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    lst[i][0] = a
    lst[i][1] = b

lst.sort(key=lambda x:(x[1]))

a = np.array(lst).T.tolist()[0]
b = np.array(lst).T.tolist()[1]

time = 0
ans = 'Yes'
for i in range(n):
    time += a[i]
    if time > b[i]:
        ans = 'No'

print(ans)

Measured memory_bytes: 67884
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, w, n) for(int i = w; i < n; i++)
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
const long long INF = 1LL << 60;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(15);
    
    while(true) {
        int x, y; cin >> x >> y;
        if(x == 0 && y == 0) break;
        cout << min(x, y) << ' ' << max(x, y) << endl;
    }

    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define ld long double
#define vii vector<ii>
#define vll vector<ll>
#define maxn 100010

template<typename T>
void trace(T a){ cout << a << '\n';}
template<typename T, typename... Args>
void trace(T a, Args ...args){ cout << a << ' '; trace(args...);}

priority_queue<int> a[maxn];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,x,y;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		if (x <= m)
			a[m-x].push(y);
	}
	int ans = 0;
	for (int i = m; i >= 0; --i) {
		if (a[i].empty()) continue;
		ans += a[i].top();
		a[i].pop();
		for (int j = i-1; !a[i].empty() && j >= 0; --j) {
			a[j].push(a[i].top());
			a[i].pop();
		}
	}
	trace(ans);
 	return 0;
}



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

typedef struct _treeNode{
  struct _treeNode *right;
  struct _treeNode *left;
  struct _treeNode *parent;
  int key;
}Node;

Node *root;

void insert(int);
void inorder(Node*);
void preorder(Node*);

int main(){
  int command_N;
  int key;
  char command[7];

  scanf("%d",&command_N);
  for(int i=0;i<command_N;i++){
    scanf("%s",command);
    if(strcmp(command,"insert")==0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(command,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

return 0;
}

void insert(int key){
  Node *in;
  Node *current=root;
  Node *pre=NULL;

  in=(Node*)malloc(sizeof(Node));
  in->key=key;
  in->left=NULL;
  in->right=NULL;

  while(current!=NULL){
    pre=current;
    if(in->key<current->key){
      current=current->left;
    }
    else{
      current=current->right;
    }
  }
  in->parent=pre;
  if(pre==NULL){ //空
    root=in;
  }else{
    if(in->key<pre->key){
      pre->left=in;
    }else{
      pre->right=in;
    }
  }
}

void inorder(Node *node){
  if(node==NULL) return;
  inorder(node->left);
  printf(" %d",node->key);
  inorder(node->right);
}

void preorder(Node *node){
  if(node==NULL) return;
  printf(" %d",node->key);
  preorder(node->left);
  preorder(node->right);
}



Measured memory_bytes: 25176
//*
#include <bits/stdc++.h>
//*/
/*
#include <iostream>
#include <vector>
#include <string.h>
//*/
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;
const ll LLINF = LLONG_MAX / 10;
//typedef pair<int, int> P;
typedef pair<double, double> P;

int A, B, C, D, E, F;

signed main()
{
    cin >> A >> B >> C >> D >> E >> F;

    double noudo = 0.0;
    int ansA = 100 * A;
    int ansB = 0;
    for (int w1=0; w1<=F; w1+=100*A) {
        for (int w2=0; w2<=F-w1; w2+=100*B) {
            for (int s1=0; s1<=F-w1-w2; s1+=C) {
                for (int s2=0; s2<=F-w1-w2-s1; s2+=D) {
                    if ((w1 + w2) / 100 * E < s1 + s2) continue;
                    if (noudo < 1.0 * (s1 + s2) / (w1 + w2)) {
                        noudo = 1.0 * (s1 + s2) / (w1 + w2);
                        ansA = w1 + w2 + s1 + s2;
                        ansB = s1 + s2;
                    }
                }
            }
        }
    }

    cout << ansA << " " << ansB << endl;
}


Measured memory_bytes: 384
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int x = Integer.parseInt(sc.next());
    int y = Integer.parseInt(sc.next());
    for (int i = 0; i <= x; i++) {
      int a = i * 4;
      int b = (x - i) * 2;
      if (a + b == y) {
        pw.println("Yes");
        return;
      }
    }
    pw.println("No");
  }
}


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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef __int128 Long;

inline Long f(Long x){
	if (x > 0) return x;
	return -x;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	LL x, k, d;
	cin >> x >> k >> d;
	if (x < 0) x = -x;

	Long lft = x - k * (Long) d;	
	Long ans = f(lft);
	
	if (lft < 0){
		LL cand1 = x % d;
		LL cand2 = cand1 - d;
		LL do1 = (x - cand1) / d;
		if (do1 % 2 == k % 2) setmin(ans, (Long) f(cand1));
		else setmin(ans, (Long) f(cand2));
	}

	cout << (LL) ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, fv;
    string s;

    cin >> s;

    n = s.size();

    for (i = 0; i < n - 1; i++) {
        if (s[i] != s[n - i - 2]) {
            printf("-1\n");
            return 0;
        }
    }

    if (s[0] == '0' || s[n - 1] == '1') {
        printf("-1\n");
        return 0;
    }

    fv = 1;
    for (i = 2; i <= n / 2 + 1; i++) {
        printf("%d %d\n", fv, i);
        if (s[i - 2] == '1') {
            fv = i;
        }
    }

    if (s[n / 2 - 1] == '1') {
        fv = n / 2 + 1;
    }

    for (i = n / 2 + 2; i <= n; i++) {
        printf("%d %d\n", fv, i);
    }

    return 0;
}

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

const int N = 110;

int dp[N][N][N][2];
int moder;
int comb[N][N], power[N][N];

void addmult(int &a, int b, int c){a = (a + 1ll * b * c) % moder;}

int main(){
    int n, m, k;
    scanf("%d%d%d%d", &n, &m, &k, &moder);
    for (int i = 0; i < N; ++ i){
        comb[i][0] = 1;
        for (int j = 1; j <= i; ++ j){
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % moder;
        }
        power[i][0] = 1;
        for (int j = 1; j < N; ++ j){
            power[i][j] = 1ll * power[i][j - 1] * i % moder;
        }
    }
    dp[1][0][0][0] = 1;
    for (int i = 1; i <= k; ++ i){
        for (int j = 0; j <= n; ++ j){
            for (int K = 0; K <= m; ++ K){
                int now = dp[i][j][K][0], coe1 = power[k - i + 1][j], coe2 = power[i][n - j] - power[i - 1][n - j];
                coe2 += coe2 < 0 ? moder : 0;
                int coe = 1ll * coe1 * coe2 % moder;
                for (int u = 0; K + u <= m; ++ u){
                    addmult(dp[i][j][K + u][1], now, comb[m - K][u]);
                    now = 1ll * coe * now % moder;
                }
            }
        }
        for (int j = 0; j <= n; ++ j){
            for (int K = 0; K <= m; ++ K){
                int now = dp[i][j][K][1], coe1 = power[k - i + 1][K] - power[k - i][K], coe2 = power[i][m - K];
                coe1 += coe1 < 0 ? moder : 0;
                int coe = 1ll * coe1 * coe2 % moder;
                for (int u = 0; j + u <= n; ++ u){
                    addmult(dp[i + 1][j + u][K][0], now, comb[n - j][u]);
                    now = 1ll * coe * now % moder;
                }
            }
        }
    }
    printf("%d\n", dp[k + 1][n][m][0]);
    return 0;
}


Measured memory_bytes: 10368
import math
n=int(input())
arr=list(map(int,input().split()))
a=True

if n%2!=0:
    if len([0 for c in arr if c==0])!=1:
    	a=False
    elif len(set(arr))!=int(n/2)+1:
        a=False
else:
    if 0 in arr:
        a=False
    elif len(set(arr))!=int(n/2):
        a=False

if a:
    print(2**math.floor(n/2)%((10**9)+7))
else:
    print(0)

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >>d[i];
	SORT(d);
	//a[n/2]は含んで良いa[n/2 - 1]は含んじゃダメ
	cout << d[n/2] - d[n/2 -1] << endl;
}


Measured memory_bytes: 640
use std::io;
use std::str::FromStr;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn binary_power(x: u64, n: u64) -> u64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}
  
fn inverse_mod(n: u64) -> u64 {
    binary_power(n, MOD-2)
}  

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret %= MOD;
        ret *= n - i;        
    }
    ret %= MOD;

    let mut div = 1u64;
    for i in 1..(m+1) {
        div %= MOD;
        div *= i;
    }
    div %= MOD;

    // println!("{}, {}", ret, div);
    ret * inverse_mod(div) % MOD
}

fn main() {
    let (n, k) = input_tuple();
    if k >= n {
        // 全組み合わせ
        println!("{}", combination(n * 2 - 1, n - 1));
        return;
    }
    let mut sum = 0;
    let mut c1 = combination(n, n - k);
    let mut c2 = combination(n - 1, k);
    for i in (n-k)..(n+1) {
        // println!("{}, {}", c1, c2);
        sum = sum + c1 % MOD * c2 % MOD;
        sum %= MOD;

        c1 = c1 * (n - i) % MOD * inverse_mod(i + 1) % MOD;
        c2 = c2 * (n - i) % MOD * inverse_mod(i) % MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;
int main(){
  int N;
  cin>>N;
  cout<<N/3<<endl;
}  
  

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll K,Q;
  cin>>K>>Q;
  ll D[K];
  REP(i,K) cin>>D[i];
  REP(q,Q){
    ll N,X,M,S=0,ans=0;
    cin>>N>>X>>M;
    
    ll E[K];
    REP(i,K){
      E[i]=D[i]%M;
      if(E[i]==0) E[i]=M;
      S+=E[i];
    }
    
    X%=M;
    X+=(N-1)/K*S;
    REP(i,(N-1)%K) X+=E[i];
    
    ans=N-1-X/M;
    co(ans);
  }
  return 0;
}

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

bool g[55][55];  // グラフ
vector<bool> went(55);
int n, m;

void dfs(int now) {
  went[now] = true;  // 訪れた

  for (int i = 0; i < n; i++) {
    if (g[now][i] && !went[i]) {  // 橋がかかっていて、行ったことがないなら
      dfs(i);
    }
  }
}

int main() {
  cin >> n >> m;
  int a[m], b[m];  // 橋の情報
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]][b[i]] = true;  // 橋をつなぐ
    g[b[i]][a[i]] = true;
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    g[a[i]][b[i]] = false;                         // 橋の片方を切断する
    for (int i = 0; i < 55; i++) went[i] = false;  // 初期化
    dfs(a[i]);                                     // aの方から探索させる
    if (n != accumulate(went.begin(), went.end(), 0)) ans++;
    g[a[i]][b[i]] = true;  // 橋をつなげる
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long double ld;
typedef long long ll;

using namespace std;

void pr(ll x){
	cout << x << endl; exit(0);
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, m; cin >> n >> m;
    if(n == 1 || m == 1){
    	ll z = n * m;
    	if(z == 1) cout << 1 << endl;
    	else cout << z - 2 << endl; 
    	return 0;
    }
    ll corners = 4;
    ll inborder = 2 * n + 2 * m - 8;
    ll inside = n * m - inborder - corners;

    cout << inside << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use std::collections::HashMap;
use std::cmp::min;

fn main() {
    input! {
        n:usize,
        xyd:[(i64,i64,char);n]
    };
    let mut dirmp = HashMap::new();
    dirmp.insert('R',0);
    dirmp.insert('L',1);
    dirmp.insert('U',2);
    dirmp.insert('D',3);

    let dxy:Vec<(i64,i64)> = vec![(1,0),(-1,0),(0,1),(0,-1)];

    let xyd:Vec<(i64,i64,usize)> = {
        xyd.into_iter().map(|(x,y,d)|(x*2,y*2,dirmp[&d])).collect()
    };

    let xyd = {
        let mut xyd_sml = Vec::new();
        for i in 0..4 {
            if let Some(e) = xyd.iter().filter(|&(_,_,d)|*d==i).max_by_key(|&(x,_,_)|x) {
                xyd_sml.push(*e);
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)|*d==i).min_by_key(|&(x,_,_)|x) {
                xyd_sml.push(*e);
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)|*d==i).max_by_key(|&(_,y,_)|y) {
                xyd_sml.push(*e);
            }
            if let Some(e) = xyd.iter().filter(|&(_,_,d)|*d==i).min_by_key(|&(_,y,_)|y) {
                xyd_sml.push(*e);
            }
        }
        xyd_sml
    };

    let ts = {
        let mut ts = vec![0];
        for &(x1,y1,d1) in &xyd {
            for &(x2,y2,d2) in &xyd {
                let dx = dxy[d1].0-dxy[d2].0;
                let dy = dxy[d1].1-dxy[d2].1;
                if dx!=0 {
                    let t = (x2-x1)/dx;
                    if 0<=t {
                        ts.push(t);
                    }
                }
                if dy!=0 {
                    let t = (y2-y1)/dy;
                    if 0<=t {
                        ts.push(t);
                    }
                }
            }
        }
        ts
    };

    let mut ans = std::i64::MAX;
    for t in ts {
        let max_x = xyd.iter().map(|&(x,_,d)|{
            let dx = dxy[d].0;
            x+dx*t
        }).max().unwrap();
        let min_x = xyd.iter().map(|&(x,_,d)|{
            let dx = dxy[d].0;
            x+dx*t
        }).min().unwrap();

        let max_y = xyd.iter().map(|&(_,y,d)|{
            let dy = dxy[d].1;
            y+dy*t
        }).max().unwrap();
        let min_y = xyd.iter().map(|&(_,y,d)|{
            let dy = dxy[d].1;
            y+dy*t
        }).min().unwrap();
        let sz = (max_x-min_x)*(max_y-min_y);
        ans = min(ans,sz);
    }

    println!("{}",ans as f64/4.0);

}

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

int a[1000010];
bool r[100], c[100];
string s[100];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n, m, k, ans = 0;
    cin >> n >> m >> k;
    for(int i=0;i<n;i++) cin >> s[i];
    for(int i=0;i<(1<<(n+m));i++){
        memset(r, 0, sizeof(r));
        memset(c, 0, sizeof(c));
        for(int j=0;j<n+m;j++){
            if((i>>j)&1){
                if(j >= n) c[j-n] = 1;
                else r[j] = 1;
            }
        }
        int cnt = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(r[i]) continue;
                if(c[j]) continue;
                if(s[i][j] == '#') cnt++;
            }
        }
        if(cnt == k) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3780
#include <stdio.h>

int main() {
	long H, N, S=0, i, j, ans;
	scanf("%ld %ld", &H, &N);
	for (i = 0; i < N; i++) {
		j = 0;
		scanf("%ld", &j);
		S += j;
	}

	if (S >= H) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;
Node find(Node u,int k){
  if(u==NIL||u->key==k)
    return u;
  if(u->key > k)
    return find(u->left,k);
  else
    return find(u->right,k);
}
void insert(int k){
   Node y = NIL;
   Node x = root;
   Node z;
   
   z =malloc(sizeof(struct node));
   z->key = k;
   z->left = NIL;
   z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key < x->key)x=x->left;
     else x=x->right;
   }
   z->parent=y;
   if(y==NIL)root=z;
   else if(z->key <y->key)
   y->left=z;
   else
     y->right=z;
}

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

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

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

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


signed main() {

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);

    for(auto&&i:a) cin >> i;
    for(auto&&i:b)cin >> i;
    for(auto&&i:c)cin >> i;

    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    ll sum = 0;
    
    for(int i = 0; i < n; i++)
        sum += (lower_bound(ALL(a), b[i]) - a.begin()) * (c.end() - upper_bound(ALL(c), b[i]));
    cout << sum << endl;
    
    return 0;
}



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

int main()
{
  int n, q;
  cin >> n >> q;
  vector<pair<int, int>> tree(n, {-1, 0});

  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[b].first = a;
  }

  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    tree[p].second += x;
  }

  map<int, int> mp;

  for (int i = 0; i < n; i++) {
    int64_t ans = 0;
    int p = i;
    while (p >= 0) {
      if (mp.count(p) != 0) {
        ans += mp[p];
        break;
      }
      ans += tree[p].second;
      p = tree[p].first;
    }
    mp[i] = ans;
    cout << ans << endl;
  }
}


Measured memory_bytes: 13312
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

void operate(int* ori, int* next, const int* ope, int dir)
{
	for (int i = 0; i < 4; ++i)
		next[ope[(i+dir) % 4]] = ori[ope[i]];
}
int main()
{
	const int NS[] = { 0, 4, 5, 1 };
	const int EW[] = { 0, 2, 5, 3 };
	const int RL[] = { 1, 3, 4, 2 };
	const char* s = "NSEWRL";
	const int* op[] = { NS, NS, EW, EW, RL, RL };
	const int dir[] = { 1, 3, 1, 3, 1, 3 };
	int n;
	while (scanf("%d", &n), n)
	{
		int res = 1;
		int dice[] = { 1, 2, 3, 4, 5, 6 };
		while (n--)
		{
			char buf[16];
			scanf("%s", buf);

			int ori[6];
			memcpy(ori, dice, sizeof(ori));
			int t = strchr(s, buf[0]) - s;
			operate(ori, dice, op[t], dir[t]);
			res += dice[0];
		}
		printf("%d\n", res);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int ans = 0;
        int now = 0;
        int pre = 0;
        rep(i, 0, n){
            string s;
            cin >> s;
            if(s == "lu") now += 2;
            if(s == "ru") now += 1;
            if(s == "ld") now -= 2;
            if(s == "rd") now -= 1;
            if(now == 3 && pre == 0){
                ans++;
                pre = 1;
            }else if(now == 0 && pre == 1){
                ans++;
                pre = 0;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3144