akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

struct edge{int t; long long c; int r;};
vector<edge> G[105];
int depth[105], n, INF=1e15;
long long ans, a;
void add_edge(int f, int t, long long c){
	G[f].push_back(edge{t, c, (int)G[t].size()});
	G[t].push_back(edge{f, 0, (int)G[f].size()-1});
}
bool bfs(int s, int t){
	memset(depth,-1,sizeof(depth));
	depth[s] = 0;
	queue<int> que;
	que.push(s);
	while(!que.empty()){
		int v = que.front(); que.pop();
		for(edge e: G[v]) if(e.c && depth[e.t] == -1){
			depth[e.t] = depth[v] + 1;
			que.push(e.t);
		}
	}
	return depth[t] != -1;
}
long long dfs(int v, int t, long long f){
	if(v == t) return f;
	long long ret = 0;
	for(edge& e: G[v]){
		if(depth[v] < depth[e.t] && e.c){
			long long d = dfs(e.t, t, min(f - ret, e.c));
			if(d){
				e.c -= d; G[e.t][e.r].c += d;
				ret += d;
			}
		}
		if(f == ret) break;
	}
	return ret;
}
long long maxflow(int s, int t){
	long long ret = 0;
	while(bfs(s,t)) ret += dfs(s, t, INF);
	return ret;
}
 
int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a;
		if(a < 0) add_edge(i,n+1,-a);
		else{
			ans += a;
			add_edge(0,i,a);
		}
		for(int j=i*2; j<=n; j+=i) add_edge(j,i,INF);
	}
	cout<<ans-maxflow(0,n+1)<<endl;
}

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

using namespace std;

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

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

#endif

class CompareFirst{ public:
    bool operator()(P n1, P n2) {
        // return n1.first>n2.first; //>:昇順　pairのfirst同士を比較する
        return n1.first < n2.first; // 降順
    }
};


void Main() {
    ll N, M;
    cin >> N >> M;
    priority_queue< ll, vector<ll>, greater<ll> > A; // 小さい方から取り出し
    rep(i, N){ll a; cin >> a; A.push(a);}

    priority_queue<P, vector<P>, CompareFirst> CB;
    rep(i, M){ll b, c; cin >> b >> c; CB.push(make_pair(c, b));}

    while (CB.size() > 0){
        P p = CB.top();
        CB.pop();
        bool flag = false;
        rep(i, p.second){
            if (p.first > A.top()){
                A.pop();
                A.push(p.first);
            } else {
                flag = true;
                break;
            }
        }
        if (flag){break;}
    }
    ll ans = 0;
    while (A.size() > 0){ans += A.top(); A.pop();}
    cout << ans << endl;
}

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


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  bool ins = false;
  int streak = 0;
  for (int i = 0; i < s.size(); i++){
    if (!ins && (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T')) {
      ins = true; streak = 1;  continue;
    }
    if (ins && (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T')) {
      streak++; continue;
    }
    if (ins && !(s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T')) {
      ans = max(ans, streak);
      streak = 0; ins = false;
      continue;
    }
  }
  ans = max(ans, streak);
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	W := nextInt()
	H := nextInt()
	N := nextInt()
	blocks := make([][]int, H)
	for i := 0; i < H; i++ {
		blocks[i] = make([]int, W)
	}
	for i := 0; i < N; i++ {
		x := nextInt()
		y := nextInt()
		a := nextInt()
		switch a {
		case 1:
			for h := 0; h < H; h++ {
				for w := 0; w < x; w++ {
					blocks[h][w] = 1
				}
			}
		case 2:
			for h := 0; h < H; h++ {
				for w := x; w < W; w++ {
					blocks[h][w] = 1
				}
			}
		case 3:
			for h := 0; h < y; h++ {
				for w := 0; w < W; w++ {
					blocks[h][w] = 1
				}
			}
		case 4:
			for h := y; h < H; h++ {
				for w := 0; w < W; w++ {
					blocks[h][w] = 1
				}
			}
		}
	}
	cnt := 0
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if blocks[h][w] == 1 {
				cnt++
			}
		}
		log.Println(blocks[h])
	}
	fmt.Println(H*W - cnt)
}

