akhauriyash/Code-Regression huggingface dataset:
class UnionFindTree:
    """
        Disjoint set data structure
        Union-Find tree
        complexity:
            init: O(n)
            find, unite, same: O(alpha(n))
    """
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


class Kruskal:
    """
        Kruskal's algorithm: find Minimum Spanning Tree
        complexity:
            O(E logV)
    """
    def __init__(self, V, E, start=0, INF=10**9):
        """
        :param V: the number of vertices
        :param E:  adjacency list (undirected graph)
        :param start:
        :param INF:
        """
        self.kruskal(V, E)

    def kruskal(self, V, E):
        edges = []
        for v1 in range(V):
            for v2, cost in E[v1]:
                if v1 < v2:
                    edges.append((cost, v1, v2))
        edges.sort(reverse=True)
        self.mincost = 0
        self.min_spanning_tree = []
        uf = UnionFindTree(V)
        while len(self.min_spanning_tree) < V - 1:
            cost, v1, v2 = edges.pop()
            if not uf.same(v1, v2):
                self.mincost += cost
                uf.unite(v1, v2)
                self.min_spanning_tree.append((v1, v2, cost))

    def min_cost(self):
        return self.mincost

    def get_min_spanning_tree(self):
        return sorted(self.min_spanning_tree)


V = int(input())
edges = [[] for _ in range(V)]
for i in range(V):
    for j, d in enumerate(map(int, input().split())):
        if d != -1:
            edges[i].append((j, d))
mst = Kruskal(V, edges)
print(mst.min_cost())


Measured memory_bytes: 6672
# coding: utf-8
# Your code here!
h,w=map(int,input().split())
s=[]
ans=''
for i in range(h):
    s.append(list(input()))
for j in range(h):
    for l in range(w):
            ans+=s[j][l]
    for k in range(2):
        print(ans)
    ans=''

Measured memory_bytes: 3060
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	ws := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&ws[i])
		sum += ws[i]
	}

	res := 1000000
	t := 0
	for i := 0; i < n; i++ {
		t += ws[i]
		d := int(math.Abs(float64(t - (sum - t))))
		if d < res {
			res = d
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n,t);V a(n);VECCIN(a);
  //最大利益の計算
  int minnum = INF;
  int maxdif = -INF;
  REP(i,n){
    minnum=min(minnum,a[i]);
    maxdif = max(maxdif,a[i]-minnum); 
  }
  ll profits = 1LL * maxdif * t / 2;

  vector<P> vec;

  P minnum2 = mp(INF,-1);
  REP(i,n){
    if(minnum2.first > a[i]){
      minnum2.first = a[i];
      minnum2.second = i;
    }
    if(a[i]-minnum2.first == maxdif)vec.pb(mp(minnum2.second,i));
  }
  // FOREACH(xx,vec)cout<<xx.first<<" "<<xx.second<<endl;
  COUT(vec.size());


  return 0;
}


Measured memory_bytes: 1276
n,k=list(map(int, input("").split()))
d=[]
a=[]
t=[]
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int, input("").split())))
for i in range(n):
    t.append(True)
for i in range(k):
    for j in a[i]:
        if t[j-1]:
            t[j-1]=False
out=0
for i in t:
    if i:
        out+=1
print(out)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
long long n2,n1;
int f(long long m)
{
	long long d=m-n1;
	d=max(1LL*0,d);
	long long f=n1,s=n2;
	s-=2*d;
	if(s>=2*m)
	return 1;
	return 0;
}
int main()
{
	long long int n,i,sum=0,p=1,ans=1,d;
	scanf("%lld %lld",&n1,&n2);
	long long start=0,end=1e15,mid;
	while(end-start>1)
	{
		//printf("%lld",mid);
		mid=(start+end)/2;
		if(f(mid))
		{
			start=mid;
		}
		else
		end=mid-1;
	}
	if(f(end))
	printf("%lld",end);
	else if(f(mid))
	printf("%lld",mid);
	else
	printf("%lld",start);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v;
    rep(i,n){
        int enter;
        cin>>enter;
        v.push_back(enter);
    }
    sort(v.begin(),v.end());
    int a=0;
    int b=0;
    rep(i,n){
        if(i%2==0) a+=v[i];
        else b+=v[i];
    }
    cout<<abs(a-b);
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,(input().split()))
h = list(map(int,input().split()))
H = [0]*N
for i in range(1,N):
    if i == 1:
        H[i] = abs(h[1]-h[0])
    else:
        Min = 1000000000
        start = max((i-K),0)
        for j in range(start,i):
            if Min > H[j]+abs(h[i]-h[j]):
                Min = H[j]+abs(h[i]-h[j])
        H[i] = Min
