akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, M;
	cin >> N;
	vector<string> s;
	for (int i = 0; i < N; i++){
		string si;
		cin >> si;
		s.push_back(si);
	}

	cin >> M;
	vector<string> t;
	for (int i = 0; i < M; i++){
		string ti;
		cin >> ti;
		t.push_back(ti);
	}

	vector<string> dic;
	
	
	for (int i = 0; i < s.size(); i++){
		if (i == 0 && dic.size() == 0){
			dic.push_back(s[i]);
			continue;
		}
		bool find = true;
		for (int j = 0; j < dic.size(); j++){
			if (s[i] == dic[j]){
				find = false;
				break;
			}
		}
		if (find){
			dic.push_back(s[i]);
		}
	}

	for (int i = 0; i < t.size(); i++){
		if (i == 0 && dic.size() == 0){
			dic.push_back(t[i]);
			continue;
		}
		bool find = true;
		for (int j = 0; j < dic.size(); j++){
			if (t[i] == dic[j]){
				find = false;
				break;
			}
		}
		if (find){
			dic.push_back(t[i]);
		}
	}

	int max = 0;
	for (int i = 0; i < dic.size(); i++){
		int cnt = 0;
		for (int j = 0; j < s.size(); j++){
			if (s[j] == dic[i]){
				cnt++;
			}
		}

		for (int j = 0; j < t.size(); j++){
			if (t[j] == dic[i]){
				cnt--;
			}
		}



		if (max < cnt){
				max = cnt;
		}
	}
	cout << max << endl;
}


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

const int mod = 998244353;
const int MN = 200010;

int N;
string S;
int dp[MN][3][3];
map<string, int> vis;

string nxt(string &s) {
    string ret = s;
    if(s[0] != s[1]) {
        ret[0] = 'a' + 'b' + 'c' - s[0] - s[1];
        ret[1] = ret[0];
    }
    else if(s[1] != s[2]) {
        ret[1] = 'a' + 'b' + 'c' - s[1] - s[2];
        ret[2] = ret[1];
    }
    return ret;
}
bool same() {
    for(int i = 0; i < N - 1; i++) if(S[i] != S[i + 1]) return false;
    return true;
}

