akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int n;
int w[10001];
int f[10001];
int edge[10001];
bool used[10001];
vector<int> vs;

void dfs(int v){
	used[v]=true;
	vs.push_back(w[v]);
	if(!used[edge[v]])dfs(edge[v]);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&w[i]);
		f[i]=w[i];
	}
	sort(f,f+n);
	ll res=0;
	for(int i=0;i<n;i++){
		if(f[i]==w[i])edge[i]=i;
		else edge[i]=lower_bound(f,f+n,w[i])-f;
	}
	for(int i=0;i<n;i++){
		if(edge[i]!=i){
			vs.clear();
			dfs(i);
			int all=vs[0];
			int minx=vs[0];
			for(int j=1;j<vs.size();j++){
				minx=min(minx,vs[j]);
				all+=vs[j];
			}
			res+=min(all+(vs.size()-2)*minx,all+(vs.size()+1)*f[0]+minx);
		}
	}
	printf("%d\n",res);
	return 0;
}

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

int main() {

    int N; cin >> N;
    vector<int> L;

    for(int i = 0; i < 2*N; i++){
        int tmp; cin >> tmp;
        L.push_back(tmp);
    }

    int ans;
    sort(L.begin(), L.end());

    for(int i = 0; i < 2*N; i += 2){
        ans += min(L[i], L[i+1]);
    }


    cout << ans << endl;

    return 0;
}

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



int main() {
string S;
cin >> S;
int lo = S.size();
bool check = 1;
if(lo % 2 == 1)check = 0;
sort(S.begin(),S.end());
for(int i = 0; i < lo; i++){
if(S[i] != S[i+1]) check = 0;
i+=1;
}

if(check == 1)cout << "Yes"<< endl;
else cout << "No" << endl;

}



Measured memory_bytes: 256
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long N = arr[0], K = arr[1];
        var answer = N;
        var isZero = K == 1 || N % 2 == 0 && K == 2;
        if (isZero) answer = 0;
        if (!(N <= Math.Abs(N - K)) && !isZero){
            var mod = N % K;
            answer = mod < Math.Abs(mod - K) ? mod : Math.Abs(mod - K);}
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27444
N, K = list(map(int,input().split()))

def sum_(i, j):
    return (a[i] + a[j]) * (j - i + 1) // 2

a = [i for i in range(N + 1)]
ans = 0
for i in range(K, N + 2):
    min_ = sum_(0, i - 1)
    max_ = sum_(N - i + 1, N)
    ans += (max_ - min_ + 1)
    ans %= 10 ** 9 + 7
print(ans)

Measured memory_bytes: 81196
#define _XOPEN_SOURCE 500
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n, m;
int a[10005];
void solve() {
    cin >> n >> m;
    rep(i, m) cin >> a[i];
    int sum = 0;
    rep(i, m) sum += a[i];
    if (sum > n)
        cout << -1 << endl;
    else
        cout << n - sum << endl;
}

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


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

int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int x=tx-sx, y=ty-sy;
    cout<<string(y,'U')<<string(x+1,'R')<<string(y+1,'D')<<string(x+1,'L')<<"U";
    cout<<"L"<<string(y+1,'U')<<string(x+1,'R')<<string(y+1,'D')<<string(x,'L')<<endl;

    return 0;
}

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

using namespace std;