print(H[N-1])

Measured memory_bytes: 52576
#include <iostream>
#include <unordered_set>

using namespace std;

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

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N - i; ++j) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << ' ' << j << ' ' << N - i - j << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#=
B:
- Julia version: 0.5.2
- Author: abap
- Date: 2019-12-22
=#
N = parse(readline())
A,B = split(readline())
ans = []
for (i,j) in zip(A,B)
	push!(ans,i)
	push!(ans,j)

end

for k in ans
	print(k)
end


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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll a[300];
double dp[301][301][301];
ll N;

double calcdp(VL n) {
    if(dp[n[3]][n[2]][n[1]]) return dp[n[3]][n[2]][n[1]];
    if(n[0] == N) return 0;
    double &res = dp[n[3]][n[2]][n[1]];
    double p = 0, tmp = 0;
    FOR(i, 1, 4) {
        if(n[i]) {
            p += (double)n[i] / N;
            VL next(n);
            next[i]--;
            next[i - 1]++;
            tmp += (double)n[i] / N * calcdp(next);
        }
    }
    return res = (1.0 + tmp) / p;
}

signed main() {
    cin >> N;
    VL num(4);
    REP(i, N) num[IN()]++;
    double ans = calcdp(num);
    cout << scientific << setprecision(12) << ans << "\n";
}


Measured memory_bytes: 426496
use std::io::*;
use std::str::*;

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

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let n = read::<usize>(s).unwrap();
    let x = read::<usize>(s).unwrap();
    let t = read::<usize>(s).unwrap();

	let tt = if n % x != 0 {
	((n / x)+1) * t 
		}
	else {
	 (n / x) * t
	};
	println!("{}", tt);
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long double n;
    int k,tmp_k;
    cin>>n>>k;
    tmp_k=k;
    long double sum=0;
    int tmp=0;
    while (tmp_k!=1) {
        tmp++;
        tmp_k/=2;
    }
    tmp++;
    for (long double i=1;i<=n;i++) {
        if (i<k) {
            if (i*pow(2,tmp-1)>=k) {
                tmp--;
            }
            sum+=pow(0.5,tmp);
        } else {
            sum+=1.0;
        }
    }
    sum*=1/n;
    printf("%.12Lf",sum);
    cout<<endl;
}

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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,m,k,i,j,x;
	cin >> n >> m >> k;
	vector<int> a(n+1),b(m+1);
	a[0]=0; b[0]=0;
	for(i=0;i<n;i++)
	{
		cin >> x;
		a[i+1]= a[i]+x;
	}
	for(i=0;i<m;i++)
	{
		cin >> x;
		b[i+1]= b[i]+x;
	}
	int ans=INT_MIN;

	for(i=0;i<=m;i++)
	{
		if(b[i]>k)
			break;
		x = k-b[i];
		j = upper_bound(a.begin(),a.end(),x)-a.begin()-1;
		ans = max(i+j,ans);
	}
	cout << ans << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


struct Edge {
    int to, id;
    Edge(int to, int id) :to(to), id(id) {}
};

vector<Edge> adj[55];

