akhauriyash/Code-Regression huggingface dataset:
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn root(parent: &[usize], mut x: usize) -> usize {
    while parent[x] != x {
        x = parent[x];
    }
    x
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1, u64); m],
        q: usize,
        p: [(usize1, usize1); q],
    }
    let mut parent = Vec::with_capacity(n);
    let mut size = Vec::with_capacity(n);
    let mut cost = Vec::with_capacity(n);
    for i in 0..n {
        parent.push(i);
        size.push(1);
        cost.push(1_000_000_000 + 1);
    }
    let mut e = e;
    e.sort_by_key(|e| e.2);
    let mut sum = 0;
    for (a, b, c) in e {
        let mut a = root(&parent, a);
        let mut b = root(&parent, b);
        if a == b {
            continue;
        }
        if size[a] < size[b] {
            std::mem::swap(&mut a, &mut b);
        }
        size[a] += size[b];
        parent[b] = a;
        cost[b] = c;
        sum += c;
    }
    for (mut a, mut b) in p {
        let mut ans = 0;
        while a != b {
            if cost[a] < cost[b] {
                ans = cost[a];
                a = parent[a];
            } else {
                ans = cost[b];
                b = parent[b];
            }
        }
        writeln!(out, "{}", sum - ans).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 29944
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int A, B, C, K;
	std::cin >> A >> B >> C >> K;
	
	int V[3] = { A, B, C };
	std::sort(std::begin(V), std::end(V));
	V[2] *= 1 << K;
	std::cout << V[0]+V[1]+V[2] << "\n";
}


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

int main() {
  int n,k;
  string s;
  cin>>n>>k>>s;
  if(s.at(k-1)=='A'){
    s.at(k-1)='a';
  }if(s.at(k-1)=='B'){
    s.at(k-1)='b';
  }if (s.at(k-1)=='C'){
    s.at(k-1)='c';
  }cout<<s<<endl;
}


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

class LazySegmentTree {
	int[] nodes;
	int[] lazy;

	int n;
	int e = 0; // 単位元

	public LazySegmentTree(int size) {
		n = 1;
		while (n < size) {
			n *= 2;
		}

		nodes = new int[2 * n - 1];
		lazy = new int[2 * n - 1];

		Arrays.fill(nodes, e);
		Arrays.fill(lazy, e);
	}

	public void eval(int k) {
		if (lazy[k] == e) {
			return;
		}

		// 葉でないなら
		if (k < n - 1) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}

		nodes[k] += lazy[k];
		lazy[k] = 0;
	}

	public void add(int a, int b, int val) {
		add(a, b, val, 0, 0, n);
	}

	private void add(int a, int b, int val, int k, int l, int r) {
		// [l,r) が[a,b) に含まれていない場合
		if (a >= r || b <= l) {
			return;
		}

		eval(k);

		if (a <= l && r <= b) {
			lazy[k] += val;
			eval(k);
			return;
		}

		add(a, b, val, 2 * k + 1, l, (l + r) / 2);
		add(a, b, val, 2 * k + 2, (l + r) / 2, r);

		nodes[k] = Math.max(nodes[2 * k + 1], nodes[2 * k + 2]);
	}

	public int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}

	private int query(int a, int b, int k, int l, int r) {
		if (a >= r || b <= l) {
			return e;
		}
		eval(k);
		if (a <= l && r <= b) {
			return nodes[k];
		}

		int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);

		return Math.max(vl, vr);

	}
	
}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		LazySegmentTree seg = new LazySegmentTree(n);

		for (int i = 0; i < q; i++) {
			int c = sc.nextInt();

			if (c == 0) {
				int s = sc.nextInt() - 1;
				int t = sc.nextInt();
				int x = sc.nextInt();

				seg.add(s, t, x);

			} else {
				int a = sc.nextInt() - 1;
				out.println(seg.query(a, a + 1));
			}
		}

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}



Measured memory_bytes: 115112
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

// NewSet is constructer of Set
func NewSet() *Set {
	s := new(Set)
	s.content = map[int]int{}
	return s
}

// Set for integer
type Set struct {
	content map[int]int
}