int q_sort(int d[],int left,int right){
	if(left >= right) return 0;
	int pipot = d[(left+right)/2], l = left, r = right, tmp;
	while(l<r){
		while(d[l] < pipot) l++;
		while(d[r] > pipot) r--;
		if( l <=  r){
			tmp = d[l]; 
			d[l] = d[r];
			d[r] = tmp;
			l++; r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}
int main(void){
	int N; cin >> N;
	int L[N],i;
	for(i = 0; i < N;i++){
		cin >> L[i];
	}
	q_sort(L,0,N-1);
	int j,k,ans,flag,w;
	ans = 0;
	//cout << "N = " << N << " L[N-1] == "<<L[N-1]<<endl;
	for(i = 0; i < N-2 ; i++){
		for(j = i+1; j < N-1;j++){
			k = N-1;
			flag = 0;
			while(L[i] + L[j] <= L[k]){
				flag = 0;
				k--;
				//cout << "i = " << i << "  j = "<<j<<"  k = "<<k<<endl;
				if(k == j){
					flag = 1;
					break;
				}
			}
			if(flag == 0){
				//cout << "i = " << i << "  j = "<<j<<"  k = "<<k<<endl;
				w = k - j;
				ans += w;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define N 100001

int n, m, dp[100001];
vector<int> g[100001];

int dfs(int u) {
        if (dp[u]) return dp[u];
        dp[u] = 1;
        for (int i = 0; i < g[u].size(); i++) {
                int to = g[u][i];
                dp[u] = max(dfs(to) + 1, dp[u]);
        }
        return dp[u];
}

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n>> m;
        for (int i = 0, v, u; i < m; i++) {
                cin >> v>> u;
                g[v].push_back(u);
        }
        int mx = -1;
        for (int i = 1; i <= n; i++) {
                mx = max(mx, dfs(i));
        }
        cout << mx - 1;
return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	ll sum1 = 0, sum2 = 0;
	REP(i, n) sum1 += a[i];
	REP(i, n) sum2 += b[i];
	if(sum1 < sum2) {
		cout << -1 << endl;
		return 0;
	}
	vector<ll> v1;
	vector<ll> v2;
	REP(i, n) {
		if(a[i] - b[i] == 0) continue;
		if(a[i] - b[i] > 0) {
			v1.pb(a[i] - b[i]);
		} else {
			v2.pb(a[i] - b[i]);
		}
	}
	ll ans = v2.size();
	sort(ALL(v1)); sort(ALL(v2));
	reverse(ALL(v1));
	REP(i, v2.size()) v2[i] = abs(v2[i]);
	if(v2.empty()) {
		cout << 0 << endl;
		return 0;
	}
	ll diff = 0;
	REP(i, v2.size()) diff += v2[i];
	ll sum = 0;
	REP(i, v1.size()) {
		sum += v1[i];
		if(sum >= diff) {
			cout << ans + (i + 1) << endl;
			return 0;
		}
	}
	return 0;
}

/* --------------------------------------- */


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

using namespace std;

int main() {

	string str;

	cin >> str;

	int flag = 0;

	int A = 0.5 * (str.size() - 1);
	int B = 0.5 * (str.size() + 3);

	for (int i = 0; i < str.size(); i++) {
		if (str[i] != str[str.size() - i - 1]) {
			flag = 1;
		}
	}

	for(int i = 0; i < A; i++){
		if (str[i] != str[A - i - 1]) {
			flag = 1;
		}
	}

	for (int i = B - 1; i < str.size(); i++) {
		if (str[i] != str[B + str.size() - i - 2]) {
			flag = 1;
		}
	}

	if (flag == 0) {
		cout << "Yes";
	}

	if (flag == 1) {
		cout << "No";
	}

}

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

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){

  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){

  P a = Q[head];
  head = (head + 1) % LEN;
  return a;
}

int min(int a, int b){

  if(a < b)
    return a;
  else
    return b;
}

int main(){

  int elaps = 0, c;
  int i, q;
  P u;

  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  tail = n + 1;
  head = 1;

  while(head != tail){

    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;

    if(u.t > 0)
      enqueue(u);
    else
      printf("%s %d\n", u.name, elaps);
  }

  return 0;
}


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

const int MAX = 1000000;
const int MOD=1000000007;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  vector<int>R;
  vector<int>L;
  int rnow=1;
  int lnow=1;
  bool r_ok=true;
  bool l_ok=false;
  rep(i,n-1){
    if(s[i]==s[i+1]){
      if(r_ok)rnow++;
      if(l_ok)lnow++;
    }
    else{
      if(r_ok){
        R.push_back(rnow);
        rnow=1;
        r_ok=false;
        l_ok=true;
        continue;
      }
      if(l_ok){
        L.push_back(lnow);
        lnow=1;
        l_ok=false;
        r_ok=true;
        continue;
      }
    }
  }
  L.push_back(lnow);
  
  queue<int>q;
  rep(i,R.size()){
    int sum = R[i]+L[i];
    if(sum%2==0){
      q.push(sum/2);
      q.push(sum/2);
    }
    else{
      if(R[i]>L[i]){
        if(min(R[i],L[i])%2!=0){
          q.push(sum/2);
          q.push(sum/2+1);
        }
        else{
          q.push(sum/2+1);
          q.push(sum/2);
        }
      }
      else{
        if(min(R[i],L[i])%2!=0){
          q.push(sum/2+1);
          q.push(sum/2);
        }
        else{
          q.push(sum/2);
          q.push(sum/2+1);
        }
      }    
    }
  }
  rep(i,n-1){
    int ans=0;
    if(s[i]==s[i+1]) cout << ans <<" ";
    if(s[i]=='R' &&s[i+1]=='L'){
      ans = q.front();
      q.pop();
      cout << ans <<" ";
      ans = q.front();
      q.pop();
      cout << ans <<" ";
    }
  }
      
}

Measured memory_bytes: 1404
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

--powmod a b p= (a ^ b) mod p
powmod a b p
    | b == 0 = 1
    | b == 2 = mod (a*a) p
    | odd b  = mod ((a *) $ powmod a (b-1) p) p
    | True   = mod ((^ 2) $ powmod a (div b 2) p) p

main=do
    n<-readLn :: IO Int
    aa@(a:as) <-sort.unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine :: IO [Int]
    print $ if (if even n then chk 1 aa else (a==0) && (chk 2 as))
        then powmod 2 (n`div`2) 1000000007
        else 0

chk _ [] = True
chk n (a:b:as)
    | a==n && b==n = chk (n+2) as
    | True = False


Measured memory_bytes: 17788
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(int i=0;i<(int)n;++i)
#define _rep1(i,k,n) for(int i=k;i<(int)n;++i)
#define _rep2(i,k,n,d) for(int i=k;d>0?i<(int)n:i>(int)n;i+=d)
#ifdef __LOCAL
#include "ostreams.h"
#endif
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(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

constexpr ll N = 505;
ll dp[N][N];
bool used[N][N];
ll di[4] = {-1, 1, 0, 0};
ll dj[4] = {0, 0, -1, 1};

void solve(){
    ll n; cin >> n;
    rep(i, n)rep(j, n){
        dp[i][j] = min((ll)min(i, j), (ll)min(n - i - 1, n - j - 1));
        used[i][j] = true;
    }

    ll ans = 0;
    rep(_, n * n){
        ll p; cin >> p; p--;
        ll i = p / n, j = p % n;
        ans += dp[i][j];
        used[i][j] = false;
        // dfs
        vector<pair<ll, ll>> stack{{i, j}};
        while(stack.size()){
            auto [i, j] = stack.back(); stack.pop_back();
            rep(t, 4){
                ll ni = i + di[t], nj = j + dj[t];
                if(!(0 <= ni and ni < n and 0 <= nj and nj < n)){
                    continue;
                }
                if(chmin(dp[ni][nj], dp[i][j] + used[i][j])){
                    stack.emplace_back(ni, nj);
                }
            }
        }
    }

    cout << ans << '\n';
}

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

typedef long long ll;



int main()
{
    string s;
    int k;
    cin>>s>>k;
    for(int i=0;i<s.length();i++){
        if(s[i]=='1')
            k-=1;
        else
            k=-1;
        if(k<=0){
            cout<<s[i];
            return 0;
        }



    }
}


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

int32_t main() 
{
  ios::sync_with_stdio(0); 
  cin.tie(0); cout.tie(0);
  
  int n, k;
  cin >> n >> k;
  int x[n];
  for(int i = 0; i < n; i++)
     cin >> x[i];

  int ans = 1e18;

  for(int i = 0; i + k - 1 < n; i++){
      if(x[i] * x[i + k - 1] >= 0)
          ans = min(ans, max(abs(x[i]), abs(x[i + k - 1])));
      else
          ans = min(ans, abs(x[i]) + abs(x[i + k - 1]) + min(abs(x[i]), abs(x[i + k - 1])));
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 4456
#include <algorithm>
#include <cstdio>
const int MAXN = 25;
int P[MAXN];
int N;

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &P[i]);
  }
  int ret = 0;
  for (int i = 2; i < N; ++i) {
    int mn = P[i-1];
    int mx = P[i+1];
    if (mn > mx) std::swap(mn, mx);
    if ((mn < P[i]) && (P[i] < mx)) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 128
// AOJ 2440

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
	int n, m;
	string str;
	vector <string> keys;
	bool door = false;

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> str;
		keys.push_back(str);
	}

	cin >> m;
	for (int i = 0; i < m; i++){
		cin >> str;
		bool know = false;
		for (int j = 0; j < n; j++){
			if (keys[j] == str){
				know = true;
			}
		}
		if (know){
			if (door){
				cout << "Closed by " << str << endl;
				door = false;
			}
			else {
				cout << "Opened by " << str << endl;
				door = true;
			}
		}
		else {
			cout << "Unknown " << str << endl;
		}
	}

	return 0;
}

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

typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  
  map<int, int> mp;
  
  for(int i=0; i<m; i++){
    int a,b;
    cin >> a >> b;
    
    mp[a++]++, mp[b++]++;
  }
  
  for(int i=1; i<=n; i++){
    cout << mp[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  string S;  
  cin >> S;
  
  string result = "Yes";
  
  if (S.at(0) == S.at(1) && S.at(1) == S.at(2)) {
    result = "No"; 
  }
  
  cout << result << endl;

}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int N;
vec<vec<int>> G;

void dfs(int pos, int par, int cost, vec<int>& dist) {
   dist[pos] = cost;
   for (int to : G[pos]) {
      if (to != par) {
         dfs(to, pos, cost+1, dist);
      }
   }
}

int main() {
   cin >> N;
   G = vec<vec<int>>(N);
   rep (i, N-1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }
   vec<int> dist1(N), dist2(N);
   dfs(0, -1, 0, dist1);
   dfs(N-1, -1, 0, dist2);
   int b = 0, w = 0;
   rep (i, N) {
      if (dist1[i] <= dist2[i]) {
         b++;
      } else {
         w++;
      }
   }

   if (b > w) {
      puts("Fennec");
   } else {
      puts("Snuke");
   }

   return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M, a[100000], c;
ll MIN, t;
vector<int>v[100000];

int main() {
	cin >> N >> M;
	for (int i = 0; i != N; ++i) {
		cin >> a[i];
		--a[i];
		v[a[i]].push_back(i);
	}
	for (int i = 1; i != N; ++i) {
		if (a[i - 1] != 0 && a[i] && a[i] < a[i - 1]) {
			++c;
		}
		t += min(a[i] + 1, (M + a[i] - a[i - 1]) % M);
	}
	MIN = t;
	//cout << t << sp << c << endl;
	for (int i = 1; i != M; ++i) {
		t -= c;
		for (int j = 0; j != v[i - 1].size(); ++j) {
			if (v[i - 1][j] != N - 1)
				++c;
			if (v[i - 1][j]) {
				t += (M + a[v[i - 1][j]] - a[v[i - 1][j] - 1]) % M - 1;
			}
		}
		for (int j = 0; j != v[i].size(); ++j) {
			if (v[i][j]) {
				--c;
			}
		}
		//cout << t << sp << c << endl;
		MIN = min(MIN, t);
	}
	cout << MIN << endl;
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	if(n%(2*d+1)==0)
	{
		cout<<n/(2*d+1)<<endl;
	}
	else
	{
		cout<<n/(2*d+1) +1<<endl;
	}
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

const int N=1e5+7;
vector<int> gp[N];

int main(){
    nimble
    int n,m;
    cin>>n>>m;
    rep(i,0,m){
        int u,v;
        cin>>u>>v;
        gp[u].pb(v);
        gp[v].pb(u);
    }
    vector<int> d(N);
    rep(i,0,N)d[i]=inf;
    d[1]=0;
    deque<int> q;q.push_back(1);
    while(_sz(q)){
        int u=q.front();q.pop_front();
        for(int j=0;j<_sz(gp[u]);j++){
            int v=gp[u][j];
            if(d[v]==inf){
                d[v]=d[u]+1;
                q.push_back(v);
            }
        }
    }
    map<int,vector<int>> mp;
    mp[0].pb(1);
    for(int i=2;i<=n;i++){
        mp[d[i]].pb(i);
    }
    map<int,int> as;
    int f=1;
    int xx=0;
    for(auto x:mp){
        if(f){
            f=0;
            continue;
        }
        vector<int> t=x.Y;
        for(int i=0;i<_sz(t);i++){
            if(mp.find(x.X-1)==mp.end()){
                xx=1;
                break;
            }
            as[t[i]]=mp[x.X-1][0];
        }
    }
    if(xx){
        cout<<-1<<nl;
        return 0;
    }
    cout<<"Yes"<<nl;
    for(int i=2;i<=n;i++)cout<<as[i]<<nl;
    return 0;
}


Measured memory_bytes: 24744
s = input()
s_ki = s[0::2]
s_gu = s[1::2]
count = 0
for i in s_ki:
    if i == 'L':
        count += 1
for _ in s_gu:
    if _ == 'R':
        count += 1
if count ==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;
#define Fill(a, b) memset(a, b, sizeof(a))
#define Debug(x) cout << #x << "=" << (x) << endl;
typedef long long LL;
const LL inf = 1LL << 61;
const LL mod = 1000000007;
//Fill(dp,0x3f3f3f3f)
#define DEBUG
#ifdef DEBUG
#endif
const int maxn = 2010;


int a[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n, z, w;
    scanf("%d%d%d", &n, &z, &w);
    for(int i = 1; i <= n; i++)
    {
    	scanf("%d", &a[i]);
    }
    int ans = 0;
    if(n==1)
    	ans = abs(a[1]-w);
    else
    	ans = max(abs(a[n-1]-a[n]), abs(a[n]-w));
    printf("%d\n", ans);






















    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 5e6 + 5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

vector<int> v[N];
int DP[N];

void solve()
{
	int n, d;
	cin >> n >> d;
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		if(x * x + y * y <= d * d)
		{
			cnt++;
		}
	}
	cout << cnt << endl;
}
 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 15364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long int

#define rep(p,q) for(int i = p; i < q;i++)


int main(void) {
	int n;
	vector<int> vec = vector<int>();
	cin >> n;
	rep(0, n) {
		int a;
		cin >> a;
		vec.push_back(a);
	}
	bool flag = true;
	int count = 0;
	while (flag) {
		flag = false;
		for (int i = n - 1; 0 < i; i--) {
			if (vec[i] < vec[i - 1]) {
				int tmp = vec[i];
				vec[i] = vec[i - 1];
				vec[i - 1] = tmp;
				flag = true;
				count++;
			}
		}
	}
	rep(0, n - 1) cout << vec[i] << " ";
	cout << vec[n - 1] << endl << count << endl;
}


Measured memory_bytes: 3144
// abc175_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    
    ll ans = 0;
    
    ll n = X / D;
    if (K <= n){
        ans = X - K * D;
    } else {
        ans = abs((X % D) - (D * ((K - n) % 2)));
    }
    
    print(ans);
    


    return 0;
}


Measured memory_bytes: 3644
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String topCoDeer = sc.nextLine();
        char[] chars = topCoDeer.toCharArray();
        int gooSurplus = 0;
        for(int i = 0; i < chars.length; i++) {
            if (chars[i] == 'g') {
                gooSurplus++;
            } else {
                gooSurplus--;
            }
        }
        int answer = (int) Math.floor(gooSurplus/2);
        System.out.println(answer);
    }
}

Measured memory_bytes: 27068
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let s: String = sc.input();
    let mut chs: Vec<char> = s.chars().collect();
    chs[3] = '8';
    let ans: String = chs.into_iter().collect();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream> 
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define pb push_back
bool hw(string s)
{
	rep(i,0,s.length()-1)
	{
		if(i>=s.length()-i-1)return true;
		if(s[i]!=s[s.length()-i-1])
		{
			return false;
		}
	}
	return true;
}
int main(int argc, char** argv) {
	string s,a,b;
	cin>>s;
	if(!hw(s))cout<<"No";
	else{
	int n=s.length();
	rep(i,0,s.length()-1)
	{
		if(i+1<=(n-1)/2)
		a+=s[i];
		if(i+1>=(n+3)/2)
		{
			b+=s[i];
		}
	}
//	cout<<a<<" "<<b<<endl;
	if(hw(s)&&hw(a)&&hw(b))
	{
		cout<<"Yes";
	}
	else cout<<"No";
}
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	string S;
	int K, L;
	cin >> S >> K;
	priority_queue<string> q;
	set<string> used;
	int n = S.size();
	L = K;
	for(int i = 0; i < n; ++i) {
		for(int j = 1; i + j <= n && j <= L; ++j) {
			string t = S.substr(i,j);
			if (used.find(t) != used.end()) {
				continue;
			}
			q.push(t);
			used.insert(t);
			if (K == 0) {
				q.pop();
			} else {
				K--;
			}
		}
	}
	cout << q.top() << endl;
	return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 5;
typedef long long int64;
int n;
int data[maxn];

int main()
{
  while (scanf("%d", &n) == 1)
  {
    for (int i = 0; i < n; ++i) scanf("%d", data+i);
    int ans = 0;
    sort(data, data+n);
    int64 s = 0;
    int last = -1;
    for (int i = 0; i < n; ++i)
    {
      s += data[i];
      if (i + 1 < n && s * 2 < data[i+1]) last = i;
    }
    cout << n - (last + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    int n;
    cin>>n;
    double p,dp[n+1]={},ans=0.0;
    for(int i=0;i<n;i++){
        cin>>p;
        if(!i)dp[0]=1.0-p,dp[1]=p;
        else for(int j=n;j>=0;j--)dp[j]=dp[j-1]*p+dp[j]*(1-p);
    }
    for(int i=(n+1)/2;i<=n;i++)ans+=dp[i];
    cout<<setprecision(15)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct Team
{
	string team;
	int num,point;
};
bool comp(Team a,Team b)
{
	if(a.point!=b.point)return a.point>b.point;
	return a.num < b.num;
}
int main()
{
	bool first=true;
	while(1)
	{
		int n;
		scanf("%d",&n);
		if(n==0)break;
		if(!first) cout << endl;
		else first=false;
		vector<Team> vec;
		for(int i=0;i<n;i++)
		{
			string team;
			int win,lose,tie;
			cin >> team >> win >> lose >> tie;
			int point=win*3+tie;
			Team a;
			a.team=team;
			a.num=i;
			a.point=point;
			vec.pb(a);
		}
		sort(vec.begin(),vec.end(),comp);
		for(int i=0;i<vec.size();i++)
		{
			cout << vec[i].team << ',' << vec[i].point << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1272
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

  int N;
  cin >> N;
  vector<int> A(N + 1, 0);
  rep(i, N) cin >> A[i];

  bool iflag = false, dflag = false;
  int ans = 0;

  rep(i, N - 1) {
    if (A[i] < A[i + 1]) {
      if (dflag) {
        ans++;
        dflag = false;
        continue;
      }
      dflag = false;
      iflag = true;
    } else if (A[i] > A[i + 1]) {
      if (iflag) {
        ans++;
        iflag = false;
        continue;
      }
      dflag = true;
      iflag = false;
    }
  }

  cout << ans + 1 << endl;

  return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {


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

		String S = scan.next();

		String ans = solve(S);

		System.out.println(ans);

	}

	/**
	 *  踏みやすい判定メソッド
	 * @param s
	 * @return
	 *
	 *
	 */
	public static String solve(String s)
	{
		// 文字列の長さ取得
		int sLen = s.length();

		// 偶数テーブル
		final List<String> Etable = new ArrayList<String>(Arrays.asList("L", "U", "D"));
		// 奇数テーブル
		final List<String> Otable = new ArrayList<String>(Arrays.asList("R", "U", "D"));


		for(int i = 0;i < sLen;i++)
		{
			// 文字を一文字ずつ抽出する
			char tmp = s.charAt(i);

			// 偶数判定
			// 数字の先頭を1番目にするため、1を足す
			if(0 == ((i + 1) & 1))
			{
				if(!Etable.contains(String.valueOf(tmp)))
				{
					return "No";
				}
			}
			// 奇数判定
			else
			{
				if(!Otable.contains(String.valueOf(tmp)))
				{
					return "No";
				}
			}
		}
		return "Yes";
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

int ryuca(int n){
    if(n==0){
        return 2;
    }else if(n==1){
        return 1;
    }else{
        return ryuca(n-1) + ryuca(n-2);
    }
}

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

    int n;
    cin >> n;
    // lint ans = ryuca(n);
    vector<lint> ans(n+1);
    for(int i=0; i<n+1; i++){
        if(i==0){
            ans[i] = 2;
        }else if(i==1){
            ans[i] = 1;
        }else{
            ans[i] = ans[i-1] + ans[i-2];
        }
    }

    COUT(ans[n]);

    return 0;
}

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

int main(){
  double a, b, c, C, S, L, h;
  cin >> a >> b >> C;
  C = C * M_PI / 180;
  S = a * b * sin(C) / 2;
  c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(C));
  L = a + b + c;
  h = b * sin(C);
  printf("%.8f\n%.8f\n%.8f\n", S, L, h);
}

Measured memory_bytes: 3468
#include <stdio.h>

int main(){
int i,n;
scanf("%d",&n);
for(i=3;i<=n;i++){
    if(i%3==0||i%10==3||i/10%10==3||i/100%10==3||i/1000==3)
    printf(" %d",i);}
printf("\n");
return 0;
}

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

int N,A,B,C;
vector<int> v(10);
const int INF=1e9;

int dfs(int now,int a,int b,int c){
    if(now==N){
        // 必ずa,b,cには一本ずつ選ぶから10×3だけ余計になる
        if(min({a,b,c})>0) return abs(A-a)+abs(B-b)+abs(C-c)-30;
        else return INF;
    }
    int r0=dfs(now+1,a,b,c);
    int r1=dfs(now+1,a+v[now],b,c)+10;
    int r2=dfs(now+1,a,b+v[now],c)+10;
    int r3=dfs(now+1,a,b,c+v[now])+10;
    return min({r0,r1,r2,r3});
}

int main(){
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++) cin>>v[i];
    int ans=dfs(0,0,0,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll N,A,B; 
int ans[140000][18];
bool used[140000][18];

int BITS(ll x){
    int ret=0;
    while(x>0){
        if(x%2) ret++;
        x/=2;
    }
    return ret;
}

void kinyu(ll a, ll x){
    rep(i,N) {
        ans[x][i]=a%2;
        a/=2;
    }
    return;
}

void exc(ll i, ll j){
    ans[i][j]=1-ans[i][j];
    return;
}

void solve(ll a, ll b){
    ll A=(a+b)/2;
    ll B=A+1;
    int x=-1,y=-1;
    rep(i,N) if(!used[a][i] && !used[b][i] && ans[a][i]!=ans[b][i]) {x=i; break;}
    REP(i,a,b+1) used[i][x]=true;
    rep(i,N) if(!used[a][i] && !used[b][i]) {y=i;break;}
    rep(i,N) ans[A][i]=ans[a][i];
    exc(A,y);
    rep(i,N) ans[B][i]=ans[A][i];
    exc(B,x);
    return;    
}



int main(){
    cin>>N>>A>>B;
    int a=BITS(A), b=BITS(B);
    rep(i,140000) rep(j,18) ans[i][j]=-1;
    if((a-b)%2==0) cout<<"NO"<<endl;
    else{
        cout<<"YES"<<endl;
        ll MAXN=(1<<N);
        kinyu(A,0);
        kinyu(B,MAXN-1);
        

        rep(i,N-1){
            ll Haba=(1<<(N-i));
            rep(j,(1<<i)) solve(Haba*j, Haba*(j+1)-1);
        }
        rep(i,MAXN) {
            ll kari=0;
            rep(j,N) if(ans[i][j]) kari+=(1<<j);
            cout<<kari<<' ';
        }
        cout<<endl;
        
        
        

    }
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=103,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<vector<int>> A(N,vector<int>(N));
    
    for(int i=0;i<M;i++){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        A[a][b]=c;
        A[b][a]=c;
    }
    
    int ans=0;
    
    set<vector<int>> SE;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(A[i][j]){
                ans=max(ans,A[i][j]*2);
                vector<int> use(N);
                use[i]=1;
                use[j]=1;
                SE.insert(use);
            }
        }
    }
    
    for(int q=2;q<15;q++){
        if(SE.empty()) break;
        
        set<vector<int>> ne;
        
        for(auto it=SE.begin();it!=SE.end();it++){
            for(int i=0;i<N;i++){
                if((*it)[i]) continue;
                bool ok=true;
                
                for(int j=0;j<N;j++){
                    if(i==j) continue;
                    if((*it)[j]&&A[i][j]==0){
                        ok=false;
                        break;
                    }
                }
                
                if(ok){
                    vector<int> S=*it;
                    S[i]=1;
                    int sum=0;
                    for(int j=0;j<N;j++){
                        if(S[j]==0) continue;
                        int mini=INF;
                        for(int k=0;k<N;k++){
                            if(S[k]==0) continue;
                            if(j==k) continue;
                            if(A[j][k]) mini=min(mini,A[j][k]);
                        }
                        sum+=mini;
                    }
                    
                    ans=max(ans,sum);
                    
                    ne.insert(S);
                }
            }
        }
        
        SE=ne;
    }
    
    cout<<ans<<endl;
}






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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

long long D[5];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, A;
	long long ans;
	D[1]=D[2]=D[3]=D[4]=0x7fffffff;
	for(cin>>N;N;N--) {
		cin>>A;
		D[4]=min(D[4],min(D[3],min(D[2],min(D[1],D[0]))))+A;
		D[3]=min(D[3],min(D[2],min(D[1],D[0])))+(A ? (A&1):2);
		D[2]=min(D[2],min(D[1],D[0]))+!(A&1);
		D[1]=min(D[1],D[0])+(A ? (A&1):2);
		D[0]+=A;
	}
	ans=D[0];
	for(int i=1;i<5;i++) ans=min(ans,D[i]);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine();
			if (input.Length < 8)
			{
				Console.WriteLine("YES");
				return;
			}
			int loseCount = 0;
			foreach(var s in input.ToCharArray())
			{
				if (s.Equals('x'))
				{
					loseCount++;
				}
				if (loseCount >= 8)
				{
					Console.WriteLine("NO");
					return;
				}
			}
			Console.WriteLine("YES");
		}
	}
}


Measured memory_bytes: 11092
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 10e16;
int inf = 10e8;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

template<typename T>
void dump_2d_mat(T &m, int N, int M) {
    REP(i, N) {
        REP(j, M) {
            cout << m[i][j] << " ";
        }
        cout << endl;
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;


    cout << fixed << setprecision(20);

    if (a > b) {
        REP(i, a) cout << b;
    } else {
        REP(i, b) cout << a;
    }

    cout << endl;

}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let h: usize = sc.read();
    let w: usize = sc.read();

    let mut uf = UnionFind::new(h + w);
    let mut edges = vec![];
    for _ in 0..n {
        let row = sc.read::<usize>() - 1;
        let col = sc.read::<usize>() - 1;
        let value: u64 = sc.read();
        edges.push((value, row, col + h));
    }
    edges.sort();

    let mut ans = 0;
    for (value, row, col) in edges.into_iter().rev() {
        let x = uf.find(row);
        let y = uf.find(col);

        if x != y {
            if uf.sizes[x] + uf.sizes[y] >= uf.edge_count[x] + uf.edge_count[y] + 1 {
                uf.unite(x, y);
                ans += value;
            }
        } else if uf.sizes[x] > uf.edge_count[x] {
            uf.edge_count[x] += 1;
            ans += value;
        }
    }

    println!("{}", ans);
}

pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
    edge_count: Vec<usize>,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
            edge_count: vec![0; n],
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;

        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;

        self.edge_count[large] += self.edge_count[small] + 1;
        self.edge_count[small] = 0;

        self.size -= 1;
        return true;
    }
}

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

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


Measured memory_bytes: 14588
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[2005][2005]={0};
ll dpsum[2005][2005]={0};
const ll mod=1e9+7;
ll s[2005],t[2005];
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++) cin>>s[i];
  for(int i=1;i<=m;i++) cin>>t[i];
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i]==t[j]){
        dp[i][j]+=dpsum[i-1][j-1];
        dp[i][j]++;
        dp[i][j]%=mod;
      }
      dpsum[i][j]=dpsum[i-1][j]+dpsum[i][j-1]-dpsum[i-1][j-1];
      dpsum[i][j]+=dp[i][j];
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      ans+=dp[i][j];
      ans%=mod;
    }
  }
  cout<<(ans+1)%mod<<endl;
}


Measured memory_bytes: 62848
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

int[] eratos(int N) {
    auto s = new bool[](N + 1);
    s[] = true;
    s[0] = s[1] = false;

    for (int p = 2; p*p <= N; p++) {
        if (s[p]) for (int d = p*p; d <= N; d += p) {
            s[d] = false;
        }
    }

    return iota(N + 1).filter!(i => s[i]).array;
}

void main() {
    int N;
    scan(N);
    auto ans = eratos(55556).filter!"a % 5 == 1".take(N).array;
    writefln("%(%s %)", ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 380