int main() {
    cin >> S;
    N = S.size();

    int rem = 0;
    for(int i = 0; i < N; i++) {
        rem += S[i] - 'a';
        rem %= 3;
    }

    if(N == 2) {
        if(S[0] == S[1]) printf("1");
        else printf("2");
        return 0;
    }
    if(N == 3) {
        vis[S] = 1;
        if(S[0] != S[1]) {
            string T = S;
            T[0] = 'a' + 'b' + 'c' - S[0] - S[1];
            T[1] = T[0];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }
        if(S[1] != S[2]) {
            string T = S;
            T[1] = 'a' + 'b' + 'c' - S[1] - S[2];
            T[2] = T[1];

            while(!vis[T]) {
                vis[T] = 1;
                T = nxt(T);
            }
        }

        cout << vis.size();
        return 0;
    }
    if(same()) {
        cout << 1;
        return 0;
    }

    int ans = 1;
    for(int i = 0; i < N - 1; i++) {
        ans = 1LL * ans * 3 % mod;
    }

    for(int i = 0; i < 3; i++) {
        dp[N][i][rem] = 1;
    }
    for(int i = N - 1; i >= 0; i--) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                for(int a = 0; a < 3; a++) {
                    if(a == j) continue;
                    dp[i][j][k] += dp[i + 1][a][(k + a) % 3];
                    dp[i][j][k] %= mod;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        ans += mod - dp[1][i][i];
        ans %= mod;
    }

    bool ok = true;
    for(int i = 0; i < N - 1; i++) if(S[i] == S[i + 1]) {
        ok = false;
        break;
    }
    if(ok) {
        ans++;
        ans %= mod;
    }

    cout << ans;
}


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

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

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B)cout << C << endl;
  else if(B==C) cout << A << endl;
  else cout << B << endl;
}



Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	s, t := next(), next()
	s += s

	for i := 0; i < len(t); i++ {
		if s[i:i+len(t)] == t {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 640
def counting_sort(array)
  count = Array.new(10000, 0)
  count_sum = Array.new(10000, 0)
  sorted = Array.new(array.length, 0)
  array.each do |value|
    count[value] += 1
  end

  count.each_with_index do |value, index|
    if index.zero?
      count_sum[index] = value
    end
    count_sum[index] = count_sum[index - 1] + value
  end

  array.reverse_each do |value|
    index = count_sum[value] -= 1
    sorted[index] = value
  end
  sorted
end

gets
input = gets.split(' ').map(&:to_i)
puts counting_sort(input).join ' '


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

int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > a(n),b(n);
  rep(i,n){
    int x,y;
    cin >> x >> y;
    a[i] = make_pair(y,x);
  }
  rep(i,n){
    int x,y;
    cin >> x >> y;
    b[i] = make_pair(x,y);
  }
  sort(all(b));
  sort(all(a));
  reverse(all(a));
  int b_i = -1, a_i = -1;
  int ans = 0;
  while(true){
    b_i = -1, a_i = -1;
    rep(i,b.size()){
      if(b_i!=-1) break;
      rep(j,a.size()){
        if(b[i].first>a[j].second&&b[i].second>a[j].first){
          b_i = i;
          a_i = j;
          break;
        }
      }
    }
    if(b_i==-1) break;
    ans++;
    a.erase(a.begin()+a_i);
    b.erase(b.begin()+b_i);
  }
  cout<< ans << endl;
}



Measured memory_bytes: 256
def sortex(X):
  b=sorted(X)
  b.append("null")
  a=[]
  for i in range(len(X)):
    if b[i]!=b[i+1]:a.append(b[i])
  return a
n=int(input());a=[int(input())for i in range(n)];a=sortex(a);print(len(a))

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s, t;
	cin >> s >> t;

	sort(all(s));
	sort(rall(t));

	if (s < t) {
		out("Yes");
	}
	else {
		out("No");
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vll L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    ll ans = 0;
    rep(i, N) {
        REP(j, i + 1, N) {
            REP(k, j + 1, N){
                if (L[k] < L[i] + L[j]) {
                    if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) ans++;
                }
            }
        }
    }

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

Measured memory_bytes: 3652
#include<iostream>
#include <cmath>
#include <string>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define solve(s,c) {int judge{}; loop(n){if(s[i]!=c[i%3]) {judge=-1;break;}}cout<<(judge==-1?-1:m)<<endl;}
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    char turn='a';//次が誰のターンかを与える。
   
    loop(300){
        if(turn=='a'){
            if(a.length()==0){
                cout<<"A"<<endl;
                break;
            }else{
                turn=a[0];
                a.erase(a.begin());
            }
        }else if(turn=='b'){
            if(b.length()==0){
                cout<<"B"<<endl;
                break;
            }else{
                turn=b[0];
                b.erase(b.begin());
            }
        }else if(turn=='c'){
            if(c.length()==0){
                cout<<"C"<<endl;
                break;
            }else{
                turn=c[0];
                c.erase(c.begin());
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll N;cin>>N;
    cout<<N*N*N<<endl;

}



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

vector<pair<long long,long long>> bunkai;

int main(){
  int a,b,c; cin >> a >> b >> c;
  if(a == b && b == c && c == a || a != b && b != c && c != a)
    cout << "No";
  else
    cout << "Yes";
}
  

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 200;
int N,M,R;
int r[8];

namespace warshall_floyd {
  const int64_t INF = 1000000000;
  int64_t d[MAX_N][MAX_N];
  int n;

  void init(int m)
  {
    n = m;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        d[i][j] = i == j ? 0 : INF;
  }

  void add_edge(int u, int v, int64_t cost)
  {
    d[u][v] = d[v][u] = cost;
  }

  void search()
  {
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}


int main()
{
  cin >> N >> M >> R;
  for (int i = 0; i < R; ++i) {
    cin >> r[i];
  }
  sort(r,r+R);

  warshall_floyd::init(N);

  int a,b,c;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> c;
    warshall_floyd::add_edge(a-1,b-1,c);
  }

  warshall_floyd::search();

  i64 res = INT64_MAX;
  do {
    i64 temp = 0;
    for (int i = 0; i < R-1; i++) {
      temp += warshall_floyd::d[r[i]-1][r[i+1]-1];
    }
    res = min(res, temp);
  } while (next_permutation(r,r+R));

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    for (int i = 0; i < M; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1536
n = gets.to_i
a_list = gets.split.map(&:to_i)

before = a_list[0]
ans = 0

1.step(n - 1) do |i|
    current = a_list[i]
    inc = 0
    if before > current
        inc = before - current
        ans = ans + inc
    end
    before = current + inc
end

puts ans


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

int main() {
    vector<int> cnt(100 + 1, 0);
    int a, b;
    while (cin >> a >> b) {
        if (a | b) {
            cnt[a]++, cnt[b]++;
        } else {
            string ans = "OK";
            if (cnt[1] % 2 == 0 || cnt[2] % 2 == 0) ans = "NG";
            for (int i = 3; i <= 100; i++) if (cnt[i] % 2) ans = "NG";
            cout << ans << endl;
            cnt.assign(100 + 1, 0);
        }
    }
    return 0;
}


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

vector<int> grundy(100005, -1);

int getMax(set<int> s)
{
	int max = 0;
	while(s.find(max) != s.end())
		max++;
	return max;
}

int getGrundy(int pos, int *a, int n)
{
	if(grundy[pos] != -1)
		return grundy[pos];
	set<int> s;
	for(int i = 0; i < n; i++)
	{
		if(a[i] > pos)
		break;
		int res = getGrundy(pos - a[i], a, n);
		s.insert(res);
	}
	return grundy[pos] = getMax(s);
}

int main() {
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	grundy[0] = 0;
	grundy[k] = getGrundy(k, a, n);
	if(grundy[k])
	cout << "First\n";
	else
	cout << "Second\n";
	
	return 0;
}

Measured memory_bytes: 23040
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)


def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    dp = [-1]*(N+1)
    # G = [[0] * (N+1) for i in range(N+1)]
    G = [[] for i in range(N+1)]
    for i in range(M):
        G[x[i]].append(y[i])

    def rec(v : int):
        if dp[v] != -1:
            return dp[v]
        
        t = 0
        for i in G[v]:
            t = max(t, rec(i)+1)
        dp[v] = t

        return dp[v]

    res = 0
    for i in range(1,N+1):
        res = max(res, rec(i))
    print(res)



    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]" 
    y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 71856
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll H, W, M;
    cin >> H >> W >> M;

    ll maxh = 0;
    ll maxw = 0;
    set<pair<int, int>> st;

    vec<ll>  hb(H), wb(W);
    rep(i, M) {
        int h,w;
        cin >> h >> w;
        --h, --w;
        ++hb[h], ++wb[w];
        maxh = max(maxh, hb[h]);
        maxw = max(maxw, wb[w]);
        st.insert({h, w});
    }
    vec<ll> maxhs, maxws;
    rep(i, H) if (hb[i] == maxh) maxhs.push_back(i);
    rep(i, W) if (wb[i] == maxw) maxws.push_back(i);
    for (auto e : maxhs) {
        for (auto j : maxws) {
            if (st.count({e, j}) == 0) {
                cout << maxh + maxw << endl;
                return 0;
            }
        }
    }
    cout << maxh + maxw - 1 << endl;
}


Measured memory_bytes: 30388
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  string S;
  cin >> S;
  ll counter = 0;
  for(int i = 0; i < S.size(); i++){
    if(i == 0) counter++;
    else if(S.at(i-1) != S.at(i)) counter++;
  }
  cout << counter -1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double deg1= h/12*360 + m/60 *30;
    double deg2=m/60 *360;
    double a1,a2,b1,b2;
    a1=a*sin(deg1 * 3.14159265358/ 180);
    a2=a*cos(deg1 * 3.14159265358/ 180);
    b1=b*sin(deg2 * 3.14159265358/ 180);
    b2=b*cos(deg2 * 3.14159265358/ 180);
    double ans;
    ans=(a1-b1)*(a1-b1) + (a2-b2)*(a2-b2);
    ans=sqrt(ans);
    cout<<fixed<<setprecision(10)<<ans;
    

    return 0;
}

Measured memory_bytes: 4100
import kotlin.math.abs

fun main() {
    val inLine = readLine()!!.split(" ").map(String::toInt)
    val x = inLine[0]
    val n = inLine[1]
    var pList = mutableListOf<Int>()
    var result = 0
    if (n == 0){
        result = x
    }else{
        pList = readLine()!!.split(" ").map(String::toInt).toMutableList()

        val lxList = mutableListOf<Int>()
        val bxList = mutableListOf<Int>()
        var minP1 = Integer.MAX_VALUE
        var minP2 = Integer.MAX_VALUE

        pList.forEach{
            if(it > x){
                bxList.add(it)
            }else if(it < x){
                lxList.add(it)
            }
        }
        bxList.add(x)
        lxList.add(x)


        var baseX = x + 1

        if(bxList.isEmpty()){
            minP1 = baseX
        }else{
            run loop@{
                while(bxList.isNotEmpty()){
                    if(!bxList.contains(baseX)){
                        minP1 = baseX
                        return@loop
                    }else{
                        bxList.remove(baseX)
                    }
                    baseX++
                }
            }
        }

        baseX = x - 1
        if(lxList.isEmpty()){
            minP2 = baseX
        }else{
            run loop@{
                while(lxList.isNotEmpty()){
                    if(!lxList.contains(baseX)){
                        minP2 = baseX
                        return@loop
                    }else{
                        lxList.remove(baseX)
                    }
                    baseX--
                }
            }
        }


        result = if(!pList.contains(x)) x else if(abs(x - minP1) < abs(x - minP2)) minP1 else minP2
    }
    println(result)
}

Measured memory_bytes: 36460
#include <bits/stdc++.h>
using namespace std;
long long N;
int main() {
    cin >> N;
    long long a = 0;
    int time = 0;
    for(long long i = 0; i < N; ++i) {
        cin >> a;
        while(1) {
            if(a % 2 == 0) {
                time++;
                a /= 2;
            }else {
                break;
            }
        }
    }
    cout << time << endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n int 
  fmt.Scan(&n)
  cand := []int{17, 13, 10, 9, 6, 5, 3, 2, 1}
  ans := "Yes"
  for _, x := range cand {
    if n == x {
      ans = "No"
      break
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int s = Integer.parseInt(sc.next());
		sc.close();
		int mod = (int)Math.pow(10 , 9) + 7;
		int[] q = new int[s + 1];
		Arrays.fill(q , 0);
		q[0] = 1;
		for(int i = 3 ; i <= s ; i++) q[i] = (q[i - 1] + q[i - 3]) % mod;
		ou.println(q[s]);
		ou.flush();
	}
}

Measured memory_bytes: 35748
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int R; cin >> R;
	double ans = M_PI * (double)R * 2.;
	printf("%.4lf\n", ans);

	return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main()
{
	int n;
	vector<int> p;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}
	int ans = 0;
	for (int i = 1; i < p.size()-1; i++) {
		if ((p[i] - p[i - 1]) * (p[i] - p[i + 1]) < 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m = map(int,input().split())

tanshin = 2 * math.pi * m / 60
choushin = 2 * math.pi * (60*h + m) / 720
difference = choushin - tanshin
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(difference))
print(c)


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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 3e2+5;

int n, x, a, b, c;
ld memo[N][N][N];

ld dp (int i, int j, int k) {
    if (memo[i][j][k]) return memo[i][j][k];
    if (i+j+k > n) return 0;
    if (i or j or k) memo[i][j][k] = (ld) n/(i+j+k);
    if (i) memo[i][j][k] += i*dp(i-1, j,   k)  /(i+j+k);
    if (j) memo[i][j][k] += j*dp(i+1, j-1, k)  /(i+j+k);
    if (k) memo[i][j][k] += k*dp(i,   j+1, k-1)/(i+j+k);
    return memo[i][j][k];
}

int main () {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        if (x == 1) a++;
        if (x == 2) b++;
        if (x == 3) c++;
    }
    printf("%.10Lf\n", dp(a, b, c));
    return 0;
}


Measured memory_bytes: 436480
#include <stdio.h>
int Search(int);

int S[10000];
int n;

int main(){
  int T[500],q,C=0;
  int i;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++){
    if(Search(T[i])) C++;
  }
  printf("%d\n",C);
  return 0;
}

int Search(int key){
  int i;
  for(i = 0; i < n; i++){
    if(S[i] == key) return 1;
  }
  return 0;
}

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

int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    int cnt = 0;
    for(int i = 0 ; i < N-2 ; i++){
        if(S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>

int gcd(int a,int b){
	return b == 0 ? a : gcd(b,a%b);
}

int lcm(int a,int b){
	return a / gcd(a,b) * b;
}

int main(void){
	int a,b;

	while(scanf("%d%d",&a,&b) != EOF){
		printf("%d %d\n",gcd(a,b),lcm(a,b));
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(n*a,b) << endl;
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3632
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  2 15:08:28 2020
//
package main

import "fmt"

const MOD = 1e9 + 7

var H, N int
var A []int

func main() {
	fmt.Scan(&H, &N)
	A = make([]int, N)

	sum := 0
	for i := range A {
		fmt.Scan(&A[i])
		sum += A[i]
	}

	if H <= sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

void solve()
{
	vi a;
	for(int x;cin>>x && x;) a.push_back(x);
	
	vector<pii> es;
	vi path(1,0),deg(1,a[0]);
	for(int i=0,j=0,v=0;i<a.size()-1;i++){
		while(deg[j]==0){
			path.pop_back();
			deg.pop_back();
			j--;
		}
		deg[j]--;
		if(a[i+1]<0){
			es.emplace_back(path[j],path[j+a[i+1]]);
			deg[j+a[i+1]]--;
		}
		if(a[i+1]>0){
			v++;
			es.emplace_back(path[j],v);
			path.push_back(v);
			deg.push_back(a[i+1]-1);
			j++;
		}
	}
	
	int n=0;
	for(auto p:es) n=max({n,p.first,p.second});
	
	vvi g(++n);
	for(auto p:es){
		int u,v; tie(u,v)=p;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	rep(u,n){
		cout<<u+1;
		sort(all(g[u]));
		for(int v:g[u]) cout<<' '<<v+1;
		cout<<endl;
	}
}

int main()
{
	int tc; cin>>tc;
	rep(_,tc) solve();
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char s[MN+5];int ans=1e9;
int n,head[MN+5],cnt,rt,allb[MN+5],f[MN+5],mx[MN+5],from[MN+5],mx2[MN+5],g[MN+5],d[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;
}
inline void Add(int x,int v,int s)
{
	if(v>mx[x]) mx2[x]=mx[x],mx[x]=v,from[x]=s;
	else mx2[x]=max(mx2[x],v);
}
inline int V(int x,int S){return (s[x]=='W')^(S&1);}
void dfs(int x,int fa)
{
	allb[x]=s[x]=='B';mx[x]=mx2[x]=-1e9;f[x]=1;
	for(int i=head[x];i;i=e[i].next)
		if(e[i].to!=fa)
		{
			dfs(e[i].to,x);
			allb[x]&=allb[e[i].to];
			if(allb[e[i].to]) continue;
			f[x]+=f[e[i].to]+1;++d[x];
			Add(x,f[e[i].to]+1-g[e[i].to],e[i].to);
		}
	g[x]=f[x]-mx[x]+V(x,d[x]?d[x]:1);f[x]+=V(x,d[x]+1);
	if(!d[x]) g[x]=f[x]+V(x,1);
//	cout<<x<<" f= "<<f[x]<<" g= "<<g[x]<<endl;
}
void Solve(int x,int fa)
{
//	cout<<"Solve"<<x<<" "<<fa<<" "<<f[x]<<" "<<mx[x]<<" "<<from[x]<<endl;
	int dd=d[x]+(fa>0);f[x]-=V(x,d[x]+1);ans=min(ans,min(f[x]+V(x,dd+1),f[x]-mx[x]+V(x,dd?dd:1)));
	for(int i=head[x];i;i=e[i].next) if(e[i].to!=fa&&!allb[e[i].to])
	{
		int ff=f[x]-f[e[i].to]-1+V(x,dd),gg=ff-V(x,dd)-(from[x]==e[i].to?mx2[x]:mx[x])+V(x,dd>1?dd-1:1);
	//	cout<<x<<" - > "<<e[i].to<<" "<<ff<<" "<<gg<<endl;
		f[e[i].to]+=ff+1;
		Add(e[i].to,ff+1-gg,x);
		Solve(e[i].to,x);
	}
}
int main()
{
	n=read();
	for(int i=1;i<n;++i) ins(read(),read());
	scanf("%s",s+1);
	for(rt=1;s[rt]=='B';++rt);if(rt>n) return 0*puts("0");
	dfs(rt,0);Solve(rt,0);cout<<ans;
	return 0;
}



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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"

using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 10000000;
const ll inf = 5e18-1;
	
int main() {
	fastio;
	ll s,w;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
	return 0;
	}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K);
    for (int i = 0; i < K; i++)
    {
        cin >> d.at(i);
        vector<int> input(d.at(i));
        for (int j = 0; j < d.at(i); j++)
        {
            cin >> input.at(j);
            A.at(i).push_back(input.at(j));
        }
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        bool trick = true;
        for (int k = 0; k < K; k++)
        {
            for (int j = 0; j < d.at(k); j++)
            {
                if (i == A.at(k).at(j) - 1)
                {
                    trick = false;
                }
            }
        }
        if (trick)
        {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<bool> app(26);
  rep(i, s.size()) app[s[i] - 'a'] = true;
  rep(i, 26) if(!app[i]) {
    printf("%c\n", char(i + 'a'));
    return 0;
  }
  
  printf("None\n");
  return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()

int main() {
  int n,m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n){
     int a; cin >> a;
     q.push(a);
  }
  rep(i,m){
     int a=q.top(); q.pop();
     q.push(a/2);
  }
  long long ans=0;
  rep(i,n){
     ans+=q.top(); q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll n;
    cin >> n;
    ll c = 0;
    for (ll i = 1; i <= n; ++i) {
        if (i >= 1 && i <10) {
            ++c;
        }
        if (i >= 100 && i < 1000) {
            ++c;
        }
        if (i >= 10000 && i < 100000) {
            ++c;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 256
def myAnswer(N,M,L,R) -> int:
   total = 0
   MAXL=max(L)
   MINR =min(R)
   for i in range(1,N+1):
      if(MAXL<= i and MINR >= i):
         total += 1
   return total


def modelAnswer():
   tmp=1
def main():
   N, M = map(int,input().split())
   L =[]
   R = []
   for _ in range(M):
      l,r = map(int,input().split())
      L.append(l)
      R.append(r)
   print(myAnswer(N,M,L[:],R[:]))
   

if __name__ == '__main__':
   main()

Measured memory_bytes: 12620
// AOJ ITP 1_4_D
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef long long ll;

const int INF = 1 << 30;

int n;
ll ma=-INF, mi=INF, sum;

int main()
{
	scanf( "%d", &n );
	rep( i, n )
	{
		ll a;
		scanf( "%lld", &a );
		ma = std::max( ma, a );
		mi = std::min( mi, a );
		sum += a;
	}

	printf( "%lld %lld %lld\n", mi, ma, sum );

	return 0;
}

Measured memory_bytes: 1028
require 'set'
A, B, C, D, E, F = gets.split.map(&:to_i)

def water_comb(a, b, max, acc = 0)
  comb = Set.new()
  comb = comb.union(Set.new([acc + a]).union(water_comb(a, b, max, acc + a))) if max >= acc + a
  comb = comb.union(Set.new([acc + b]).union(water_comb(a, b, max, acc + b))) if max >= acc + b
  comb
end

$suger_memo = {}
def max_suger(c, d, f)
  return $suger_memo[f] if $suger_memo[f]
  max = 0
  if f >= c
    a = c + max_suger(c, d, f - c)
    max = [max, a].max
  end
  if f >= d
    a = d + max_suger(c, d, f - d)
    max = [max, a].max
  end
  $suger_memo[f] = max
end

weight = 0
suger_weight = 0
percent = 0
water_comb(A * 100, B * 100, F).to_a.each do |w|
  rest = F - w
  f = w / 100 * E
  s = max_suger(C, D, [rest, f].min)
  next if w == 0
  next if w == 0 && s == 0
  x = (100.0 * s) / (w + s)
  if x >= percent
    percent = x
    weight = w + s
    suger_weight = s
  end
end
puts "#{weight} #{suger_weight}"


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

int main(void) {
  long long X;
  cin >> X;
  for (long long i = 1; i <= 1000; i++) {
    for (long long j = -1000; j <= 1000; j++) {
      if (i * i * i * i * i - j * j * j * j * j == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3632
import java.io.*
import java.util.*

fun solve(N: Int, a: IntArray) {
    val memo = IntArray(N + 1){ -1 }
    var idx = 0
    var cur = 1
    while(idx < N){
        if(a[idx] == cur){
            memo[cur] = idx
            cur++
        }
        idx++
    }
    if (memo[1] == -1){
        println(-1)
        return
    }
    var ans = memo[1]
    var ret = memo[1]
    for (i in 2..N){
        if (memo[i] == -1 || memo[i] < ret){
            // 右の数字を全破壊
            ans += N - ret - 1
            break
        }
        ans += memo[i] - ret - 1
        ret = memo[i]
    }
    println(ans)
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val a = IntArray(N.toInt())
    for (i in 0 until N.toInt()) {
        a[i] = sc.next().toInt()
    }
    solve(N, a)
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){cin >> a[i];}
  int max = *max_element(a.begin(),a.end());
  int min = *min_element(a.begin(),a.end());
  cout << max-min << endl;
}

Measured memory_bytes: 256
//wherever you are,whatever you do, be in love

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

vector<ll> g[2*100002];
ll vis[2*100002];

ll dfs(ll u,ll par){
	ll cn=1;
	vis[u]=1;
	for(auto x:g[u]){
		if(!vis[x]) cn+= dfs(x,u);
	}
	return cn;
}

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

	forn(i,m){
		ll u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	ll ma=0;
	for1(i,n){
		if(!vis[i]) ma=max(ma,dfs(i,0));
	}
	cout<<ma;	
}

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

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(long long int* a, long long int* b)
{
	long long int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int main()
{
	long long int A, B;

	scanf("%lld%lld", &A, &B);

	if (A > B)
		swap(&A, &B);

	for (long long int i = A; i <= A*B; i += A)
	{
		if (i%B == 0)
		{
			printf("%lld\n", i);
			return 0;
		}
	}
}

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

using namespace std;

int main(){
  int n;
  vector <int> w;
  cin >> n;
  cin.ignore();
  int tmp;

  for (int i = 0; i < n; i++){
    cin >> tmp;
    w.push_back(tmp);
  }
  cin.ignore();

  // 総和
  int sum = accumulate(w.begin(), w.end(), 0);

  int s1 = 0;
  int s2;

  int ab = sum;
  int minab;

  for (int i = 0; i < n - 1; i++){
    s1 += w[i];
    s2 = sum - s1;
    ab = abs(s1-s2);
    if(i == 0){
      minab = ab;
    } else {
      if(ab < minab){
        minab = ab;
      } else {
        cout << minab << endl;
        return 0;
      }
    }
  }

  cout << ab << endl;


  return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}
int char_to_int(char val) {
    return val - '0';
}

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M); REP(i, M) cin >> A[i];

    ll sum_num = accumulate(all(A), 0LL);

    ll ans = N - sum_num;
    if(ans < 0) {
      cout << -1 << endl;
    } else if(ans >= 0) {
      cout << ans << endl;
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int r; cin >> r;
  cout << r * r << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int INF = 1 << 23;

int main(void) {
    int e;
    while(cin >> e and e) {
        int ans = INF;
        for(int z = 0; z*z*z <= e; z++)
            for(int y = 0; y*y <= e - z*z*z; y++) 
                ans = min(ans, e + y + z - y*y - z*z*z);

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


vector<vector<int>> G;
vector<int> A;
vector<int> Ans;

void DFS(int n, map<int, set<pair<int, int>>>& LenToVal)
{
    if (Ans[n] != 0) {
        return;
    }
    
    int Len = 1;
    for (auto it = LenToVal.rbegin(); it != LenToVal.rend(); ++it) {
        if (it->second.begin()->first < A[n]) {
            Len = it->first + 1;
            break;
        }
    }
    
    LenToVal[Len].emplace(A[n], n);
    Ans[n] = LenToVal.rbegin()->first;
    for (int m : G[n]) {
        DFS(m, LenToVal);
    }
    LenToVal[Len].erase(make_pair(A[n], n));
    if (LenToVal[Len].empty()) {
        LenToVal.erase(Len);
    }
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    A.assign(N, 0);
    for (int n = 0; n < N; ++n) {
        cin >> A[n];
    }
    G.assign(N, vector<int>());
    for (int n = 0; n < N-1; ++n) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    
    Ans.assign(N, 0);
    map<int, set<pair<int, int>>> LenToVal;
    DFS(0, LenToVal);
    
    for (int n = 0; n < N; ++n) {
        cout << Ans[n] << '\n';
    }

    return 0;
}


Measured memory_bytes: 41592
#include<stdio.h>

int main() {
	int max, i, n, l[10], sum;
	if (scanf("%d", &n) == 0) return 1;
	sum = 0;
	max = 0;
	for (i = 0; i < n; i++) {
		if (scanf("%d", &l[i]) == 0) return 1;
	}
	for (i = 0; i < n; i++) {
		sum += l[i];
		if (max < l[i]) max = l[i];
	}
	printf(sum - max > max ? "Yes" : "No");

	return 0;
}

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

class Stack{
    private:
        int top = 0;
        int S[1000];
    public:
        void push(int x);
        int pop();
};
void Stack::push(int x){
    Stack::top += 1;
    Stack::S[Stack::top] = x;
}
int Stack::pop(){
    Stack::top -= 1;
    return Stack::S[Stack::top+1];
}

int main() {
    int a, b;
    char s[100];
    Stack stack;

    while(scanf("%s", s) != EOF){
        if (s[0] == '+'){
            b = stack.pop();
            a = stack.pop();
            stack.push(a + b);
        } else if (s[0] == '-'){
            b = stack.pop();
            a = stack.pop();
            stack.push(a - b);
        } else if (s[0] == '*'){
            b = stack.pop();
            a = stack.pop();
            stack.push(a * b);
        } else {
            stack.push(atoi(s));
        }
    }
    printf("%d\n", stack.pop());

    return 0;
}



Measured memory_bytes: 2760
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//red and black
#if 0

#endif // 0
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
#define MAX 1000
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
int matri[MAX][MAX],s[MAX][MAX];
int w,h;
bool valid(int x,int y)
{
    return x>=0&&x<w&&y>=0&&y<h&&matri[x][y];
}
int main()
{
    while(cin>>w>>h&&w&&h)
    {
        pair<int,int> p;
        for(int j=0;j<h;j++)
            for(int i=0;i<w;i++)
            {
                s[i][j]=1;
                char c;
                cin>>c;
                if(c=='.')
                    matri[i][j]=1;
                else if(c=='#')
                {
                    matri[i][j]=0;
                    s[i][j]=0;
                }
                else if(c=='@'){
                    matri[i][j]=1;
                    p.first=i;
                    p.second=j;
                }
            }
        stack<pair<int,int> > q;
        int sum=0;
        q.push(p);
        s[p.first][p.second]=0;
        while(!q.empty())
        {
            p=q.top();
            int i;
            for(i=0;i<4;i++)
            {
                int x=p.first+dx[i];
                int y=p.second+dy[i];
                if(valid(x,y)&&s[x][y])
                {
                    p.first=x;
                    p.second=y;
                    q.push(p);
                    s[x][y]=0;
                    break;
                }
            }
            if(i>=4)
            {
                sum++;
                q.pop();
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}



Measured memory_bytes: 3320