func (s *Set) insert(x int) int {
	_, ok := s.content[x]
	if !ok {
		s.content[x] = 1
	}
	return len(s.content)
}

func (s *Set) find(x int) int {
	v, ok := s.content[x]
	if ok {
		return v
	}
	return 0
}

func main() {
	scanner.Split(bufio.ScanWords)

	nQueries := nextInt()
	set := NewSet()
	for iQuery := 0; iQuery < nQueries; iQuery++ {
		queryType := nextInt()
		x := nextInt()
		if queryType == 0 {
			setSize := set.insert(x)
			fmt.Println(setSize)
		} else if queryType == 1 {
			fmt.Println(set.find(x))
		}
	}
}



Measured memory_bytes: 13892
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    double S,A,B;
    S = 1;
    B = 0;
    for(double i = 1; i <= N; i++){
        A = i;
        S /= N;
        while(A < K){
            A *= 2;
            S /= 2;
        }
        B += S;
        //cout << A << " " << endl;
        S = 1;
    }
    cout << setprecision(12) << B << endl;
}


Measured memory_bytes: 256
def sum_of_numbers(num):

    s = 0

    for i in range(len(num)):
        s += int(num[i])

    print(str(s)+"\n", end="")

if __name__ == "__main__":
    

    while(True):

        number = input()

        if int(number) == 0:
            break 

        sum_of_numbers(number)



Measured memory_bytes: 5604
N,M = [int(x) for x in input().split()]
a=[]
b=[]
for i in range(M):
    A,B=[int(x) for x in input().split()]
    a.append(A)
    b.append(B)

for i in range(N):
    print(a.count(i+1)+b.count(i+1))


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

int main(){
    int a;
    cin >> a;
    if(65<=a && a<=90)
    {
        cout << 1;
    }
    else if(97<=a && a<=122)
    {
        cout << 2;
    }
    else
    {
        cout <<0;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  map<LL, LL> m;
  LL N, K; cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    LL a, b; std::cin >> a >> b;
    m[a] += b;
  }

  LL count = 0;
  LL last_a = -1;
  for (auto p : m) {
    LL a = p.first;
    LL b = p.second;
    count += b;
    last_a = a;
    if (count >= K) {
      std::cout << a << std::endl;
      return 0;
    }
  }
  std::cout << last_a << std::endl;
}


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

const int N=100005;

int ans,n,x,y,w,m,sz;
int dp[N],b[N],a[N],cnt[N];
bool tag[N];

void init(){
	int s,i,ss;
	sz=(1<<m)-1;
	for (s=0;s<=sz;s++){
		ss=0;
		for (i=1;i<=m;i++) if ((s>>i-1)&1) ss^=a[i];
		if (!ss) tag[s]=1;
	}
}

int main(){
	int i,s,ss,is;
	scanf("%d",&n);
	for (i=1;i<n;i++){
		scanf("%d%d%d",&x,&y,&w); x++; y++;
		b[x]^=w; b[y]^=w;
	}
	for (i=1;i<=n;i++) cnt[b[i]]++;
	ans+=cnt[0];
	for (i=1;i<=15;i++){
		ans+=cnt[i]/2;
		if (cnt[i]&1) a[++m]=i;
	}
	init();
	for (s=0;s<=sz;s++){
		is=sz^s;
		for (ss=is;ss;ss=(ss-1)&is)
			if (tag[ss]) dp[s|ss]=max(dp[s|ss],dp[s]+1);
	}
	printf("%d\n",n-(ans+dp[sz]));
	return 0;
}