// now から goal までに含まれる辺の id を帰るときに edges_id に格納する
bool dfs(int now, int goal, int from, vector<int> & edges_id) {
    if (now == goal) return true;
    for(auto edge: adj[now]) {
        if (edge.to == from) continue;
        if (dfs(edge.to, goal, now, edges_id)) { edges_id.push_back(edge.id); return true; }
    }
    return false;
}


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

    int n; cin >> n;
    rep(i, n-1) {
        int a, b; cin >> a >> b; --a; --b;
        adj[a].push_back(Edge(b, i));
        adj[b].push_back(Edge(a, i));
    }

    int m; cin >> m;
    // u[i]-v[i] 上の辺の id を bit で管理する．
    vector<ll> bit_edges(m, 0);
    rep(i, m) {
        int a, b; cin >> a >> b; --a; --b;
        vector<int> edges_id;
        dfs(a, b, -1, edges_id);
        for(auto id: edges_id) bit_edges[i] |= 1LL<<id;
    }

    ll ans = 0;
    rep(bit, 1<<m) {
        //　bit で立ってる制約 u-v について，それら全てのパス上にある辺の id を mask でビット管理する
        ll mask = 0;
        rep(i, m) if (bit>>i&1) mask |= bit_edges[i];
        int white = __builtin_popcountll(mask);
        ll val = 1LL<<(n-1-white);

        if (__builtin_popcount(bit)%2==0) ans += val;
        else ans -= val;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
from collections import defaultdict
import math

A, B, H, M = map(int, input().split())
x1 = A * math.cos(math.pi/180*(90-360*H/12-30*M/60))
y1 = A * math.sin(math.pi/180*(90-360*H/12-30*M/60))
x2 = B * math.cos(math.pi/180*(90-360*M/60))
y2 = B * math.sin(math.pi/180*(90-360*M/60))
print(((x1-x2)**2+(y1-y2)**2)**0.5)

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

int main()
{
    int n,d,ans=0;
    cin>>n>>d;

    for(int i=1;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;

        if( sqrt(x*x+y*y) <= d )
            ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(){
	int N,i,j;
	long a[100000],b[100000],c[100000],dp[100000][3] = {};

	cin >> N ;
	myfor(i,N){
		cin >> a[i]>>b[i]>>c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0]; 
	myforFL(i,1,N){
		dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
		dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
		dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
	}
	cout << max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]) << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+1;
const ll p=1e9+7;
int a[10];
int main()
{
	int n;
	cin>>n;
	memset(a,0,sizeof a);
	for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        for(int j=8;j>=0;j--)
        if(x>=400*j){a[j]++;break;}
    }
    int ans=0;
    for(int i=0;i<8;i++)ans+=(a[i]>0);
    cout<<max(1,ans)<<' '<<ans+a[8];
	return 0;
}


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

void solve(std::string s, long long K){
    vector<string> vec;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 1; j <= K; ++j){
            string ss = s.substr(i, j);
            vec.push_back(ss);
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    cout << vec[K-1] << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    long long K;
    scanf("%lld",&K);
    solve(s, K);
    return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <iostream>
#include <string>
#include <functional>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pci pair<char,int>
#define pdd pair<double,double>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pdi pair<double,int>
#define pdd pair<double,double>
#define mod 1000000007
#define mod1 1000000009
#define mod2 1000000021
#define INF 987564231
#define MAX 2000001
long double PI = 3.141592653589793238462643383279502884197;
using namespace std;

/* 🐣🐥 */
char A[200001], B[200001];
int main() {
	int n, m, t, r, c;
	scanf("%d %d %d %d %d", &n, &m, &t, &r, &c);
	scanf("%s %s", A, B);
	int R = c, L = 0;
	for (int i = 0; i < 2*t; i++){
		if (i % 2){
			if (B[i / 2] == 'L' && R > 1) R--;
		}
		else {
			if (A[i/2] == 'L'){
				if (R == 1 && L){
					L--;
					R++;
				}
			}
			else if(A[i / 2] == 'R'){
				R++;
				if (R == m + 1) return !printf("NO");
			}
		}
	}
	R = c, L = 0;
	for (int i = 0; i < 2 * t; i++){
		if (i % 2){
			if (B[i / 2] == 'R' && R < m) R++;
		}
		else {
			if (A[i / 2] == 'R'){
				if (R == m && L){
					L--;
					R--;
				}
			}
			else if (A[i / 2] == 'L'){
				R--;
				if (R == 0) return !printf("NO");
			}
		}
	}
	//////////////
	R = r, L = 0;
	for (int i = 0; i < 2 * t; i++){
		if (i % 2){
			if (B[i / 2] == 'U' && R > 1) R--;
		}
		else {
			if (A[i / 2] == 'U'){
				if (R == 1 && L){
					L--;
					R++;
				}
			}
			else if (A[i / 2] == 'D'){
				R++;
				if (R == n + 1) return !printf("NO");
			}
		}
	}
	R = r, L = 0;
	for (int i = 0; i < 2 * t; i++){
		if (i % 2){
			if (B[i / 2] == 'D' && R < n) R++;
		}
		else {
			if (A[i / 2] == 'D'){
				if (R == n && L){
					L--;
					R--;
				}
			}
			else if (A[i / 2] == 'U'){
				R--;
				if (R == 0) return !printf("NO");
			}
		}
	}
	printf("YES");

	return 0;
}

Measured memory_bytes: 640
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f

let rec solve v x y = if x > y then v else solve (v+1) (2*x) y

let () =
  let x = read_int () in let y = read_int () in
  solve 0 x y |> printf "%d\n"


Measured memory_bytes: 384
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let result = U.foldr' (\x h -> case h of
                            Just h' | x <= h'+1 -> Just $! min h' x
                            _ -> Nothing
                        ) (Just $ 10^9) xs
  case result of
    Just _ -> putStrLn "Yes"
    Nothing -> putStrLn "No"


Measured memory_bytes: 3964
#include <iostream>
#include <iterator>
#include <list>

int main() {
  int q;
  std::cin >> q;
  std::list<int> a;
  std::list<int>::iterator cur = a.begin();

  for (int i = 0; i < q; ++i) {
    int c;
    std::cin >> c;
    int x, d;
    switch (c) {
    case 0:
      std::cin >> x;
      cur = a.insert(cur, x);
      break;
    case 1:
      std::cin >> d;
      cur = std::next(cur, d);
      break;
    case 2:
      cur = a.erase(cur);
      break;
    }
  }

  for (int x : a) {
    std::cout << x << std::endl;
  }
}



Measured memory_bytes: 18656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _      << " " <<
#define all(X) (X).begin(), (X).end()
#define Pint   pair<int, int>
#define Pll    pair<ll, ll>
#define Tint   tuple<int, int, int>
#define Tll    tuple<ll, ll, ll>
#define PI     3.141592653589793

int cnt = 0, k;
ll ans = -1;

void dfs(ll n, int f, int at, int d) {
    n = n * 10 + f;
    if (at == d) {
        cnt++;
        //cerr << cnt _ n << endl;
        if (cnt == k) ans = n;
        return;
    }
    if (f != 0 && ans == -1) dfs(n, f - 1, at + 1, d);
    if (ans == -1) dfs(n, f, at + 1, d);
    if (f != 9 && ans == -1) dfs(n, f + 1, at + 1, d);
}

int main() {
    cin >> k;
    for (int i = 1; i <= 10; i++) {
        for (int j = 1; j < 10; j++) {
            dfs(0, j, 1, i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = input()

cnt = {'a': 0, 'b': 0, 'c': 0}
for s in S:
    cnt[s] += 1

cnt_list = [[v, k] for k, v in cnt.items()]
cnt_list.sort(reverse=True)

if len(S) == 1:
    print("YES")
    exit(0)

if len(S) == 2:
    v, k = cnt_list[0]
    if v == 2:
        print("NO")
    else:
        print("YES")
    exit(0)

_, prev2 = cnt_list[0]
_, prev1 = cnt_list[1]
cnt[prev2] -= 1
cnt[prev1] -= 1
for i in range(2, len(S)):
    curr = 'a'
    for c in ('a', 'b', 'c'):
        if c != prev2 and c != prev1:
            curr = c
    if cnt[curr] > 0:
        cnt[curr] -= 1
        prev2 = prev1
        prev1 = curr
    else:
        print("NO")
        exit(0)

print("YES")


Measured memory_bytes: 41520
import itertools

n=int(input())
ls=[list(map(int,input().split(' '))) for i in range(n)]

def get_distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(1/2)

routes=list(itertools.permutations(range(n), n))
sum=0

for i in routes:
    for j in range(n-1):
        sum+=get_distance(ls[i[j]],ls[i[j+1]])
print(sum/len(routes))

Measured memory_bytes: 46832
S=input()
T=(",").join(S)
U=T.split(",")

ans="Yes"
for i in range(len(U)):
    if i%2==0:
        if U[i]=="L":
            ans="No"
            break
    else:
        if U[i]=="R":
            ans="No"
            break

print(ans)


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


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n - 1);
    int ans = 0;
    for (int i = 0; i < n - 1; i++) cin >> b.at(i);
    
    for (int i = 0; i < n - 1; i++){
        if (i == 0){
            a.at(i) = b.at(i);
            a.at(i + 1) = b.at(i);
        }else{
            a.at(i + 1) = b.at(i);
        }
    }
    
    for (int i = 0; i < n - 1; i++){
        if (a.at(i) > a.at(i + 1)){
            a.at(i) = a.at(i + 1);
        }
    }
    
    for (int i = 0; i < n; i++){
        ans = ans + a.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int A = sc.nextInt();
  int B = sc.nextInt();
  int C = sc.nextInt();
  if(C>=A && C<=B)System.out.println("Yes");
  else System.out.println("No");
}
}


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

int main(){
    int h,w;
    cin >> h >> w;
    char x[60][60] = {};
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> x[i][j];
        } 
    }
    for(int i = 1; i < h+1; i++){
        for(int j = 1; j < w+1; j++){
            if(x[i][j] == '#' && (x[i][j-1] == '.' && x[i][j+1] == '.' && x[i+1][j] == '.' && x[i-1][j] == '.')){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import  itertools
N=int(input())
XY=[]
for _ in range(N):
  x, y = map(int, input().split())
  XY.append([x,y])

D=np.zeros((N, N))
for i in range(N-1):
  xi, yi=XY[i][0], XY[i][1]
  for j in range(i+1, N):
    xj, yj=XY[j][0], XY[j][1]
    distance=np.sqrt((xi-xj)**2 + (yi-yj)**2)
    D[i][j]=distance
    D[j][i]=distance

ans=0
for l in itertools.permutations(range(N)):
  dis=0
  for i in range(N-1):
    dis+=D[l[i]][l[i+1]]
  ans+=dis
print(ans/np.math.factorial(N))



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
signed main(){
    int n;
    cin >> n;
    cout << "ABC" << n << '\n';
    return 0;   
}


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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	char al = a[a.length() - 1], bb = b[0], bl = b[b.length() - 1], cb = c[0];
	cout << (al == bb && bl == cb ? "YES" : "NO") << endl;
	return 0;
}

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

public class Main {
	int[][] a;
	int k;

	void addRect(int r1, int r2, int c1, int c2) {
//		System.err.println(r1 + " " + r2 + " " + c1 + " " + c2);
		if (r2 < 0) {
			addRect(r1 + 2 * k, r2 + 2 * k, c1, c2);
			return;
		}
		if (c2 < 0) {
			addRect(r1, r2, c1 + 2 * k, c2 + 2 * k);
			return;
		}
		if (r1 < 0) {
			addRect(0, r2, c1, c2);
			addRect(r1 + 2 * k, 2 * k,c1, c2);
			return;
		}
		if (c1 < 0) {
			addRect(r1, r2, 0, c2);
			addRect(r1, r2, c1 + 2 * k, 2 * k);
			return;
		}
		add(r1, c1, r2, c2);
	}

	void add(int r1, int c1, int r2, int c2) {
		a[r1][c1]++;
		a[r2][c1]--;
		a[r1][c2]--;
		a[r2][c2]++;
	}

	void solve() {
		int n = in.nextInt();
		k = in.nextInt();
		a = new int[2 * k + 1][2 * k + 1];
		for (int i = 0; i < n; i++) {
			int x = in.nextInt() % (2 * k);
			int y = in.nextInt() % (2 * k);
			char c = in.nextToken().charAt(0);
			if (c == 'B') {
				addRect(x - k + 1, x + 1, y - k + 1, y + 1);
				addRect(x - 2 * k + 1, x - k + 1, y - 2 * k + 1, y - k + 1);
			} else {
				addRect(x - k + 1, x + 1, y - 2 * k + 1, y - k + 1);
				addRect(x - 2 * k + 1, x - k + 1, y - k + 1, y + 1);
			}
		}
		int max = 0;
		for (int i = 0; i <= 2 * k; i++) {
			for (int j = 0; j <= 2 * k; j++) {
				if (i > 0){
					a[i][j] += a[i - 1][j];
				}
				if (j > 0) {
					a[i][j] += a[i][j - 1];
				}
				if (i > 0 && j > 0) {
					a[i][j] -= a[i - 1][j - 1];
				}
				max = Math.max(a[i][j], max);
			}
		}
		out.println(max);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 59820
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if(n.charAt(0) == n.charAt(2)){
            System.out.println("Yes");
            return;
        }
            System.out.println("No");
    }
}


Measured memory_bytes: 20692
def abc071_c():
    from collections import Counter
    _ = int(input())
    a = list(map(int, input().split()))
    a_count = Counter(a)
    ans = 1

    if len(a_count) == 1:
        print(a[0] ** 2)
    elif a_count.most_common()[1][1] < 2:
        print(0)
    else:
        tmp = 0
        for v in sorted(set(a), reverse=True):
            if tmp == 2:
                break
            if tmp == 0 and a_count[v] >= 4:
                ans = v**2
                break
            if a_count[v] >= 2:
                ans *= v
                tmp += 1
        print(ans)


abc071_c()

Measured memory_bytes: 21540
#include<stdio.h>

int main(){

    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b && b==c)
        printf("1\n");
    else if(a==c || a==b || b==c)
        printf("2\n");
    else
        printf("3\n");
	return 0;
}


Measured memory_bytes: 128
import java.io.PrintWriter
fun main(args: Array<String>) {
    val (X, Y, Z, K) = readLine()!!.split(" ").map(String::toInt)
    val A = readLine()!!.split(" ").map(String::toLong).sortedDescending()
    val B = readLine()!!.split(" ").map(String::toLong).sortedDescending()
    val C = readLine()!!.split(" ").map(String::toLong).sortedDescending()
    val ab = mutableListOf<Long>(0)
    for (i in 0 until X) {
        for (j in 0 until Y) {
            if ((i+1) * (j+1) > K) break
            ab.add(A[i] + B[j])
        }
    }
    ab.sortDescending()
    val li = mutableListOf<Long>(0)
    for (i in 0 until X * Y) {
        if (i + 1 > K) break
        for (j in 0 until Z) {
            if ((i+1) * (j+1) > K) break
            li.add(ab[i] + C[j])
        }
    }
    li.sortDescending()
    val pw = PrintWriter(System.out)
    for (i in 0 until K) {
        pw.println(li[i])
    }
    pw.flush()
}

Measured memory_bytes: 41984
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int k,t;
	int a[100];
	int high=0;
	int j;
	int igai=0;
	cin >> k >> t;
	for (int i = 0; i < t; i++){
		cin >> a[i];
		if (high < a[i]){
			high = a[i];
			j = i;
		}
	}
	for (int i = 0; i < t; i++){
		if (j != i){
			igai += a[i];
		}
	}
	if (high - 2 < igai){
		cout << "0" << endl;
	}
	else{
		cout << high - 1 - igai << endl;
	}
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int ans = 0;
    int now = 0;
    for(int i=0;i<n;i++){
    	if(a[i] > now){
    		ans += a[i] - now;
    		now = a[i];
    	}
    	else{
    		now = a[i];
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007 
int n,a,b,ans;
int qPow(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%MOD) if(y&1) res=1ll*res*x%MOD;
	return res; 
}
int C(int x,int y)
{
	int res=1;
	for(int i=x-y+1;i<=x;++i) res=1ll*res*i%MOD;
	for(int i=1;i<=y;++i) res=1ll*res*qPow(i,MOD-2)%MOD;
	return res; 
}
int main()
{
	scanf("%d %d %d",&n,&a,&b);ans=qPow(2,n)-1;
	ans=((ans-C(n,a))%MOD-C(n,b))%MOD;printf("%d\n",(ans+MOD)%MOD);
	return 0;
}

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

int main() {
	
	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	vector<ll> visit(n + 1, -1);
	int higePlusCycleLength = 0;
	int target = 0;
	while (visit[target] == -1) {
		visit[target] = higePlusCycleLength;
		higePlusCycleLength++;
		target = a[target];
	}
	int cycle = higePlusCycleLength - visit[target];
	int index = 0;
	if (k <= higePlusCycleLength) {		
		for (int i = 0; i < k; i++) {
			index = a[index];
		}
		cout << index + 1 << endl;
	}
	else {
		for (int i = 0; i < higePlusCycleLength; i++) {
			index = a[index];
		}
		k -= higePlusCycleLength;
		k %= cycle;
		for (int i = 0; i < k; i++) {
			index = a[index];
		}
		cout << index + 1 << endl;
	}
    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

string solve(int H, int N, const vector<int>& xs)
{
    ll sum = accumulate(xs.begin(), xs.end(), 0);

    return sum >= H ? "Yes" : "No";
}

int main()
{
    ios::sync_with_stdio(false);

    int H, N;
    cin >> H >> N;

    vector<int> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(H, N, xs);

    cout << ans << '\n';

    return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m), c(m, 0);
  vector<vector<int>> dp(1100, vector<int>(5000, LINF));
  rep(i, 0, m) {
    cin >> a[i] >> b[i];
    rep(j, 0, b[i]) {
      int t;
      cin >> t;
      --t;
      c[i] += bits(t);
    }
  }

  dp[0][0] = 0;
  rep(i, 0, m) {
    rep(j, 0, bits(n)) {
      chmin(dp[i + 1][j], dp[i][j]);
      chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
    }
  }

  if (dp[m][bits(n) - 1] >= INF)
    cout << "-1\n";
  else
    cout << dp[m][bits(n) - 1] << '\n';
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0){
			cout << " " << i;
		}
		else{
			for(int x = i; x != 0; x /= 10){
				if(x % 10 == 3){
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
#define ll long long

ll r = 1000000007;
int n;
bool is_prime[1001];
int c[1001];

int main(){
    cin >> n;

    REP(i, 1001) is_prime[i] = true;
    is_prime[0] = false; is_prime[1] = false;

    REP(i, 1001){
        if(is_prime[i]){
            for(int j=2*i; j<=1001; j+=i) is_prime[j] = false;
        }
    }

    REP(i, 1001) c[i] = 0;
    for(int i=1; i<=n; i++){
        int num = i;
        REP(j, 1001){
            while(1){
                if(is_prime[j] && num%j==0){
                    c[j] += 1;
                    num /= j;
                } else {
                    break;
                }
            }
        }
    }

    ll output = 1;
    REP(i, 1001){
        if(c[i]>0){
            output *= (c[i]+1);
            output = output%r;
        }
    }
    cout << output << endl;
}


Measured memory_bytes: 256
n = int(raw_input())
Pre = map(int,raw_input().split())
In = map(int,raw_input().split())

idx = 0

def reconstruction(l,r):
    global idx
    if l >= r:
        return
    c = Pre[idx]
    idx += 1
    m = In.index(c)
    reconstruction(l,m)
    reconstruction(m+1,r)

    print c,

def main():
    reconstruction(0,n)
    print 
    return 0

main()

Measured memory_bytes: 6448
#include<bits/stdc++.h>
using namespace std;
int F[45];
int f(int n){
	if(n==1||n==0)	return F[n]=1;
	if(F[n])	return F[n];
	else return F[n]=f(n-1)+f(n-2);
}
int main(){
	int n;
	cin>>n;
	cout<<f(n)<<endl;
}


Measured memory_bytes: 3080
fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    if (a.all { it % 2 == 1 || (it % 2 == 0 && (it % 3 == 0 || it % 5 == 0))}) {
        println("APPROVED")
    } else {
        println("DENIED")
    }
}

Measured memory_bytes: 37884
# -*- coding: utf-8 -*-

N,M,X = map(int, input().split())

book = [list(map(int, input().split())) for _ in range(N)]

def sum_i(flg, i):
  result = 0
  for j in range(N):
    result += book[j][i]*flg[j]
  return result

def skill(flg):
  if len(flg)==N:
    for i in range(1,M+1):
      if sum_i(flg,i)<X:
        return ('No', -1)
    return ('Yes', sum_i(flg,0))
  else:
    result_0 = skill(flg+[0])
    result_1 = skill(flg+[1])
    if result_0[0]=='No':
      return result_1
    elif result_1[0]=='No':
      return result_0
    else:
      return ('Yes', min(result_0[1],result_1[1]))

print(skill([])[1])

Measured memory_bytes: 9236
# coding:utf-8

import math

def main():
    s = list(raw_input())
    substr = ''
    total = []
    cnt = 0
    m = False
    for i in s:
        if i == 'A' and m == False:
            cnt += 1
        elif i == 'A':
            cnt = 1
            m = False
        elif i == 'B' and m == False:
            m = True
        elif i == 'C' and m == True:
            total.append(cnt)
            m = False
        else:
            m = False
            cnt = 0
    result = 0
    for i in total:
        result += i
    print result

if __name__ == "__main__":
    main()



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

const int N = 1000001;
int g[N][26], h[N][26], c = 0;

typedef long long ll;

int main(void) {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<string> sv(n);
    for (string& s : sv) cin >> s;
    sort(sv.begin(), sv.end(), [](const string& s1, const string& s2) { return s1.size() > s2.size(); });
    ll ans = 0;
    for (string& s : sv) {
        reverse(s.begin(), s.end());
        bool fail = 0;
        int p = 0;
        for (int i = 0; i + 1 < s.size(); ++i) {
            p = g[p][s[i] - 'a'];
            if (!p) fail = 1;
        }
        if (!fail) ans += h[p][s.back() - 'a'];
        int z[26] = { 0 };
        for (char ch : s) z[ch - 'a']++;
        p = 0;
        for (int i = 0; i < s.size(); ++i) {
            for (int j = 0; j < 26; ++j)
                if (z[j]) h[p][j]++;
            int o = s[i] - 'a';
            z[o]--;
            if (!g[p][o]) g[p][o] = ++c;
            p = g[p][o];
        }
    }
    printf("%lld\n", ans);
    


    return 0;
}

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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100005;

int main() {

	ll a, b;
	scanf("%lld %lld", &a, &b);
	printf("%lld\n", a*b / __gcd(a, b));
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=0; cin>>n;
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        ll k=1;
        while(k*(k+1)/2<=cnt) k++;
        ans+=k-1;
    }
    if(n!=1) ans+=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  ll a,b;
  cin>>a>>b;
  if((a+b)&1)cout<<"IMPOSSIBLE"<<endl;
  else{
    ans=(a+b)/2;
    cout<<ans<<endl;
  }
}


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

int main(){
    int n, k;
    int num[200020]={0};
    cin >> n >> k;
    for (int i=1; i<=n; i++){
        int l;
        cin >> l;
        num[l] += 1;
    }
    sort(num+1, num+n+1, greater<int>());
    int s = 0;
    for (int i=1; i<=k; i++) {
        s += num[i];
    }
    int ans = n - s;
    if (ans >= 0) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            var input = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long ans = 0;
            long num = 0;
            input = input.OrderBy(l => l).ToArray();
            long check = input[0];
            for (int i = 0; i < n; i++)
            {
                if (input[i] != check)
                {
                    if (num > check) ans += num - check;
                    else if (num < check) ans += num;
                    check = input[i];
                    num = 1;
                }
                else if (input[i] == check)
                {
                    num++;
                }
            }
            if (num > check) ans += num - check;
            else if (num < check) ans += num;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.printf("%d %d %.10f\n", a/b,a%b,(double)a/(double)b);
	}
}




Measured memory_bytes: 26540
#!/usr/bin/python3

h, w = list(map(int, input().split()))
s = []
s.append([0 for i in range(w + 2)])
for i in range(h):
    line = [0]
    line.extend(input().replace('.', '0'))
    line.append(0)
    s.append(line)
s.append([0 for i in range(w + 2)])

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '#':
            for k in range(i - 1, i + 2):
                for l in range(j - 1, j + 2):
                    if k == i and l == j:
                        continue
                    if s[k][l] == '#':
                        continue
                    elif s[k][l] == '0':
                        s[k][l] = 1
                    else:
                        s[k][l] += 1

for i in range(1, h + 1):
    for j in range(1, w + 1):
        print(s[i][j], end = '')
    print()


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

int main(void) {
    string S; cin >> S;
    if(S[int(S.size())-1] == 's') S+="es";
    else S+='s';
    cout << S << endl;
}

Measured memory_bytes: 3620
import itertools

n = int(input())
L = list(map(int, input().split()))

L.sort(reverse = True)
li = list(itertools.combinations(L, 3))

ans = 0
for v in li:
    if v[0] != v[1] and v[1] != v[2] and v[0] - v[1] < v[2]:
        ans += 1
print(ans)


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

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

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

int main() {
    int H;
    while(true) {
        scanf("%d", &H);
        if(H == 0) break;
        int p[10][5];
        for(int i = H - 1; i >= 0; --i) {
            for(int j = 0; j < 5; ++j) {
                scanf("%d", &p[i][j]);
            }
        }
        bool updated;
        int point = 0;
        while(true) {
            updated = false;
            for(int i = 0; i < H; ++i) {
                for(int j = 0; j < 5; ++j) {
                    if(p[i][j] == 0) continue;
                    int d = 1;
                    while(j + d < 5) {
                        if(p[i][j] != p[i][j + d]) break;
                        ++d;
                    }
                    if(d >= 3) {
                        updated = true;
                        point += d * p[i][j];
                        fill(p[i] + j, p[i] + j + d, 0);
                    }
                }
            }
            if(!updated) break;
            for(int _ = 0; _ < 5; ++_) {
                for(int i = 0; i < H - 1; ++i) {
                    for(int j = 0; j < 5; ++j) {
                        if(p[i][j] == 0) {
                            swap(p[i][j], p[i + 1][j]);
                        }
                    }
                }
            }
        }
        printf("%d\n", point);
    }
    return 0;
}

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

using namespace std;
#define lint long long


int main() {
    int N;
    cin >> N;
    
    int a[N];
    
    for(int i = 0; i < N; ++i){
        int b;
        cin >> b;
        a[i] = b - 1;
    }
    int cnt = 0;
    
    for(int i = 0; i < N; ++i){
        if(a[i] > i){
            if(a[a[i]] == i){
                ++cnt;
            }
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 640