func intPow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func intMax(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func intMin(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func intSum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func intAbs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = newScanner()
}

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
	int cards[4][14] = {0};
	int n, i, j, tmp;
	char c,c2;
	
	scanf("%d",&n);
	for (i = 0; i < n; ++i) {
		scanf(" %c %d%c",&c, &tmp, &c2);
		
		
		switch(c) {
		case 'S':
			cards[0][tmp] = 1;
			break;
		case 'H':
			cards[1][tmp] = 1;
			break;
		case 'C':
			cards[2][tmp] = 1;
			break;
		case 'D':
			cards[3][tmp] = 1;
			break;
		}
	}
	
	for (j = 0; j < 4; ++j) {
		for (i = 1; i < 14; ++i) {
			if (cards[j][i] == 1) {
				continue;
			}
			switch(j) {
			case 0:
				printf("S %d\n", i);
				break;
			case 1:
				printf("H %d\n", i);
				break;
			case 2:
				printf("C %d\n", i);
				break;
			case 3:
				printf("D %d\n", i);
				break;
			}
		}
	}
	return 0;
}

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

int check(int k, int dig) {
  while (k) {
    if (k % 10 == dig)
      return 1;
    k /= 10;
  }
  return 0;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(k);
  for (int &i : a)
    cin >> i;
  int ans = n;
  for (ans = n; ans <= 1000000; ans++) {
    int ok = 1;
    for (int dig : a) {
      if (check(ans, dig)) {
        ok = 0;
      }
    }
    if (ok) {
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int n,s;

int main(){
	int i;
	while( cin >> n ){
		if( !n )break;
		
		int ans = 0,mx = 0,mn = 10000;
		for( i = 0; i < n; i++ ){
			cin >> s;
			ans += s;
			mx = max( mx, s );
			mn = min( mn, s );
		}
		ans -= mx+mn;
		cout << ans/(n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int factorization(int n){
    int fac_ans = 1.0;
    for(int i=1;i<=n;i++) fac_ans *= i;
    return fac_ans;
}

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 100000000;


int main() {
    int h,w,k;
    cin >> h >> w >> k;
    string c[h];
    rep(i,h) cin >> c[i];

    int64_t ans=0,cnt=0;
    for(int tmp1 = 0; tmp1 < 1<<h; tmp1++){
        for(int tmp2 = 0; tmp2 < 1<<w; tmp2++){
            rep(i,h){
                rep(j,w){
                    if((tmp1&1<<i) || (tmp2&1<<j)) continue;
                    if(c[i][j] == '#') cnt++;
                }
            }
            if(cnt==k) ans++;
            cnt=0;
        }
    }

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

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().Int();
            var r = ReadSplit();
            var d = new Dictionary<long, long>();
            for (int i = 0; i < n; i++)
            {
                if (d.ContainsKey(r[i].Int()))
                {
                    d[r[i].Int()]++;
                }
                else
                {
                    d.Add(r[i].Int(), 1);
                }
            }
            long sum = 0;
            foreach (var item in d)
            {
                sum += d[item.Key] * (d[item.Key] - 1) / 2;
            }
            for (int i = 0; i < n; i++)
            {
                var t = r[i].Int();
                long ans = sum;
                if (d.ContainsKey(t))
                {
                    ans = sum - (d[t] * (d[t] - 1) / 2);
                    ans += (d[t] - 1) * (d[t] - 2) / 2;
                }
                Write(ans);
            }
            Read();
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=0,wa=0;

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

    map<int,int> pena;
    vector<bool> ac(n+1,false);

    rep(i,m){
        string si;
        int p;

        cin >>p>>si;
        if(si =="AC"){
            ac[p]=true;
        }else{
            if(ac[p] == false)pena[p]++;
        }
    }

    rep1(i,1,n+1){
        if(ac[i]==true)ans++;
        else pena[i]=0;
    }

    for(auto p:pena){
        wa += p.se;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<" "<<wa<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 4992
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	ll n; cin >> n;
	rep(i, 1, 3500)rep(j, 1, 3500) {
		ll a = n * i * j;
		ll b = 4 * i * j - n * i - n * j;
		if (a == 0 || b <= 0) continue;
		if (a % b == 0) {
			cout << i << " " << j << " " << a / b << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1

if A_dict.get(0, 0) > 0:
    ans = 0
else:
    for val in A_dict:
        ans *= val ** A_dict[val]

        if ans > limit:
            ans = -1
            break

print(ans)


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

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

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void){
  long long a,b,c;
  scanf("%lld%lld%lld",&a,&b,&c);
  if((c-a-b>0)&&((c-a-b)*(c-a-b)>4*a*b)) printf("Yes");
  else printf("No");

    return 0;
  }

Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

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

ll fact[100010], ifact[100010];

ll pow(ll a, ll k) {
	if (k == 0) return 1;
	ll res = pow(a, k / 2);
	res = res * res % MOD;  //k:偶数 a^k = a^(k/2)*a^(k/2)
	if (k & 1) res = res * a % MOD; //k:奇数 a^k = a^(k/2) * a^(k/2) * a
	return res;
}

ll inv(ll a) {
	return pow(a, MOD - 2); //b^-1 = a^m-2
}

ll C(ll n, ll r) { //nCr
	if (n < 0 || r < 0 || r > n) return 0;
	if (r > n / 2) r = n - r;
	return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD; //n! / r!(n-r)!
}

int main() {
	ll n;
	cin >> n;
	int N = n + 1;

	fact[0] = ifact[0] = 1;
	REP(i, 1, 100010) {
		fact[i] = (fact[i - 1] * i) % MOD; //n!
		ifact[i] = inv(fact[i]); //逆元
	}

	int d = -1;
	int used[100010];
	fill(all(used), -1);

	rep(i, N) {
		int a;
		cin >> a;
		if (used[a] != -1) { //重複した数字の間隔
			d = i - used[a];
		}
		used[a] = i;
	}

	rep(i, N) {
		cout << (C(N, i + 1) - C(N - d - 1, i) + MOD) % MOD << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

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

	int a[10];
	fill(a, a+10, 0);
	for(int i = 0; i < 3; i++) {
		int n;
		cin >> n; n--;
		a[n]++;
	} 
	
	if(a[4] >= 2 && a[6] >= 1) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	char ch1,ch2;
	getchar();
	int sum=0;
	for(int i=1;i<=n;i++){
		ch2=getchar();
		if(ch2!=ch1)
		sum++;
		ch1=ch2;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,c,k,m,i,p;
	scanf("%d %d",&n,&c);
	p=0;
	for(i=0;i<c;i++){
		scanf("%d",&k);
		p+=k;
	}
	if(p/(n+1)>0){
		if(p%(n+1)==0)	printf("%d\n",p/(n+1));
		else	printf("%d\n",p/(n+1)+1);
	}
	else	printf("1\n");
	return 0;
}



Measured memory_bytes: 2732
def main():
    n,m=map(int,input().split())
    cnt=[1]*n
    res=[0]*n
    res[0]=1
    for i in range(m):
        x,y=map(int,input().split())
        if res[x-1]==1:
            res[y-1]=1
            if cnt[x-1]==1:
                res[x-1]=0
        cnt[x-1]-=1
        cnt[y-1]+=1
    print(sum(res))
if __name__=="__main__":
    main()

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

#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()
#define endl '\n'
#define left aba
#define right abc

using namespace std;

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

const int N=1003, MOD=(int)1e9+7;

int h, w;

string a[N];
int dp[N][N];

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

    cin>>h>>w;

    for(int i=0; i<h; ++i) {
        cin>>a[i];
    }

    for(int i=1; i<w && a[0][i]=='.'; ++i) dp[0][i]=1;
    for(int i=1; i<h && a[i][0]=='.'; ++i) dp[i][0]=1;

    for(int i=1; i<h; ++i) {
        for(int j=1; j<w; ++j) {
            if(a[i][j]=='#') continue;

            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            if(dp[i][j]>=MOD) dp[i][j]-=MOD;
        }
    }

    cout<<dp[h-1][w-1]<<endl;

    //cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<"s"<<'\n';
    return 0;
}


Measured memory_bytes: 5248
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
bool cmp(int a,int b){
	return a>b;
}
int main() {
	char a[100],b[100];
	scanf("%s%s",a,b);
	sort(a,a+strlen(a));
	sort(b,b+strlen(b),cmp);
	if(strcmp(a,b)<0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int[] line1 = ReadIntArray();
    int N = line1[0], M = line1[1];
    int[] count = new int[M];
    for (int i = 0; i < N; i++) {
      int[] line2 = ReadIntArray();
      foreach (var j in line2.Skip(1)) {
        count[j-1]++;
      }
    }
    Console.WriteLine(count.Count(i => i == N));
  }

  private static string ReadStr() { return Console.ReadLine(); }
  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  private static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 13396
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K_) = Slice2<long>();
            K = K_;
            dp = Enumerable.Repeat(-1.0D, (int)Max(N, K) + 1).ToArray();
            var ans = 0D;
            for (var i = 1; i <= N; ++i)
                ans += dfs(i);
            WriteLine($"{ans / N:F10}");

        }
        static double[] dp;
        static long K;
        static double dfs(long n)
        {
            if (K <= n) return 1;
            if (0 <= dp[n]) return dp[n];
            return dp[n] = dfs(n * 2) / 2.0;
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 28784
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main() {

	int a, b, c, d;

	cin >> a >> b >> c >> d;
	if (a <= c) {
		if (b < c)cout << 0 << endl;
		else {
			if (b <= d)cout << b - c << endl;
			else cout << d - c << endl;
		}
	}
	else {
		if (d < a)cout << 0 << endl;
		else {
			if (d <= b)cout << d - a << endl;
			else cout << b - a << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    dic_Lg = {}
    for i in range(N):
        x = i - A[i]
        if x in dic_Lg:
            dic_Lg[x].append(i)
        else:
            dic_Lg[x]=[i]
    ret = 0
    for i in range(N):
        y = i+A[i]
        if not y in dic_Lg:
            continue
        arr = dic_Lg[y]
        r = bisect_right(arr, i)    # 5が入るべき境目のうち最も右側の境目を返す
        ret += len(arr)-r
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 60888
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == 'A')
			a++;
		else
			b++;
	}
	if (a == 0 || b == 0)
		cout << "No";
	else
		cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> dp(n);
    for(int i=0;i<n;i++) cin >> a[i];

    for(int i=0;i<n;i++) dp[a[i]-1] = i+1;
    
    for(int i=0;i<n;i++) cout << dp[i] << endl;

    return 0;
}


Measured memory_bytes: 1664
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad
import Control.Monad.ST

solve :: Int -> Int
solve 0 = 1
solve n = mulMod 2 $ solve (n-1)
    where
        mulMod a b = (a * b) `rem` (10^9+7)

search :: VU.Vector Int -> Int -> Bool 
search vec n = runST $ do
    (vec' :: VUM.STVector s Int) <- VUM.replicate n 0
    forM_ [0..n-1] $ \i -> do
        let v = vec VU.! i
        VUM.modify vec' (+1) v 
    vec'' <- VU.unsafeFreeze vec'
    let v = VU.zip (VU.fromList [0..n-1]) vec''
    if odd n
        then do
            let step b (i,e) = if i == 0 then (e == 1) && b else if even i then (e == 2) && b else (e == 0) && b
            return $ VU.foldl' step True v
        else do
            let step b (i,e) = if odd i then (e == 2) && b else (e == 0) && b
            return $ VU.foldl' step True v

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ 
        if search xs n
            then solve (n `quot` 2)
            else 0

Measured memory_bytes: 7036
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int ans = Math.max(0, A - 2 * B);
        System.out.println(ans);
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int num[200005];
int t[200005];
int a[200005];
map<int, int> mp;
map<int, int> mpb;
int pop = 0;
int n;
int len;
int lowbit(int x)
{
        return x & (-x); //右起第一个1的位置为第k个 返回值则为2^(k-1)
}
void update(int x, int p) //更新第x 的值
{
        while (x <= len)
        {
                t[x] += p;
                x += lowbit(x); //不断找到自己的祖先 更新值
        }
        return;
}
int sum(int k)//前k个数的和
{
        int ans = 0;
        while (k > 0)
        {
                ans += t[k];
                k -= lowbit(k);
        }
        return ans;
}
int ask(int l, int r) //求l-r区间和
{
        return sum(r) - sum(l - 1);
}
int main()
{
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
                a[i] = num[i];
        }
        sort(num + 1, num + 1 + n);
        len = unique(num + 1, num + 1 + n) - num - 1;
        for (int i = 1; i <= len; i++)
        {
                mp[num[i]] = ++pop;
                mpb[pop] = num[i];
        }
        //cout<<len<<endl;
        int aim = (n - 1) / 2 + 1;
        for (int i = 1; i <= n; i++)
        {
                update(mp[a[i]], 1);
        }
        for (int i = 1; i <= n; i++)
        {
                update(mp[a[i]], -1);
                int l = 0, r = 2 * len;
                int mid;
                while (l < r - 1)
                {
                        mid = (l + r) >> 1;
                        if (ask(1, mid) >= aim)
                        {
                                r = mid;
                        }
                        else
                        {
                                l = mid;
                        }
                }
                cout << mpb[r] << endl;
                update(mp[a[i]], 1);
        }
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ll h, cnt = 0;
  cin >> h;
  while (h > 0) {
    ++cnt;
    h /= 2;
  }
  cout << setprecision(20) << pow(2, cnt) - 1 << endl;
  return 0;
}


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

int main(){
	int A, B;
	cin >> A >> B;
	int t8 = 0, t10 = 0;
	int x = 10;
	while (t8<=A && t10 <=B) {
		t8 = x*8/100; t10 = x/10;
		if (t8==A && t10==B) {
			cout << x << endl;
			return 0;
		}
		x++;
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3612
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> w = new HashSet<>();
        String[] ww = new String[n];
        for (int i = 0; i < n; i++) {
            ww[i] = sc.next();
        }
        w.add(ww[0]);
        for (int i = 0; i < n - 1; i++) {
            String tmp1 = ww[i].substring(ww[i].length() - 1, ww[i].length());
            String tmp2 = ww[i + 1].substring(0, 1);
            if(!tmp1.equals(tmp2)) {
                System.out.println("No");
                return;
            }
            w.add(ww[i + 1]);
        }
        if(w.size() == n) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 35872
#include<stdio.h>
int main(){
	int a[3],b,i,j;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<3;i++){
		for(j=i;j<3;j++){
			if(a[i]>a[j]){
				b=a[i];
				a[i]=a[j];
				a[j]=b;
			}
		}
	}
	for(i=0;i<3;i++){
		if(i==2){
			printf("%d",a[i]);
		}
		else{
			printf("%d ",a[i]);
		}	
	}
	printf("\n");
return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define vpll        vector<pair<ll,ll>>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int n;cin>>n;
    int score[n];
    int sum=0;
    int mi=1000;
    rep(i,0,n){
        cin>>score[i];
        sum+=score[i];
        if(score[i]%10!=0){
            mi=min(mi,score[i]);
        }
    }
    if(sum%10!=0){
        cout<<sum;
    }
    else if(mi==1000){
        cout<<0;
    }
    else{
        cout<<sum-mi;
    }


}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
<?php

$s = trim(fgets(STDIN));
$count = 0;
$s =  str_split($s);
sort($s);




if($s[0] == $s[1] && $s[2] == $s[3] && $s[0] != $s[3]){
    echo "Yes";
}else{
    echo "No";
}




Measured memory_bytes: 4604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 double D = sc.nextInt();
		 double T = sc.nextDouble();
		 double S = sc.nextInt();
		 double x = D/S;
		 if(T >= x) {
			 System.out.println("Yes");
		 }else {
			 System.out.println("No");
		 }
	}
}

Measured memory_bytes: 37344
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	std::vector<vector<int>> v;
	for(int i=0;i<n;i++){
	     int a,b,c;
	     cin >> a >> b >> c;
	     v.push_back({a,b,c});
	}
	int dp[n+1][3];
	dp[0][0]=v[0][0];
	dp[0][1]=v[0][1];
	dp[0][2]=v[0][2];
	for(int i=1;i<n;i++){
	     for(int x=0;x<3;x++){
	          int maxa = 0;
               for(int y=0;y<3;y++){
                    if(y==x){
                         continue;
                    }
	               maxa=max(maxa,dp[i-1][y]+v[i][x]);
               }
               dp[i][x] = maxa;
	     }
	}
// 	for(int i=0;i<n;i++){
// 	     for(int j=0;j<3;j++){
// 	          cout << dp[i][j] << " ";
// 	     }
// 	     cout  << endl;
// 	}
	cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	return 0;
}


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

const int N = 100010;
vector<int> G[N];
vector<int> C(N);

int n, color;
map<int, pair<int, int>> mp1; // {index, {v1, v2}}
map<pair<int, int>, int> mp2; // {{v1, v2}, color}


void dfs(int now, int back_vertex, int c){
    for(int i = 0; i < int(G[now].size()); i++){
        int to = G[now][i];
        if(to == back_vertex) continue;
        
        int mi = min(now, to);
        int ma = max(now, to);

        c++;
        if(c > color) c = 1;
        mp2[make_pair(mi, ma)] = c;
        dfs(to, now, c);
    }
}

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

    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        mp1[i] = make_pair(a, b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    color = 0;
    for(int i = 0; i < n; i++){
        color = max(color, int(G[i].size()));
    }

    dfs(0, -1, 0);

    cout << color << endl;
    for(auto x : mp1){
        cout << mp2[make_pair(x.second.first, x.second.second)] << endl;
    }

    return 0;
}

Measured memory_bytes: 19456
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int h, w; cin >> h >> w;
	rep(i, h) rep(j, w){
		string s; cin >> s;
		if(s == "snuke"){
			cout << char('A' + j) << (i + 1) << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



int main() {
	int N; cin >> N;
	map<string, ll> mp_st;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		string st;
		cin >> st;
		sort(st.begin(), st.end());
		if (mp_st.find(st) == mp_st.end()) {
			mp_st.insert(make_pair(st, 1));
		}
		else mp_st[st]++;

	}
	for (auto run = mp_st.begin(); run != mp_st.end(); run++) {
		ans += run->second * (run->second - 1) / 2;
	}
	cout << ans << endl;





	return 0;
}


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

int main(int argc, char** argv) {
  std::string s;
  std::cin >> s;
  int n = s.size();
  int cnt {};
  for (auto i = 0;i < n/2;++i) {
    if (s[i] != s[n-i-1]) ++cnt;
  }
  std::cout << cnt << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	string a;
	int sum=0;
	cin>>a;
	sort(a.begin(),a.end());
	for (int i = 0 ; i < a.size(); i++){
		if (a[i]=='x')	break;
		sum+=100;
	}
	cout<<sum+700;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
u, v = 0, 0
for i in range(n):
    if a[i] > b[i]:
        u += a[i] - b[i]
    elif a[i] < b[i]:
        v += (b[i] - a[i]) // 2
print("Yes" if v >= u else "No")


Measured memory_bytes: 4596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      String[] line = br.readLine().split(" ");

      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = Integer.parseInt(line[i]);
      }

      insertionSort(a, n);
    }
  }

  public static void insertionSort(int a[], int max) {
    StringBuilder line = new StringBuilder(a.length*4);
    for (int i=0,j=0,v=0; i < max; i++) {
      for( j = i-1, v = a[i]; j>=0 && a[j]>v; j-- ) {
        a[j+1] = a[j];
      }
      a[j+1] = v;
      dispIntArray(a,line);
      line.setLength(0);
    }
  }
  public static void dispIntArray(int a[],StringBuilder line) {
    for (int i=0, max = a.length-1; i < max; i++) {
     line.append(a[i] + " ");
    }
    System.out.println( line.append(a[a.length-1]) );
  }
}


Measured memory_bytes: 27656
#include<iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "a > b" << endl;
	} else if (a < b) {
		cout << "a < b" << endl;
	} else {
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#bid DP
N, M = map(int, input().split())

g = [[] for i in range(N)] #隣接リスト

for i in range(M):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

memo = {}
All_used = (1 << N) -1

def dfs(v, used):
    if used == All_used:
        return 1
    
    key = (v, used)
    if key in memo:
        return memo[key]
    
    ans = 0
    for u in g[v]:
        if (used >> u) & 1 == 1:
            continue
        
        used ^= (1 << u)
        ans += dfs(u, used)
        used ^= (1 << u)
        
    memo[key] = ans
    return ans

print(dfs(0, 1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
// https://qiita.com/ta-ka/items/a023a11efe17ab097433
struct Edge {
    ll to, cost;
};


class Dijkstra {
    ll vector_count;

    vector<ll> distances;
    vector<vector<Edge>> edges;

public:
    Dijkstra(ll n) {
        vector_count = n;
        distances.resize(n, INF);
        edges.resize(n);
    }

    void insertTowWay(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
        edges[to].push_back({from, cost});
    }

    void insert(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
    }

    void dijkstra(ll k) {
        distances[k] = 0;  // 始点sへの最短距離は0

        priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
        que.push(P(0, k));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
            if (distances[v] < p.first) {
                continue;
            }
            for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
                if (distances[e.to] > distances[v] + e.cost) {
                    distances[e.to] = distances[v] + e.cost;
                    que.push(P(distances[e.to], e.to));
                }
            }
        }
    }

    ll distance(ll to) {
        return distances[to];
    }

};

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

    Dijkstra dijkstra(n);

    rep(i, n) {
        if (i == 0) continue;
        dijkstra.insert(i, i - 1, 0);
    }

    rep(_, m) {
        int l, r;
        ll c;
        cin >> l >> r >> c;
        l--;
        r--;
        dijkstra.insert(l, r, c);
    }
    dijkstra.dijkstra(0);

    ll now = dijkstra.distance(n - 1);
    ll ans = now >= INF ? -1 : now;
    cout << ans << endl;
}


Measured memory_bytes: 12976
#include <bits/stdc++.h>
#define ll        long long
#define endl      "\n"
#define loop(n)   for(ll i=0;i<n;i++)

using namespace std;
int main(){
    ll n,ac=0,wa=0,tle=0,re=0;
    cin>>n;
    loop(n){
        string s;
        cin>>s;
        if(s=="AC")++ac;
        else if(s=="WA")++wa;
        else if(s=="TLE")++tle;
        else if(s=="RE")++re;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl; 
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3612
N=int(input())
V=list(map(int,input().split()))
A=[0]*(10**5+1)
B=[0]*(10**5+1)
for i in range(N):
  if(i%2==0):
    A[V[i]]+=1
  else:
    B[V[i]]+=1
MA=0
NA=A[0]
MB=0
NB=B[0]
for i in range(10**5+1):
  if(A[i]>=NA):
    NA=A[i]
    MA=i
  if(B[i]>=NB):
    NB=B[i]
    MB=i
A.sort(reverse=True)
B.sort(reverse=True)
if(MA!=MB):
  print(N-NA-NB)
else:
  print(min(N-A[0]-B[1],N-A[1]-B[0]))



Measured memory_bytes: 14404
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
par = [i for i in range(N+1)]
rank = [0] * (N+1)
 
def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]
 
def union(x,y):
    x = find(x)
    y = find(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
 
def check_same(x,y):
    return find(x) == find(y)
 
for _ in range(M):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    union(x,y)
ans = 0
for i in range(1,N+1):
    if find(i) == find(P[i-1]):
        ans += 1
print(ans)

Measured memory_bytes: 13812
import java.util.Scanner;
public class Main {

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

        int n=scan.nextInt();
        int []t=new int[n];
        int sum=0;
        for(int i=0;i<n;i++){
            t[i]=scan.nextInt();
            sum+=t[i];
        }
        int m=scan.nextInt();
        int p,x;
        int temp;
        for(int i=0;i<m;i++){
            p=scan.nextInt();
            x=scan.nextInt();
            temp=sum;
            temp-=t[p-1];
            temp+=x;


            System.out.println(temp);
        }

    }
}


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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

const int maxn = 200005;
vi g[maxn];
int par[maxn];
void dfs(int u,int fa) {
    for(int v:g[u]) {
        if(v==fa) continue;
        par[v]=u;
        dfs(v,u);
    }
}
int main() {
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<n;++i) {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;++i) {
        int x=i,y=par[i];
        int l,r;
        if(i>par[i]) {
            l=y+1,r=n;
        } else {
            l=1,r=y-1;
        }
        ans+=1ll*(r-x+1)*(x-l+1);
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main() {
    int N; cin>>N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin>>A[i];

    for (int i=0;i<N;i++) {
        int v = A[i];
        int j = i - 1;
        while (j>=0 && A[j]>v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;

        for (int i=0;i<N;i++) {
            cout << A[i];
            if (i<N-1) cout << ' ';
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3104