Measured memory_bytes: 768
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	N := ScanInt(scanner)
	a := make([]int, 3 * N)
	for i := 0; i < 3 * N; i++ {
	    a[i] = ScanInt(scanner)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	
	sum := 0
	for i := 0; i < 2 * N; i++ {
	    if i % 2 == 1 {
	        sum += a[i]
	    }
	}
	fmt.Println(sum)
	
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

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

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

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

bool solve(int n, int A[], int m, int i) {
	if (m == 0) return true;
	if (i >= n) return false;
	return solve(n, A, m, i + 1) || solve(n, A, m - A[i], i + 1);
}

bool solve(int n, int A[], int m) {
	return solve(n, A, m, 0);
}

int main() {
	int n,q,A[2000],m;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m;
		if (solve(n, A, m)) {
			cout << "yes" << endl;
		} else {
			cout << "no" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#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, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	map<int, int> mp;
	REP(i,3){
		int a;
		cin >> a;
		mp[a]++;
	}

	cout << (mp.size()==2 ? "Yes" : "No")<< '\n';
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}













bool compare(pi a,pi b){
     if(a.fi-a.se>b.fi-b.se)return  true;
     else if(a.fi-a.se==b.fi-b.se&&a.se<b.se)return true;
     return false;
}




const int N=1000005;
int pr[1000005];
int main()
{
     string s;
     cin>>s;
     int ct=0;
     int l=0,r=s.length()-1;
     while(l<r)
     {
          if(s[l]!=s[r]){
               if(s[l]!='x'&&s[r]!='x'){cout<<-1;return 0;}
               else if(s[l]=='x'){l++;ct++;}
               else if(s[r]=='x'){r--;ct++;}
          }
          else{
               l++;r--;
          }
     }
     cout<<ct;
}




 
 

















Measured memory_bytes: 512
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

vector<int> a, ans;
vector<vector<int>> g;

void dfs(int v, vector<int> &d, int cur_ans = 0, int p = -1) {
    int idx = lower_bound(all(d), a[v]) - d.begin();
    int mem = d[idx];
    d[idx] = a[v];
    cmax(cur_ans, idx);
    ans[v] = cur_ans;
    for (auto &x : g[v]) {
        if (x == p) {
            continue;
        }
        dfs(x, d, cur_ans, v);
    }
    d[idx] = mem;
}

void run() {
    int n;
    cin >> n;
    a.resize(n);
    g.resize(n);
    ans.resize(n);
    for (auto &x : a) 
        cin >> x;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }
    vector<int> d(n + 1, INF);
    d[0] = -INF;
    dfs(0, d);
    for (auto &x : ans) {
        cout << x << " ";
    }
    cout << endl;
}

Measured memory_bytes: 33272
#include<stdio.h>
#include<algorithm>

	using namespace std;
	int main()
{
	int a,n[4],L=0,S=0,i,c=0;
	scanf("%d",&a);
	
	while(a!=0000){
		c=0;
		while(a!=6174){
			if(a==1111||a==2222||a==3333||a==4444||a==5555||a==6666||a==7777||a==8888||a==9999){
				
				break;
			}
		L=0;S=0;
		
		
		
		c++;
	n[0]=a/1000;
	n[1]=a/100-n[0]*10;
	n[2]=a/10-n[0]*100-n[1]*10;
	n[3]=a-n[0]*1000-n[1]*100-n[2]*10;
	sort(n,n+4);
	L+=n[3]*1000;
	L+=n[2]*100;
	L+=n[1]*10;
	L+=n[0];
	S+=n[0]*1000;
	S+=n[1]*100;
	S+=n[2]*10;
	S+=n[3];
	a=L-S;
	}
		
		if(a==1111||a==2222||a==3333||a==4444||a==5555||a==6666||a==7777||a==8888||a==9999){
			printf("NA\n");
		}
		else{
			printf("%d\n",c);
		}
	
	
	scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 1052
#include <stdio.h>

int main(void)
{
	int m, f, r;

	while(scanf("%d %d %d", &m, &f, &r)!=EOF && !(m==EOF && f==EOF && r==EOF)){
		if(m==EOF || f==EOF)
			printf("F\n");
		else if(m+f>=80)
			printf("A\n");
		else if(m+f>=65 && m+f<80)
			printf("B\n");
		else if(m+f>=50 && m+f<65)
			printf("C\n");
		else if(m+f>=30 && m+f<50){
			if(r>=50)
				printf("C\n");
			else 
				printf("D\n");
		}
		else if(m+f<30)
			printf("F\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vi hs(h), ws(w);
  set<P> s;
  rep(i, m) {
    int c, r;
    cin >> c >> r;
    --c; --r;
    hs[c]++;
    ws[r]++;
    s.insert(P(c, r));
  }
  int ms = 0, mw = 0;
  rep(i, h) ms = max(ms, hs[i]);
  rep(i, w) mw = max(mw, ws[i]);
  vi is, js;
  rep(i, h) if (ms == hs[i]) is.push_back(i);
  rep(i, w) if (mw == ws[i]) js.push_back(i);
  int ans = ms+mw;
  for (int i : is) for (int j : js) {
    if (s.count(P(i, j))) continue;
    cout << ans << endl;
    return 0;
  }
  cout << ans-1 << endl;
}


Measured memory_bytes: 23880
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\n"
#define MAXN ((int)2e5+123)
#define MOD ((int)1e9+7)
#define ll long long
#define INF INT_MAX
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define si set<int>
#define pb push_back
#define SZ(v) int(v.size())
#define ms(v,x) memset(v,x,sizeof v)
#define fore(i,m,n) for(int i=m;i<n;i++)
#define forn(i,n) fore(i,0,n)
#define foreach(i,v) for(auto i: v)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) {return b? gcd(b,a%b): a;}
template<typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}


using namespace std;

int n,t;
string s;

int main(){_
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    string s;
    cin >> s;

    cout << s.substr(0, 3) << endl;
}

Measured memory_bytes: 3640
# ABC093 B - Small and Large Integers
a,b,k = map(int, input().split())

range_ab = set(range(a,a+k))|set(range(b-k+1,b+1))
l = list(range_ab)
l = [x for x in l if a<=x<=b]

l.sort()
print(*l,sep='\n')

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define N 100010
#define mod (7+(ll)1e9)
ll modexp(ll x, ll y, ll p) {
    ll res = 1;
    for(;y>0;y>>=1) {
        if(y&1)
            res = (res*x) % p;
        x = (x*x) % p;
    }
    return res;
}
ll fac[N];
int choose(int n, int r) {
    if(n < r) return 0;
    if(!r) return 1;
    return (fac[n] * modexp((fac[r]*fac[n-r]) % mod, mod-2, mod)) % mod;
}
int n, a[N];
vi pos;
int main() {
    SYNC
    fac[0] = 1;
    FOR(i,1,N) fac[i] = (fac[i-1]*i) % mod;
    vi pos;
    cin >> n; FOR0(i, n+1) cin >> a[i];
    int y = ((n&1)? (n%4==1): n+(n%4 != 0));
    FOR0(i, n+1) y ^= a[i];
    FOR0(i, n+1) if(a[i] == y) pos.pb(i);
    pos[1] = n-pos[1];
    FOR(k,1,n+2) {
        cout << ((choose(n+1,k) - choose(pos[0] + pos[1],k-1))%mod + mod) % mod<< endl;
    }
}

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

int main(){
  vector<int> V(60);
  vector<int> C(60);
  int N;
  int counter = 0;

  cin >> N;
  
  for(int i = 0;i < N;i++){
    cin >> V[i];
  }
  for(int i = 0;i < N;i++){
    cin >> C[i];
  }

  for(int i = 0;i < N;i++){
    if(V[i] - C[i] > 0)counter+= V[i] - C[i];
  }

  cout << counter << endl;

}

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

int main () {
  int N  ;
  cin >> N ;
  
  vector<int> line(N) ;
  
  for(int i = 0 ; i < N ; i++ ) cin >> line[i] ;
  sort(line.begin() , line.end());
  reverse(line.begin() , line.end());
  
  int ans = 1 ;
  int pre = line[0] ;
  
  for(int i = 1 ; i < N ; i++ ){
    if( pre != line[i] ) {
      ans ++ ;
      pre = line[i] ;
    }
  }
  
  cout << ans << endl ;
  
  }

Measured memory_bytes: 256
import java.util.Scanner;



public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b;
		for(;;){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a==0&&b==0)break;
			else{for(int i=0;i<a;i++){
				for(int l = 0;l<b;l++){
					System.out.print("#");}
				System.out.println();
				}System.out.println();
			}
		}

	}}

Measured memory_bytes: 26952
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

vector<pair<int, int>> v;
int n, t;
int dp[3005][3005];

int f(int i, int x)
{
    if (i == n || x >= t)
        return 0;
    int& sol = dp[i][x];
    if (sol != -1)
        return sol;

    int p, q;
    tie(p, q) = v[i];
    sol = max(f(i + 1, x), q + f(i + 1, x + p));
    return sol;
}

int main()
{
    cin >> n >> t;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(all(v));
    memset(dp, -1, sizeof dp);
    cout << f(0, 0);
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> a(3*n);
  REP(i,3*n)cin >> a[i];
  vector<int32> frsum(n+1),basum(n+1);
  priority_queue<int32,vector<int32>,greater<int32>> fr;
  priority_queue<int32> ba;
  int64 sum = 0;
  REP(i,n){
    fr.emplace(a[i]);
    sum += a[i];
  }
  frsum[0] = sum;
  REP(i,n){
    if(fr.top() < a[n+i]){
      sum -= fr.top();
      fr.pop();
      sum += a[n+i];
      fr.emplace(a[n+i]);
    }
    frsum[i+1] = sum;
  }
  sum = 0;
  reverse(ALL(a));
  REP(i,n){
    ba.emplace(a[i]);
    sum += a[i];
  }
  basum[0] = sum;
  REP(i,n){
    if(ba.top() > a[n+i]){
      sum -= ba.top();
      ba.pop();
      sum += a[n+i];
      ba.emplace(a[n+i]);
    }
    basum[i+1] = sum;
  }
  int64 ans = -LLINF;
  REP(i,n+1){
    ans = max(ans, frsum[i] - basum[n-i]);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 6516
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  string n;
  cin >> n;
  if (n[0]-n[2]==0) cout << "Yes";
  else cout << "No";
  cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[3*N];
  for(int i=0;i<3*N;i++) cin >> a[i];
  sort(a,a+3*N,greater<ll>());

  ll ans = 0LL;
  for(int i=0;i<N;i++){
    ans += a[2 * i + 1];
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define rep(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

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

const int N = 200200;
const int mod = 1e9 + 7;
const ll INF = 1e18;

inline void add(int &x, int y)
{
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;	
}

inline void mult(int &x, int y)
{
	x = x * 1ll * y % mod;
}

int n;
char ch;
int a[555][555];

int ok;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	fo(i,n)
		fo(j,n)
		{
			cin>>ch;
			a[i][j]=(ch=='#');
			if(a[i][j]==1)
				ok=1;
		}         	
	int cnt=n;
	for(int j=1;j<=n;++j)
	{
		int f=1;
		for(int i=1;i<=n;++i)
			if(a[i][j]==0)
				f=0;
		if(f)
			cnt--;	
	}
	if(cnt==0)
		return cout<<0,0;
	if(!ok)
		return cout<<-1,0;
	int ans=1e9;
	for(int i=1;i<=n;++i)
	{
		bool f=1;
		int nol=0;
		for(int j=1;j<=n;++j)	
			if(a[i][j]==0)
			{
				f=0;
				++nol;
			}
		if(f)
		{
			cout<<cnt;
			return 0;
		}			
		int good=0;
		for(int k=1;k<=n;++k)
			if(a[k][i]==1)
			{
				good=1;
				ans=min(ans,nol+cnt);
			}
		if(!good)ans=min(ans,nol+cnt+1);
	}
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 1408
x,y=map(int,input().split())
mod=10**9+7

def modpow(a,n):
    if n<1:
        return 1
    ans=modpow(a,n//2)
    ans=(ans*ans)%mod
    if n%2==1:
        ans*=a
    return ans%mod
    
def conb(n,i):
    inv,ans=1,1
    for j in range(1,i+1):
        ans=ans*(n-j+1)%mod
        inv=inv*j%mod
    return (ans*modpow(inv,mod-2))%mod


if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    x=x-n
    y=y-n
    if x<0 or y<0:
        print(0)
    else:
        ans=conb(x+y,x)
        print(ans)


Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int)
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }

int main(){
    int n;cin >> n;
    int maxx = 0;
    int ans = 0;
    int curr = 0;
    for(int i = 0;i < n;i++){
        int t;cin >> t;
        if(t <= curr)ans++;
        else ans = 0;
        curr = t;
        maxx = max(maxx, ans);
    }
    cout << maxx;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007
#define INF 1000000007
#define MAX_V 30000

using namespace std;

// 辺を表す構造体 (行き先、容量、逆辺)
struct edge { int to, cap, rev; };


long long H, W;
string S[105];

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

vector<edge> G[MAX_V]; // グラフの隣接リスト表現
int level[MAX_V]; // sからの距離
int iter[MAX_V]; // どこまで調べ終わったか

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
G[from].push_back((edge){to, cap, G[to].size()});
G[to].push_back((edge){from, 0, G[from].size() - 1});
}

// sからの最短距離をBFSで計算する
void bfs(int s) {
	memset(level, -1, sizeof(level)); 
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to); 
			}
		} 
	}
}

