akhauriyash/Code-Regression huggingface dataset:
def main():
    K = int(input())

    MAX = 10

    def search(base):
        if len(base) == MAX:
            # print(base)
            return [base]
        else:
            result = [base]
            last = base[-1]
            if last != '9':
                # print('A', base + str(int(last) + 1))
                result.extend(search(base + str(int(last) + 1)))
            if last != '0':
                # print('B', base + str(int(last) - 1))
                result.extend(search(base + str(int(last) - 1)))
            # print('C', base + last)
            result.extend(search(base + last))
            return result

    runrun = []

    for i in range(0, 10):
        el = search(str(i))
        # print(i, el)
        runrun.extend(el)

    runrun_i = list(map(int, list(map(lambda x: x[::-1], runrun))))
    runrun_u = list(set(runrun_i))
    runrun_s = sorted(runrun_u)

    # print(runrun_s)

    print(runrun_s[K])


if __name__ == '__main__':
    main()


Measured memory_bytes: 41600
program main
      character(3) :: s
      integer(4) :: i

      read(*,*) s
      if ( s(1:1) == s(2:2) ) then

        if ( s(2:2) == s(3:3) ) then
          print *, 'No'
        else
          print *, 'Yes'
        end if
      else
        print *, 'Yes'
      end if

end program main


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
        ab: [(usize, usize); m],
    }
    let mut adjacency_max = vec![0; n];
    for (a, b) in ab {
        adjacency_max[a - 1] = adjacency_max[a - 1].max(h[b - 1]);
        adjacency_max[b - 1] = adjacency_max[b - 1].max(h[a - 1]);
    }
    println!(
        "{}",
        adjacency_max
            .iter()
            .zip(h)
            .filter(|(nei, nod)| nod > nei)
            .count()
    );
}