// 増加パスをDFSで探す
int dfs(int v, int t, int f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t) {
	int flow = 0; 
	for (;;) {
		bfs(s);
		if (level[t] < 0){
			return flow;
		}
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}


bool valid(int y, int x){
	return (y >= 0 && y < H && x >= 0 && x < W);
}


int main(){
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		cin >> S[i];
	}

	bool ok = true;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] == 'X' && (i == 0 || i == H -1 || j == 0|| j == W-1)){
				ok = false;
			}
		}
	}
	if(!ok){
		cout << -1 << endl;
		return 0;
	}

	int start = H*W*2;
	int goal = H*W*2 + 1;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] == 'X'){
				add_edge(start, 2*(i*W+j)+1, INF);
			}else{
				add_edge(2*(i*W+j), 2*(i*W+j)+1, 1);
			}
			for(int k = 0; k < 4; k++){
				if(valid(i + dy[k], j + dx[k])){
					add_edge(2*(i*W+j)+1, 2*((i+dy[k])*W+(j+dx[k])), INF);
				}else{
					add_edge(2*(i*W+j)+1, goal, INF);
				}
			}
		}
	}

	cout << max_flow(start, goal) << endl;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	ll x,y;
	cin>>x>>y;
	ll c=2*x-(y/2);
	ll t=(y/2)-x;
	if(c>=0 and t>=0 and c+t==x and 2*c+4*t==y) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main() {

	int n, k;
	char check, S[11];

	scanf("%d", &n);
	scanf("%s",  S);
	scanf("%d", &k);
	check = S[k - 1];

	for (int i = 0; S[i] != '\0'; i++) {
		if (S[i] != check)
			S[i] = '*';
	}
	printf("%s", S);
	return 0;
}

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

#define fi first
#define se second

bool cmp(pair<string,pair<int,int> > a,pair<string,pair<int,int> > b){
    if(a.fi==b.fi) return a.se.fi>b.se.fi;
    return a.fi<b.fi;
}

int main(){

    int n;
    cin>>n;
    pair< string,pair<int,int> >  p[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].fi>>p[i].se.fi;
        p[i].se.se = i;
    }
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<p[i].se.se<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(int, N, K);
    vector<int> p(N);

    rep(i, N) {
        input(p[i]);
    }

    long double sum = 0.0;
    rep(i, K) {
        sum += sigma(p[i]) / (long double)(p[i]);
    }

    long double ans = sum;
    reps(i, K, N-1) {
        sum -= sigma(p[i-K]) / (long double)(p[i-K]);
        sum += sigma(p[i]) / (long double)(p[i]);
        chmax(ans, sum);
    }

    cout << fixed << setprecision(12);
    print(ans);


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n";
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define vii vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define MOD LLONG_MAX
#define INF 1e18 + 5
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
vii dp(100 * 10000 + 1, INF);
vector<pii> knap(101);
int n, w;
void solve(int mx_value)
{
    // dp[i] -> max total weight with value = i;
    rep(i, 1, n + 1)
    {
        for (int value = mx_value - knap[i].second; value >= 0; value--)
        {
            dp[value + knap[i].second] = min(dp[value + knap[i].second], dp[value] + knap[i].first);
        }
    }
}
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    int t;
    t = 1;
    while (t--)
    {
        cin >> n >> w;
        int a, b;
        int mx_value = 0;
        dp[0] = 0;
        rep(i, 1, n + 1)
        {
            cin >> a >> b;
            knap[i] = mp(a, b);
            mx_value += b;
        }
        solve(mx_value);
        int ans = 0;
        rep(i, 1, mx_value+1)
        {
            if (dp[i] <= w)
                ans = i;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
signed main(){
 
	string s;
	cin>>s;
 
	vector<lli> a(s.size());
	REP(i,0,s.size())a[i] = s.at(i)-'0';
 
	lli large = s.size()+1;
	lli small = 1;
 
	while(small+1<large){
		lli middle = (large+small)/2;
		if(DEBUG)cout<<"small="<<small<<" large="<<large<<" middle="<<middle<<endl;
		lli ss = s.size()-middle;
		lli es = middle;
		if(DEBUG)cout<<"ss="<<ss<<"es="<<es<<endl; 
		lli num = a[ss];
		bool ok=true;
		REP(i,ss,es){
			if(a[i]!=num){
				ok=false;
			}
		}
		if(ok)small=middle;
		else large = middle;
	}
	cout<<small<<endl;
 
	return 0;
}

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

using namespace std;

#define ll long long
#define loop(x, start, end) for(int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)

#define left(x) (x * 2)
#define right(x) (x * 2 + 1)
#define max3(x, y, z) (max(x, max(y, z)))

void heapify(vector<int> &vec, int index) {
    int l = left(index);
    int r = right(index);
    
    int largest;
    if (l < vec.size() && vec[l] > vec[index]) largest = l;
    else largest = index;
    if (r < vec.size() && vec[r] > vec[largest]) largest = r;
    
    bool childLarger = largest != index;
    if (childLarger) {
        swap(vec[largest], vec[index]);
        heapify(vec, largest);
    }
}

int main(void){
    int n, x;
    cin >> n;
    vector<int> vec(n+1);
    
    loop(i, 1, n+1) cin >> vec[i];
    
    loopdown(i, vec.size() / 2, 0) heapify(vec, i);
    
    loop(i, 1, n+1) cout << " " << vec[i];
    cout << endl;
    return 0;
}



Measured memory_bytes: 4616
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int x, a, b;

int main() {
  cin >> x >> a >> b;
  int xa = abs(x - a);
  int xb = abs(x - b);
  if (xa < xb) {
    cout << "A";
  } else {
    cout << "B";
  }
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
using namespace std;

struct Node{
    int k;
    Node *p,*l,*r;
};

Node *root;

void insert(int k){
    Node *y=NULL;
    Node *x=root;
    Node *z;
    z=(Node*)malloc(sizeof(Node));
    z->k=k;
    z->l=NULL;
    z->r=NULL;
    while(x!=NULL){
        y=x;
        if(z->k<x->k){
            x=x->l;
        }
        else{
            x=x->r;
        }
    }
    z->p=y;
    if(y==NULL){
        root=z;
    }
    else if(z->k<y->k){
        y->l=z;
    }
    else{
        y->r=z;
    }
}

void inorder(Node* v){
    if(v==NULL)return;
    inorder(v->l);
    cout<<" "<<v->k;
    inorder(v->r);
}

void preorder(Node* v){
    if(v==NULL)return;
    cout<<" "<<v->k;
    preorder(v->l);
    preorder(v->r);
}

signed main(){
    int n;
    cin>>n;
   rep(i,n){
       string s;
       cin>>s;
       if(s=="insert"){
           int k;
           cin>>k;
           insert(k);
       }
       else{
           inorder(root);
           cout<<endl;
           preorder(root);
           cout<<endl;
       }
   }
    return 0;
}


Measured memory_bytes: 26484
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;

const int MAXN = (200 + 10) * 2;

class no_solution : public std::exception
{
public:
	const char * what(void) const noexcept
	{
		return "no solution reachable";
	}
};

namespace disjointSet
{
int fa[MAXN];

void init()
{
	memset(fa, 0x00, sizeof fa);
}

int find(int x)
{
	if(fa[x])
		return fa[x] = find(fa[x]);
	return x;
}

void merge(int x, int y)
{
	x = find(x), y = find(y);
	if(x != y)
		fa[x] = y;
}

}

bool loop[MAXN];
int inDeg[MAXN], outDeg[MAXN];
int N, H;

void solve()
{
	for(int i = 0; i <= 2 * H; i++)
	{
		if(i > H)
			if(inDeg[i] > outDeg[i])
				throw no_solution();
		if(i < H)
			if(outDeg[i] > inDeg[i])
				throw no_solution();

		bool found = false, isLoop = loop[i];

		for(int j = 0; j <= 2 * H; j++)
			if(found)
				break;
			else
				if(disjointSet::find(i) == disjointSet::find(j))
				{
					if(i != j)
						isLoop = true;
					if(inDeg[j] != outDeg[j])
						found = true;
				}

		if(!found && isLoop)
			throw no_solution();
	}
}

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

	cin >> N >> H ;
	for(int i = 1; i <= N; i++)
	{
		int a, b, c, d, L, R;
		cin >> a >> b >> c >> d;
		L = c ? H - c : H + a;
		R = d ? H + d : H - b;
		disjointSet::merge(L, R);
		inDeg[R]++, outDeg[L]++;

		if(L == R)
			loop[L] = true;
	}


	try
	{
		solve();
		cout << "YES" << endl;
	}
	catch(std::exception & x)
	{
		cout << "NO" << endl ;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
vector<int>g[105];
int dp[105],m;
ll p[105];
int n;
ll ans;
ll q[105];
int dfs(int v,int p){
    int o=0;
    for(int i=0;i<g[v].size();i++){
        int u=g[v][i];
        if(u!=p){
            o=max(dfs(u,v)+1,o);
        }
    }
    return o;
}
void dfs2(int v,int d,int p){
    q[v]=d;
    for(int i=0;i<g[v].size();i++){
        if(g[v][i]!=p)dfs2(g[v][i],d+1,v);
    }
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        dp[i]=dfs(i,-1);
        m=max(m,dp[i]);
    }
    if(m%2==1){
        int a=-1,b=-1;
        for(int i=0;i<n;i++){
            if(dp[i]==(m+1)/2){
                a=i;
                break;
            }
        }
        for(int i=0;i<n;i++){
            if(dp[i]==(m+1)/2&&i!=a){
                b=i;
                break;
            }
        }
        for(int i=0;i<n;i++){
            p[dp[i]]=max(p[dp[i]],ll(g[i].size()-1));
        }
        ll ans=1;
        for(int i=(m+1)/2;i<m;i++)ans*=p[i];
        cout<<(m+1)/2<<' '<<ans*2<<endl;
    }else{
        int a;
        for(int i=0;i<n;i++){
            if(dp[i]==m/2)a=i;
            p[dp[i]]=max(p[dp[i]],ll(g[i].size()-1));
        }
        ll ans=g[a].size();
        for(int i=m/2+1;i<m;i++)ans*=p[i];
        for(int i=0;i<g[a].size();i++){
            int b=g[a][i];
            dfs2(a,0,b);
            dfs2(b,0,a);
            ll r=1;
            for(int j=0;j<n;j++){
                p[j]=0;
            }
            for(int j=0;j<n;j++){
                p[q[j]]=max(p[q[j]],ll(g[j].size()-1));
            }
            for(int j=0;j<m/2;j++)r*=p[j];
            ans=min(ans,r*2);
        }
        cout<<m/2+1<<' '<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
    int N; string A, B, C; cin >> N >> A >> B >> C;
    string str = "";

    vector<int> count(10e3, 0);
    for (int i = 0; i < N; ++i) {
        int x, y, z; x = y = z = 0;
        if (A[i] == B[i]) x++;
        if (B[i] == C[i]) y++;
        if (A[i] == C[i]) z++;
        if (x >= y && x >= z) str += A[i];
        else if (y >= x && y >= z) str += B[i];
        else if (z >= y && z >= x) str += C[i];
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] != str[i]) cnt++;
        if (B[i] != str[i]) cnt++;
        if (C[i] != str[i]) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  int length=0;
  for(int i=0; i<N; i++){
    int tmp;
    cin >> tmp;
    if(length+1==tmp)
        length++;
  }
  cout << (length==0?-1:N-length) << endl;
}


Measured memory_bytes: 256