Measured memory_bytes: 7316
#include<bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main(){
  int n;
  cin >> n;
  vector<int> add_i;
  int before = -INF;
  for(int i = 0, temp; i < n; ++i){
    cin >> temp;
    if(temp - before == 1) add_i.push_back(before - 1);
    before = temp;
  }
  int ans = 0;
  for(int i = 0, temp; i < n; ++i){
    cin >> temp;
    ans += temp;
  }
  vector<int> add(n - 1);
  for(int i = 0; i < n - 1; ++i){
    cin >> add[i];
  }
  for(int i: add_i) ans += add[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
//const ll MOD=1e9+7;
const ll MOD=998244353;
const ll MAX=1e7;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
signed main(){
    int N; cin>>N;
    vii Edge(N);
    rep(i,1,N){
        int X,Y; cin>>X>>Y;
        Edge[X-1].pb(Y-1);
        Edge[Y-1].pb(X-1);
    }
    int K; cin>>K;
    vi max(N,INF),min(N,-INF);
    prique<pii> max_que;
    std::priority_queue<pii> min_que;
    rep(i,0,K){
        int X,Y; cin>>X>>Y;
        max[X-1]=Y;
        min[X-1]=Y;
        max_que.push(mp(Y,X-1));
        min_que.push(mp(Y,X-1));
    }
    while(max_que.size()>0){
        int X=max_que.top().second,Y=max_que.top().first;
        max_que.pop();
        if(max[X]<Y) continue;
        rep(i,0,Edge[X].size()){
            int Z=Edge[X][i];
            if(max[Z]!=INF&&max[Z]%2==Y%2){
                cout<<"No"<<endl;
                return 0;
            }
            if(max[Z]>Y+1){
                max[Z]=Y+1;
                max_que.push(mp(Y+1,Z));
            }
        }
    }
    while(min_que.size()>0){
        int X=min_que.top().second,Y=min_que.top().first;
        min_que.pop();
        if(min[X]>Y) continue;
        rep(i,0,Edge[X].size()){
            int Z=Edge[X][i];
            if(min[Z]<Y-1){
                min[Z]=Y-1;
                min_que.push(mp(Y-1,Z));
            }
        }
    }
    rep(i,0,N){
        if(max[i]<min[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,0,N) cout<<max[i]<<endl;
}
 

Measured memory_bytes: 11664
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>

using namespace std;

using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const ll INF = (1e+18)+100;
#define rep(i, n) for(int i=0;i<n;++i)
#define repl(i, l, n) for(int i=l;i<n;++i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

typedef long double ld;

void solve() {
	int m1, m2, d1, d2; cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    int a = 1, b = n;
    for (int i = 0; i < m; ++i) {
        if (n % 2 == 0 && (b - a) * 2 <= n) {
            cout << a << ' ' << b - 1 << '\n';
        } else {
            cout << a << ' ' << b << '\n';
        }
        ++a, --b;
    }
    


    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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

    vector<int> a(N + 1);
    vector<int> b(N + 1, -1);
    vector<int> ans;

    rep(i, N) {
        cin >> a[i + 1];
    }

    for(int i = N; i >= 1; i--) {
        IFD cout << "i: " << i << endl;
        int c = 0;
        for(int j = N / i; j >= 1; j--) {
            int v = j * i;
            IFD cout << v << endl;
            if(i == v) {
                b[v] = a[v] ^ c;
                if(b[v] == 1) {
                    ans.push_back(v);
                }
            } else {
                c ^= b[v];
            }
        }
    }
    IFD cout << endl;

    IFD {
        rep(i, N) {
            cout << b[i + 1] << " ";
        }
        cout << endl << endl;
    }

    cout << ans.size() << endl;
    if(ans.size() != 0) {
        rep(i, ans.size()) {
            cout << ans[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		String op = saori.nextHayami();
		int b = saori.saori_hayami();
		if(op.equals("+")){
			System.out.println(a+b);
		} else {
			System.out.println(a-b);
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  multiset<string> s;
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    string t; cin >> t;
    s.insert(t);
  }
  int m; cin >> m;
  for (int i = 0; i < m; i++) {
    string t; cin >> t;
    auto it = s.find(t);
    if (it != s.end()) s.erase(it);
  }
  int ans = 0;
  for (auto i : s) {
    ans = max(ans, (int) s.count(i));
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3632
package main

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

func main() {
	N := nextInt()
	M := nextInt()

	A := make([]int, M)
	C := make([]int, M)

	for i := 0; i < M; i++ {
		A[i] = nextInt()
		b := nextInt()

		for j := 0; j < b; j++ {
			c := nextInt() - 1
			C[i] |= (1 << uint(c))
		}
	}
	inf := 1 << 29

	max := 1 << uint(N)
	dp := make([]int, max)

	for i := 0; i < max; i++ {
		dp[i] = inf
	}
	dp[0] = 0

	for s := 0; s < max; s++ {
		for i := 0; i < M; i++ {
			t := s | C[i]
			cost := dp[s] + A[i]
			dp[t] = min(dp[t], cost)
		}
	}

	ans := dp[max-1]
	if ans == inf {
		ans = -1
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 768
import java.io.*;

public class Main {
    
    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in1 = br.readLine().split(" ");
        int a = Integer.parseInt(in1[0]);
        int b = Integer.parseInt(in1[1]);
        br.close();

        if(a <= 0 && b >= 0){
            System.out.println("Zero");
        }else if(a > 0){
            System.out.println("Positive");
        }else if((b - a) % 2 == 1){
            System.out.println("Positive");
        }else{
            System.out.println("Negative");
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>

std::vector<long long> enumDivisors(long long n){
    std::vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(i*i == n){
            res.push_back(i);
        }else{
            if(n%i == 0){
                res.push_back(i);
                res.push_back(n/i);
            }
        }
    }
    return res;
}

int main(){
    long long n;
    std::cin >> n;
    int count = 0;
    for(long long item : enumDivisors(n)){
        if(item == 1) continue;
        long long tmp = n;
        while(tmp % item == 0){
            tmp /= item;
        }
        if(tmp % item == 1) count++;
    }
    count += enumDivisors(n-1).size()-1;
    std::cout << count << std::endl;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int H=sc.nextInt(),W=sc.nextInt(),h=sc.nextInt(),w=sc.nextInt();
		int ans=H*W-(h*W+w*H-h*w);
		out.println(ans);
		
		
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

#define int long long

using P = pair<int, int>;

int n, m, x;
int h[100000];
vector<P> g[100000];
int dist[100000];

signed main()
{
	scanf("%lld %lld %lld", &n, &m, &x);
	for (int i = 0; i < n; i++){
		scanf("%lld", h + i);
	}
	for (int i = 0; i < m; i++){
		int a, b, c;
		scanf("%lld %lld %lld", &a, &b, &c), a--, b--;
		if (h[a] >= c) g[a].emplace_back(b, c);
		if (h[b] >= c) g[b].emplace_back(a, c);
	}

	priority_queue<P, vector<P>, greater<P>> pq;
	fill_n(dist, 100000, 1e18);
	dist[0] = 0;
	pq.emplace(0, 0);
	while (pq.size()){
		int sum, v;
		tie(sum, v) = pq.top(); pq.pop();
		if (dist[v] < sum) continue;
		for (P e : g[v]){
			int to, cost;
			tie(to, cost) = e;
			int nsum = max(sum + cost, x - h[to]);
			if (dist[to] > nsum){
				dist[to] = nsum;
				pq.emplace(nsum, to);
			}
		}
	}

	int d = dist[n - 1];
	if (d == (int)(1e18)){ puts("-1"); return 0; }

	printf("%lld\n", d * 2 + h[n - 1] - x);
}

Measured memory_bytes: 23188
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	string s[3];
	cin >> s[0] >> s[1] >> s[2];

	int pos[3] = { 0,0,0 };
	int sz[3] = { s[0].size(), s[1].size(), s[2].size() };
	int turn = 0;
	while (pos[turn] < sz[turn]) {
		int tmp = turn;
		turn = s[turn][pos[turn]] - 'a';
		pos[tmp]++;
	}
	cout << (char)(turn + 'A') << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<math.h>

using namespace std;

int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >>  c[i];
    }
    int dp[3][n+1];
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 1; i < n; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][n-1], dp[1][n-1]), dp[2][n-1]) <<endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	vector<pair<int, int>>vs(5);
	while (cin >> vs[0].first >> vs[0].second) {
		if (vs[0].first == 0)break;
		for (int i = 1; i < 5; ++i) {
			cin >> vs[i].first >> vs[i].second;
		}
		int ans=0;
		int sum = 0;
		for (int i = 0; i < 5; ++i) {
			if (sum < vs[i].first + vs[i].second) {
				sum = vs[i].first + vs[i].second;
				ans = i;
			}
		}
		cout << char('A' + ans) << " " << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String n = sc.next();

        String result = "No";
        if (n.charAt(0) == '9' || n.charAt(1) == '9') result = "Yes";

        System.out.println(result);
    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}

	static class Task {
		static int MAX = 1000000001;
		
		int N, K;
		int[] W;

		void solve(InputReader in, PrintWriter out) {
			N = in.nextInt();
			K = in.nextInt();
			W = in.nextIntArray(N);

			int ans = Integer.MAX_VALUE;
			int low = 0, high = MAX, mid;
			while (low < high - 1) {
				mid = (low + high) / 2;
				
				int k = 1;
				int p = mid;
				int cur = 0;
				
				for (int i = 0; i < N; ++i) {
					if (p < W[i]) {
						k = Integer.MAX_VALUE;
						break;
					}
					cur += W[i];
					if (cur > p) {
						k++;
						cur = W[i];
					}
				}
				
				if (k > K) {
					low = mid;
				} else {
					high = mid;
					ans = Math.min(ans, p);
				}
			}
			
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; ++i) {
				arr[i] = nextInt();
			}
			return arr;
		}

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

		long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; ++i) {
				arr[i] = nextLong();
			}
			return arr;
		}
	}
}



Measured memory_bytes: 43076
N = int(input())
t0 = x0 = y0 = 0
for _ in range(N):
    t1, x1, y1 = map(int, input().split())
    d = abs(x1 - x0) + abs(y1 - y0)
    if d > t1 - t0 or d % 2 != (t1 - t0) % 2:
        print('No')
        exit()
    t0, x0, y0 = t1, x1, y1
print('Yes')


Measured memory_bytes: 46056
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
ll N;

void dfs(ll cur,ll use,ll &counter){
    if(cur>N) return;
    if(use==0b111) counter++;

    dfs(cur*10+7,use|0b001,counter);

    dfs(cur*10+5,use|0b010,counter);

    dfs(cur*10+3,use|0b100,counter);
}

int main() {
    cin>>N;
    ll ans=0;
    dfs(0,0,ans);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int n,ans=0;
    cin>>n;
    
    int p[n];
    
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    
    sort(p,p+n);
    
    for(int j=0;j<n-1;j++){
        ans+=p[j];
    }
    
    ans+=p[n-1]/2;
    
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 256
N=gets.chomp.to_i
W=gets.chomp.split.map(&:to_i)

ans=100000000
(0..(N-2)).each do |i|
  a=W[0..i].inject {|sum, n| sum + n }
  b=W[(i+1)..(N-1)].inject {|sum, n| sum + n }
  ans=(a-b).abs if ans>((a-b).abs)
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;

	int n, s[200] = {}, num[200000] = {}, result = 0, lamp = 1, in, ax, h, w, m, a, b, c, d, r;
	string str, str2;
	long long int tmp;
	char memo;
	cin >>tmp;
	n = str.length();
	in = n;
  tmp++;
	for (int i = 0; i < 20; i++) {
		if (tmp / 10 != 0) { tmp /= 10; continue; }
		else {
			cout << tmp % 10 + i * 9-1;break;
		}
	}

}

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

int gcd(int x, int y){
  int r;
  if ( x < y ) swap (x, y);

  while( y > 0 ){
    r = x %y;
    x = y;
    y = r;
  }
  return x;
}

main(){
  int a, b;
  cin >> a >> b;
  cout << gcd(a, b) << endl;
}




Measured memory_bytes: 3092
n, k = map(int, input().split())
dic = {}
a = map(int, input().split())
for i in a:
    if int(i) in dic:
        dic[int(i)] += 1
    else:
        dic[int(i)] = 1
len_all = len(dic.keys())
a = [[i, dic[i]] for i in dic.keys()]
a = sorted(a, key=lambda x: x[1])

ans = 0
if k == len_all:
    print(0)
else:
    for i in range(len_all - k):
        ans += a[i][1]
    print(ans)


Measured memory_bytes: 45388
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

    static int w, h, x, y, r;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        w = Integer.parseInt(st[0]);
        h = Integer.parseInt(st[1]);
        x = Integer.parseInt(st[2]);
        y = Integer.parseInt(st[3]);
        r = Integer.parseInt(st[4]);

        if (x + r > w || x - r < 0 || y + r > h || y - r < 0) {
            System.out.println("No");
            return;
        }

        System.out.println("Yes");

        bw.flush();
    }

}


Measured memory_bytes: 24428
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

void	lcm(ll &a, ll &b)
{
	ll i = 1, j = 1;
	while (a*i != b*j)
	{
		ll A = a*i, B = b*j;
		if (A < B)
			i = (B + a - 1) / a;
		else
			j = (A + b - 1) / b;
		//cout << a*i << " " << b*j << endl;
	}
	a *= i;
	b *= j;
}

int		main(void)
{
	int N;
	cin >> N;
	vector<ll> T(N);
	for (int i = 0; i < N; i++)
		cin >> T[i];
	for (int i = 0; i < N-1; i++)
	{
		lcm(T[i], T[i+1]);
	}
	cout << T[N-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define name "a"
using namespace std;
string s;
long long res, k, du;
void nhap(){
    cin >> s;
    cin >> k;
}

void xuli(){
    string tmps = s;
    int n = s.size();
    res = 0;
    for (int i = 1; i < n; i++){
        if (s[i] == s[i - 1]){
            if (i < n - 1){
                s[i] = s[i + 1] + 1;
            }
            else {
                s[i] = s[0] + 1;
            }
            res++;
        }
    }
    long long res1 = res;
    if (k == 1){
        cout << res1;
        return;
    }
    s = tmps + tmps;
    res = 0;
    n = s.size();
    for (int i = 1; i < n; i++){
        if (s[i] == s[i - 1]){
            if (i < n - 1){
                s[i] = s[i + 1] + 1;
            }
            else {
                s[i] = s[0] + 1;
            }
            res++;
        }
    }
    if (s[n - 1] == s[0])
        res = (res - res1) * (k - 1) + res1;
    else {
        res = res * (k / 2);
        if (k%2 == 1)res +=res1;
    }
   // cout << s << endl;
    cout << res;
}

int main(){
   // freopen(name".inp", "r",stdin);
   // freopen(name".out", "w",stdout);
    nhap();
    xuli();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll dp[n+1][n+1]={{0}};
  /*  for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=n;j++)
        cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    for(ll i=0;i<n;i++)
    dp[0][i]=1;
    ll m=1000000007;
    for(ll i=1;i<n;i++)
    {
        if(s.at(i-1)=='>')
        {
          ll r=0;
          for(ll j=n-i-1;j>=0;j--)
          {
              r=(r+dp[i-1][j+1])%m;
              //cout<<"nh "<<dp[i-1][j+1]<<endl;
              //cout<<j<<" hjh "<<r<<endl;
              dp[i][j]=(dp[i][j]+r)%m;
          }
        }
        else
        {
            ll r=0;
            for(ll j=0;j<n-i;j++)
            {
                r=(r+dp[i-1][j])%m;
                //cout<<"no  "<<dp[i-1][j]<<endl;
                //cout<<j<<" yjh "<<r<<endl;
                dp[i][j]=(dp[i][j]+r)%m;

            }
        }
    }
    //for(ll i=0;i<n;i++)
    //{
      //  for(ll j=0;j<n-i;j++)
       // {
            //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        //}
    //}
    cout<<dp[n-1][0]<<endl;
    return 0;
}
    
       

Measured memory_bytes: 70656
import itertools
n,m,r=map(int,input().split());R=min(r,8)
d = [[10**12for i in range(n)]for j in range(n)]
l=list(map(int,input().split()))
for i in range(r):
  l[i]-=1
for i in range(m):
  a,b,c=map(int,input().split())
  d[a-1][b-1]=d[b-1][a-1] = c
for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j]=min(d[i][j], d[i][k]+d[k][j])
#print(d)
ans=10**12
for v in itertools.permutations(l, R):
  cnt=0
  for i in range(1,R):
    cnt+=d[v[i-1]][v[i]]
  ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 46936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] a = new int[N];
		int total = 0;
		for(int i=0;i<N;i++) {
			a[i] = scanner.nextInt();
			total+=a[i];
		}
		double av = (double)total/(double)N;
		float ave = Math.round(av);
		float cost = 0;
		for(int i=0;i<N;i++) {
			cost+=(a[i]-ave)*(a[i]-ave);
		}
		System.out.println((int)cost);
		scanner.close();
	}

}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define INF 1000000007
using namespace __gnu_pbds;
using namespace std;

int h,w,k,sum[20],cur[20];
int c[20][1010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
		char s;cin>>s;
		c[i][j]=s-'0';
	}
	int ans=INF;
	for(int i=0;i<(1<<(h-1));i++){
		int num=__builtin_popcount(i);
		for(int j=1;j<=h;j++) sum[j]=0;
		for(int j=1;j<=w;j++){
			int cnt=1;
			for(int l=1;l<=h;l++) cur[l]=0;
			for(int l=1;l<=h;l++){
				cur[cnt]+=c[l][j];
				if(l<h){
					if(i&(1<<(l-1))) cnt++; 
				}
			}
			bool flag=true;
			for(int l=1;l<=cnt;l++){
				if(cur[l]>k){
					flag=false;break;
				}
			}
			if(!flag){
				num=INF;
				break;
			}
			for(int l=1;l<=cnt;l++){
				if(sum[l]+cur[l]>k){
					flag=false;break;
				}
			}
			if(!flag){
				num++;
				for(int l=1;l<=cnt;l++) sum[l]=cur[l];
			}
			else{
				for(int l=1;l<=cnt;l++) sum[l]+=cur[l];
			}
		}
		ans=min(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<long long> s(n+1);
  s[0]=0;
  for(int i=0; i<n; i++){
    long long a;
    cin>>a;
    s[i+1]=s[i]+a;
  }

  sort(s.begin(), s.end());
    
  long long ans=0LL,fl=1;
  for(int i=0; i<n; i++){
    if(s[i]==s[i+1])fl++;
    else{
      ans+=fl*(fl-1)/2;
      fl=1;
    }
  }
  ans+=fl*(fl-1)/2;

  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		char[][] a = new char[n][];
		for (int i = 0; i < n; i++)
			a[i] = sc.next().toCharArray();
		
		char[][] b = new char[m][];
		for (int i = 0; i < m; i++)
			b[i] = sc.next().toCharArray();
		
		String ans = "No";
		outer:
		for (int i = 0; i < n - m + 1; i++) {
			next:
			for (int j = 0; j < n - m + 1; j++) {
				for (int k = 0; k < m; k++) {
					for (int l = 0; l < m; l++) {
						if (a[i + k][j + l] != b[k][l]) continue next;
					}
				}
				ans = "Yes";
				break outer;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
	
}




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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<ll> a(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) a[i] += a[i - 1];

    ll min_v = 1e9 * (n + 1);
    for (int i = 1; i < n; ++i) {
        ll x = a[i], y = (a[n] - a[i]);
        if (abs(x - y) < min_v) min_v = abs(x - y);
    }

    cout << min_v << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main() {
	string s,t;
	cin>>s>>t;
	int n = s.length();
	int m = t.length();
	vector<vector<int>> dp(n+1,vector<int> (m+1)); //longest subsequence taking i items from s and j items from t
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	//for(int i=0;i<=n;i++) {
		//for(int j=0;j<=m;j++) {
			//cout<<dp[i][j]<<" " ;
		//}
		//cout<<"\n";
	//}
	//cout<<"\n";
	//int index = dp[n][m];
	string LCS;
	int i=n,j=m;
	while(i>0 && j>0) {
		if(s[i-1]==t[j-1]) {
			LCS=LCS+s[i-1];
			i--;
			j--;
		} else if(dp[i][j-1]>dp[i-1][j]) {
			j--;
		} else {
			i--;
		}
	}
	reverse(LCS.begin(), LCS.end());
	//debug()<<imie(LCS);
	cout<<LCS;
}



Measured memory_bytes: 38840
N, K = map(int, input().split())
A = [0]*N
for i in range(K):
    d = int(input())
    A_d = [int(n) for n in input().split()]
    for j in range(d):
        A[A_d[j]-1] += 1
count = 0
for i in range(N):
    if A[i] == 0:
        count += 1
print(count)

Measured memory_bytes: 9188
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll a[200010];
std::vector<ll> G[200010];
ll dp[200010];
ll ans[200010];

void dfs( ll v, ll p = -1 )
{
  ll idx = std::lower_bound( dp, dp+N, a[v] )-dp;
  ll x = dp[idx];

  dp[idx] = a[v];

  ans[v] = std::lower_bound( dp, dp+N, INF )-dp;

  for( auto u : G[v] ) if( u != p )
    dfs( u, v );

  dp[idx] = x;
  
  return;
}

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

  rep( i, N )
    std::cin >> a[i];

  rep( i, N-1 )
  {
    ll u, v;
    std::cin >> u >> v;
    --u; --v;

    G[u].emplace_back( v );
    G[v].emplace_back( u );
  }

  rep( i, N )
    dp[i] = INF;

  dfs( 0 );

  rep( i, N )
    std::cout << ans[i] << std::endl;

  return 0;
}

Measured memory_bytes: 30112
package main

import "fmt"

func main() {
	var A, B, C, X int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	fmt.Scan(&X)

	res := 0 
	for i := 0; i <= A; i ++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if 500 * i + 100 * j + 50 * k == X {
					res += 1
				}
			}
		}
	}

	fmt.Println(res)
}

Measured memory_bytes: 512
a,b=map(int,input().split())
s=list(input())
num=["0","1","2","3","4","5","6","7","8","9"]
flg=True
for i in range(len(s)):
    if i==a:
        if s[i]!="-":
            flg=False
            break
    else:
        if not(s[i] in num):
            flg=False
            break
if flg:
    print("Yes")
else:
    print("No")

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    // Xの約数列挙はO(X^(1/2))だがこれでは全く間に合わない
    // 1~Nの倍数をひたすら列挙する方針に変更
    ll N; cin >> N;
    ll ans = 0;
    rep2(i, 1, N + 1){
        ll tmp = N / i;
        ans += i * (tmp + 1) * tmp / 2;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 多次元配列を作る
// vector<vector<int>> vn(n, vector<int>(3, 0));

// 多次元配列の dump
// for (vector<int> v : vn) {
//     cout << v;
// }

// printf("%d\n", n);
// printf("%lld\n", n);

int main(void){
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    if (b % a == 0) {
        printf("%d\n", a + b);
    } else {
        printf("%d\n", b - a);
    }
    return 0;
}


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


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

    long long int a,b;

    for(long long int i=sqrt(N); i>0; i--){
        if(N%i == 0){
            a = i;
            b = N/i;
            break;
        }
    }

    cout << (a-1)+(b-1);

    return 0;
}

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

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

Node *root,*NIL;

void insert(int key){
  Node *x,*y,*z; 

  y = NIL;
  x = root;

  z = (Node *)malloc(sizeof(Node));

  z->key = key;
  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 key){
  /* if(key == x->key)
    return 1;

  if(x == NIL)
    return -1;

  if(key < x->key){
    x = x->left;
    find(x, key);
  }

  else{
    x = x->right;
    find(x, key);
    }*/

  while(x != NIL && key != x->key){
    if(key < x->key)
      x = x->left;

    else
      x = x->right;
  }

  return x;
}

void printi(Node *a){
  if(a == NIL)
    return;

  printi(a->left);
  printf(" %d", a->key);
  printi(a->right);
}

void printp(Node *a){
  if(a == NIL)
    return;

  printf(" %d", a->key);
  printp(a->left);
  printp(a->right);
}

int main(){
  int n,i,a,b;
  char s[100];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", s);

    if(strcmp(s, "insert") == 0){
      scanf("%d", &a);
      insert(a);
    }

    else if(strcmp(s, "print") == 0){
      printi(root);
      printf("\n");
      printp(root);
      printf("\n");
    }

    else if(strcmp(s, "find") == 0){
      scanf("%d", &b);

      if(find(root, b) != NIL)
	printf("yes\n");

      else
	printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K, m, sum;
  cin >> N >> K;
  m = K/2;
  sum = 0;
  
  for (int i=0; i<N; i++) {
    int l;
    cin >> l;
    if(l>m){
      sum += (K-l)*2;
    }
    else{
      sum += l*2;
    }
  }
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K, S;
    cin >> K >> S;
    K += 1;
    int cnt = 0;
    for (int i = 0; i < K; ++i) {
        if (i+K*2<S) { continue; }
        if (i>S) { break; }
        for (int j = 0; j < min(K, S-i+1); ++j) {
            if (i+j+K<=S) { continue; }
            if (i+j>S) { break; }
            
            cnt += 1;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> d(n);
    REP(i,n) cin >> d[i];
    sort(ALL(d));
    int ans = d[n/2] - d[n/2-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
using namespace std;
typedef long long ll;
const int N=200010;
int n;
int a[N];
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
}
bool solve(){
	ll ans=0;
	int last=n+1,now;
	for(int i=n;i>=1;i--){
		now=i-a[i];
		if(now<1||now>last)
			return false;
		if(now!=last)
			ans+=a[i];
		last=now;
	}
	printf("%lld\n",ans);
	return true;
}
int main(){
	readData();
	if(solve()==false)
		puts("-1");
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int main() {
    int n; cin >> n;
    int debt=100000;
    for(int i=1; i<=n; ++i){
        debt *= 1.05;
        if(debt%1000!=0) debt = (debt/1000+1)*1000;
    }
    cout << debt << endl;
    
	return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for(int i = 0;i < n / 4 + 1;i++) {
    if((n - 4 * i) % 7 == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin>>a>>b;
    int c = a*b;
    int d = c/2;
    double e = c*0.5;
    if(d == e){
        cout<<"Even";
    }
    else{
        cout<<"Odd";
    }
}

Measured memory_bytes: 256
def main():
    N, M = list(map(int, input().split()))
    AB = []
    for _ in range(M):
        a, b = list(map(int, input().split()))
        AB.append([a-1, b-1])

    # グラフを表現する（辺のある・なし）
    graph = []
    for _ in range(N):
        graph.append([False] * N)

    for a, b in AB:
        graph[a][b] = True
        graph[b][a] = True
        
    visited = [False] * N

    def dfs(v):
        """v（頂点）からスタートする"""

        # 到達済みだったらreturn
        if visited[v]:
            return

        # 到達した印
        visited[v] = True

        # そのさきへ（vと繋がっている）
        edges = graph[v]
        for i, e in enumerate(edges):
            if e:
                dfs(i)

        return


    ans = 0
        
    # 辺を一つずつ消してみて、橋かどうかを調べる
    for a, b in AB:
        graph[a][b] = False
        graph[b][a] = False

        visited = [False] * N
        dfs(0)
        
        # 全てTrueというわけではない（Falseが一つでもある場合）
        if not all(visited):
            ans += 1

        graph[a][b] = True
        graph[b][a] = True

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;


vector<int> to[2505];
vector<int> rto[2505];
bool reachable1[2505];
bool reachable2[2505];
bool ok[2505];
int d[2505];

void dfs(int v) {
    if (reachable1[v]) return;
    reachable1[v] = true;
    for (int e: to[v]) {
        dfs(e);
    }
}

void rdfs(int v) {
    if (reachable2[v]) return;
    reachable2[v] = true;
    for (int e: rto[v]) {
        rdfs(e);
    }
}


int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edge;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        to[a].emplace_back(b);
        rto[b].emplace_back(a);
        edge.emplace_back(a, b, p-c);
    }
    dfs(0);
    rdfs(n-1);
    rep(i, n) ok[i] = reachable1[i] && reachable2[i];
    rep(i, n) d[i] = INF;
    d[0] = 0;

    bool upd = true;
    int step = 0;
    while (upd) {
        upd = false;
        rep(i, m) {
            int a, b, c;
            tie(a, b, c) = edge[i];
            if (!ok[a]) continue;
            if (!ok[b]) continue;
            int newd = d[a] + c;
            if (newd<d[b]) {
                upd = true;
                d[b] = newd;
            }
        }
        step++;
        if (step>n) {
            cout << "-1" << endl;
            return 0;
        }
    }

    int ans = max(0, -d[n-1]);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define EXCEPTERROR cout << "-1" << endl;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define size_s(s) s.size()-1
#define size_a(array) sizeof(array) / sizeof(array[0])
#define INF 1000000000000 //1e12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}

int main(){
    string str; cin >> str;
    if(str[size_s(str)] == '3') {
        cout << "bon" << endl; return 0;
    }

    if(str[size_s(str)] == '0' || str[size_s(str)] == '1' ||
       str[size_s(str)] == '6' || str[size_s(str)] == '8'){
           cout << "pon" << endl; return 0;
       }

    cout << "hon" << endl; return 0;
}

/*

*/

Measured memory_bytes: 3596