akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int K = sc.nextInt();
		Long[] H = new Long[N];

		for (int i = 0; i < N; i++) {
			H[i] = sc.nextLong();
		}

		if (K >= N) {
			System.out.println(0); // 全て必殺技
		} else {
			Arrays.sort(H, Collections.reverseOrder());

			Long[] M = Arrays.copyOfRange(H, K, H.length);
			long sum = 0;

			for (int i = 0; i < M.length; i++) {
				sum += M[i];
			}

			System.out.println(sum);
		}

		sc.close();
	}

}


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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var dic = new Dictionary<string, int>() { };
        for (int i = 0; i < s.Length; i++)
        {
            bool ok = true;
            StringBuilder sb = new StringBuilder("");
            for (int k = 0; k < i; k++)
            {
                if (s[k] == '?')
                {
                    sb.Append("a");
                }
                else
                {
                    sb.Append(s[k]);
                }
            }


            for (int k = 0; k < t.Length; k++)
            {
                if (i + k == s.Length)
                {
                    ok = false;
                    break;
                }
                else if (s[i + k] == '?')
                {
                    sb.Append(t[k]);
                }
                else if (s[i + k] == t[k])
                {
                    sb.Append(t[k]);
                }
                else
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
            {
                while (sb.Length < s.Length)
                {
                    if (s[sb.Length] == '?')
                    {
                        sb.Append("a");
                    }
                    else
                    {
                        sb.Append(s[sb.Length]);
                    }
                }

                if (!dic.ContainsKey(sb.ToString()))
                {
                    dic.Add(sb.ToString(), 1);
                }
            }
        }

        // 出力
        var ans = "";
        if (dic.Count == 0)
        {
            ans = "UNRESTORABLE";
        }
        else
        {
            ans = dic.OrderBy(val => val.Key).First().Key;
        }
        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13536
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 100006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , k;
char ch[MAXN];
int l[MAXN];
string res , t;
void solve() {
	cin >> n >> k;
	scanf("%s",ch + 1);
	char c = 'z';
	rep( i , 1 , n ) ch[n + ( n - i + 1 )] = ch[i] , c = min( c , ch[i] );
	n <<= 1;
	if( k == 1 ) {
		string res;
		rep( i , 1 , ( n >> 1 ) ) {
			string t;
			rep( j , i , i + ( n >> 1 ) - 1 ) t += ch[j];
			if( res.empty() || res > t ) res = t;
		}
		cout << res << endl;
		return;
	}
	if( k >= 15 ) {
		rep( i , 1 , n >> 1 ) putchar( c ); return;
	}
	int mx = 0;
	rep( i , 1 , n ) {
		if( ch[i] == c ) l[i] = l[i - 1] + 1 , mx = max( mx , l[i] );
		else l[i] = 0;
	}
	int len = ( mx << k - 1 );
	if( len >= ( n >> 1 ) ) {
		rep( i , 1 , n >> 1 ) putchar( c ); return;
	}
	rep( i , 1 , n ) {
		if( l[i] == mx ) {
			t.clear();
			if( i - mx + ( n >> 1 ) > n ) break;
			rep( j , i + 1 , i + ( n >> 1 ) - mx ) t.push_back( ch[j] );
			if( res.empty() || res > t ) res = t;
		}
	}
	int l = len;
	rep( i , 1 , len ) putchar( c );
	for( auto& t : res ) {
		++ l , putchar( t );
		if( l >= ( n >> 1 ) ) break;
	}
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}



Measured memory_bytes: 384
// https://atcoder.jp/contests/abc155/tasks/abc155_b

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;

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

    string ans = "APPROVED";

    for(int i = 1; i <= N; i++) {
        if(a[i] % 2 == 0) {
            if(!((a[i] % 3 == 0) || (a[i]%5 == 0))) {
                ans = "DENIED";
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll n,x;
    cin >> n >> x;
    ll ans = n;
    ll a = x,b = n-x;
    while(true) {
        ans += a/b*2*b;
        if(a%b == 0) {
            ans -= b;
            break;
        }
        ll na = b,nb = a%b;
        swap(a,na);
        swap(b,nb);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

std::vector<int> manacher(const std::string &s) {
    int n = s.size();
    std::vector<int> rad(n);
    int c = 0;
    for (int r = 0; r < n; ++r) {
        int l = c - (r - c);
        if (r + rad[l] < c + rad[c]) {
            rad[r] = rad[l];
        } else {
            int rr = c + rad[c];
            int rl = r - (rr - r);
            while (rl >= 0 && rr < n && s[rl] == s[rr]) ++rr, --rl;
            rad[r] = rr - r;
            c = r;
        }
    }
    return rad;
}

std::string insert_dollar(const std::string &s) {
    int n = s.size();
    std::string res(n * 2 + 1, '$');
    for (int i = 0; i < n; ++i) {
        res[i * 2 + 1] = s[i];
    }
    return res;
}

bool is_palindrome(int l, int r, const std::vector<int> &rad) {
    l = l * 2 + 1;
    r = (r - 1) * 2 + 1;
    int c = (l + r) / 2;
    return r < c + rad[c];
}
int main() {
  cin >> L;
  long double l = (long double)(L)/3;
  cout << setprecision(14) << l*l*l;
} 



Measured memory_bytes: 256
K,N=map(int,input().split())
a=input().split()
A=[int(b) for b in a]
answers=[]
for z in range(N-1):
    sa=A[z+1]-A[z]
    answers.append(sa)
answers.append(K-A[-1]+A[0])
kotae=max(answers)
print(K-kotae)


Measured memory_bytes: 86092
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()

	println((a + b) % 24)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
	int a,b,c,i,cnt = 0;
	scanf("%d %d %d",&a,&b,&c);
	if(b > c)b = c;
	if(a <= c){
		for( i = a;i <= b; i++){
			if(c % i == 0) {
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	
	return 0;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> v(5);
  rep(i,0,4) cin >> v[i];

  ll min = *min_element(v.begin(), v.end());
  if (N <= min) {
    cout << 5 << endl;
    return 0;
  }

  ll t = (N + min - 1) / min;
  cout << t + 4 << endl;
  return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] list = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			list[i] = sc.nextInt();
			sum += list[i];
		}
		double avg = (double) sum / n;
		int avg2 = (int) Math.round(avg);
		int cst = 0;
		for (int i = 0; i < n; i++) {
			cst += Math.pow(list[i] - avg2, 2);
		}
		System.out.println(cst);
	}

}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n=0,m=0; cin>>n>>m;
  vector<int> A(n,0);
  vector<bool> AC(n,false);
  rep(i,m){
    int p=0; cin>>p;
    string s; cin>>s;
    if(s=="AC") AC.at(p-1)=true;
    else if(s=="WA"&&!AC.at(p-1)) A.at(p-1)++;
  }
  int ac=0,wa=0;
  rep(i,n) if(AC.at(i)) ac++;
  rep(i,n) if(AC.at(i)) wa+=A.at(i);
  cout<<ac<<' '<<wa<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<vector<pair<int,int>>> tree(N);
    REP(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        tree[a].push_back({b,i});
        tree[b].push_back({a,i});
    }
    vector<int> c(N-1);
    int K=1;
    function<void(int,int,int)> dfs=[&](int u,int pre,int col){
        int ini=1;
        for(auto v:tree[u]){
            if(v.first==pre) continue;
            if(ini==col) ini++;
            c[v.second]=ini;
            K=max(K,ini);
            dfs(v.first,u,ini++);
        }
    };
    dfs(0,-1,0);
    cout<<K<<endl;
    REP(i,N-1) cout<<c[i]<<endl;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<(int64)n;i++)
#define FORr(i,k,n)  for(int64 i=(int64)k;i>=n;i--)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define FOREACHr(it, l) for (auto it = l.rbegin(); it != l.rend(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}


int main(){
//	in_o();
	int n,m;
	cin>>n>>m;
	string s[n];
	FOR(i,0,n){
		cin>>s[i];
	}
	FOR(i,0,n){
		FOR(j,0,m){
			if(s[i][j]=='#') continue;
			int cnt=0;
			FOR(k,0,8){
				int x=i+dx[k];
				int y=j+dy[k];
				if((x>=0 && x<n &&  y>=0 && y<m) && s[x][y]=='#') cnt++;
			}
			s[i][j]=(char)cnt+'0';
		}
	}
	FOR(i,0,n){
		cout<<s[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		System.out.println((n / 10 == 9 || n % 10 == 9) ? "Yes" : "No");

		sc.close();


	}

}




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

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

    for (int ans = 111; ans <= 999; ans += 111)
        if (ans >= n)
        {
            cout << ans << endl;
            return 0;
        }
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list> 
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1 << 29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N, indeg[MAX];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	V[s] = true;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		out.push_back(u);
		for(int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v] --;
			if(indeg[v] == 0 && V[v] == false) {
				V[v] = true;
				q.push(v);
			}
			
		}
	}
}

void tsort() {
	for(int i = 0; i < N; i++) {
		indeg[i] = 0;
	}
	
	for(int u = 0; u < N; u++) {
		for(int i = 0; i < G[u].size(); i++) {
			int v =  G[u][i];
			indeg[v]++;
		}
	}
	
	for(int u = 0; u < N; u++) {
		if(indeg[u] == 0 && ! V[u]) bfs(u);
	}
	
	for(list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}
}

int main() {
	int s, t, M;
	
	cin >> N >> M;
	
	for(int i = 0; i < N; i++) V[i] = false;

    for(int i = 0; i < M; i++) {
    	cin >> s >> t;
    	G[s].push_back(t);
    }
    
    tsort();
    
    return 0;
} 

Measured memory_bytes: 6080
program brick_break
    implicit none
    integer(4):: n, i, ni
    integer(4), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    ni = 0
    i = 1
    do i=1,n
        if (a(i) == ni+1) ni = ni + 1
    end do

    if (ni == 0) then
        print*, -1
    else
        print*, n-ni
    endif
end program brick_break

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
using namespace std;
typedef long long ll;
const ll maxn=1e5+100;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll t,b[300];
ll a[4];
map<ll,ll> mp;
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n;
    cin>>n;
    rep(i,0,n-1) cin>>b[i];
    ll res=0;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            rep(k,j+1,n-1){
                a[0]=b[i],a[1]=b[j],a[2]=b[k];
                if(a[0]==a[1]||a[0]==a[2]||a[1]==a[2]) continue;
                sort(a,a+3);
                if(a[0]+a[1]>a[2]) res++;
            }
        }
    }
    cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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

int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>CSF(N - 1,vector<int>(3));
	rep(i, 0, N - 1)rep(j, 0, 3)cin >> CSF[i][j];
	rep(i, 0, N - 1) {
		int st = CSF[i][1] + CSF[i][0];
		rep(j, i + 1, N-1) {
			if (st <= CSF[j][1]) {
				st += CSF[j][1] - st;
				st += CSF[j][0];
			}
			else {
				if (st % CSF[j][2] != 0)st += CSF[j][2] - st % CSF[j][2];
				st += CSF[j][0];
			}
		}
		cout << st << "\n";
	}
	cout << 0 << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
  int N,M;
  int[][] e;
  
  int calc(int k, boolean[] f) {
    if (check(f)) {
      return 1;
    }
    int ret = 0;
	  for (int i = 0; i <N; i++) {
	    if (e[k][i] == 1 && !f[i]) {
		  f[i] = true;
		  ret += calc(i, f);
		  f[i] = false;
		}
	  }
	  return ret;
	}
 
	boolean check(boolean[] f) {
      for (int i = 0; i <N; i++) {
	    if (!f[i]) {
          return false;
		}
	  }
	  return true;
	}
  
  void run() {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();  
    M = sc.nextInt();
    e = new int[N][N];
	for (int i = 0; i < M; i++) {
      int a = sc.nextInt() - 1;
      int b = sc.nextInt() - 1;
      e[a][b] = e[b][a] = 1;
    }
	boolean[] f = new boolean[N];
	f[0] = true;
	System.out.println(calc(0, f));
	}
  
  public static void main(String[] args) {
    new Main().run();
  }
  
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



void solve()
{
    string str;
    cin >> str;
    int sz = str.size();
    cout << str;
    if ( str[sz - 1] != 's' ) cout << 's';
    else cout << "es";

}

int32_t main()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

    int test = 1;
    // cin >> test;
    while (test--)solve();


}





















Measured memory_bytes: 3660
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll n;
    cin >> n;
    vector<ll> l(n);
    ll ans = 0;
    rep(i,n) cin >> l[i];
    sort(all(l));
    rep(i,n-2){
      REP(j,i+1,n-1){
          ll right = lower_bound(all(l), l[i] + l[j]) - l.begin();
          ll left = j + 1;
          ans += right - left;
      }
    }
    print(ans);
}


Measured memory_bytes: 256
// AOJ 0612 Sandcastle
// 2018.2.26 bal4u

#include <stdio.h>
#include <ctype.h>

typedef struct { short r, c; } Q;
Q q[2][2000]; int top[2], tail[2];
char map[1002][1002];
char a[1002][1002];
int mv[8][2] = {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};

int main()
{
	int h, w, r, c, i, k1, k2, nr, nc, ans, f;
	char buf[15], *p;

	fgets(buf, 15, stdin), sscanf(buf, "%d%d", &h, &w);

	for (r = 0; r < h; r++) {
		fgets(p=map[r], 1002, stdin);
		while (*p > ' ') {
			if (isdigit(*p)) *p &= 0xf;
			p++;
		}
	}

	for (r = 1; r < h-1; r++) for (c = 1; c < w-1; c++) {
		for (i = 0; i < 8; i++) {
			nr = r + mv[i][0], nc = c + mv[i][1];
			if (map[nr][nc] == '.') a[r][c]++;
		}
		if (map[r][c] < 10 && a[r][c] >= map[r][c]) {
			q[0][tail[0]].r = r, q[0][tail[0]++].c = c;
		}
	}

	ans = 0;
	for (k1 = 0, k2 = 1; ; k1 = k2, k2 = !k2) {
		 f = 0;
		 top[k2] = tail[k2] = 0;
		 while (top[k1] < tail[k1]) {
			r = q[k1][top[k1]].r, c = q[k1][top[k1]++].c;
			for (i = 0; i < 8; i++) {
				nr = r + mv[i][0], nc = c + mv[i][1];
				if (map[nr][nc] < 10 && ++a[nr][nc] == map[nr][nc]) {
					q[k2][tail[k2]].r = nr, q[k2][tail[k2]++].c = nc, f = 1;
				}
			}
		}
		ans++;
		if (!f) break;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
  int a[5];
  rep(i,5) cin>>a[i];
  rep(i,5){
    if(a[i]==0) dunk(i+1);
  }
}

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

int main(){
  int N;
  cin >> N;
  
  if(N == 1){
    cout << 1 << endl;
    return 0;
  }
  
  int64_t l1 = 2, l2 = 1;
  int count = 1;
  while(count < N){
    int64_t l3 = l1 + l2;
    l1 = l2;
    l2 = l3;
    count++;
  }
  
  cout << l2 << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines

n = int(input())
a = [int(i) for i in readline().split()]

ans = 0

MOD = (10**9+7)
for i in range(62):
    c = 0
    for ai in a:
        if ai&(1<<i): c += 1
    
    r = c*(n-c)
    ans += (1<<i)*r
    ans %= MOD


print(ans)     











Measured memory_bytes: 123132
#include<bits/stdc++.h>
using namespace std;
int n,lis[111][111]={},d[111]={},f[111],t=1;

void dfs(int now){
  d[now]=t++;
  for(int i=1;i<=n;i++)
    if(lis[now][i]&&d[i]==0)dfs(i);
  f[now]=t++;
}

int main(){
  cin>>n;
  for(int c=0;c<n;c++){
    int u,k,v;
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v;
      lis[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++)if(d[i]==0)dfs(i);
  for(int i=1;i<=n;i++)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;  
  
  return 0;
}



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

typedef long long ll;

const int MAX_N = 200020;
const int INF = 1<<29;

int dp[1<<26];
int charMask[MAX_N];

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

    string s;
    cin>>s;

    int currMask = 0;

    for(int i = 0;i<(int)s.size();++i) {
        int bit = s[i]-'a';
        currMask ^= 1<<bit;

        charMask[i] = currMask;
    }

    for(int i = 0;i<(1<<26);++i) {
        dp[i] = INF;
    }

    dp[0] = 0;

    int res = 0;
    for(int i = 0;i<(int)s.size();++i) {
        int best = dp[charMask[i]] != INF ? 1 + dp[charMask[i]] : INF;
        for(int x = 0;x<26;++x) {
            int mask = charMask[i] ^ (1<<x);

            if(dp[mask] != INF) {
                best = min(best, 1+dp[mask]);
            }
        }

        dp[charMask[i]] = min(dp[charMask[i]], best);
        res = best;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 263572
program main
   implicit none
   integer::N
   integer,allocatable,dimension(:)::L
   integer::i,j
   integer::ok,ng,med
   integer::cnt=0
   read*,N
   allocate(L(N))
   read*,L
   call heapsort(N,L)
   do i=N,3,-1
      do j=i-1,2,-1
         if(L(i)<L(j)+L(1))then
            cnt=cnt+j-1
            cycle
         endif
         ok=j;ng=1
         med=(ok+ng)/2
         do while(ok-ng>1)
            if(check(L(i),L(j),L(med)))then
               ok=med
            else
               ng=med
            endif
            med=(ok+ng)/2
         end do
         cnt=cnt+j-ok
      end do
   end do
   print"(i0)",cnt
contains
logical function check(a,b,x)
   integer::a,b,x
   check=(b+x>a)
end

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort

end program main

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size() - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a[100][100];
  int i,j,n,number,dime,destination;

  scanf("%d",&n);
  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      a[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&number,&dime);
    for(j=0;j<dime;j++){
      scanf("%d",&destination);
      a[number-1][destination-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==n-1){
        printf("%d\n",a[i][j]);
      }
      else{printf("%d ",a[i][j]);}
    }
  }

  return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
if mid<=0: mid=1
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)

Measured memory_bytes: 30852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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;
}

int po[1010101];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i,j;
  for(i=1;i<1010101;i++){
    int p=i;
    int cnt=0;
    while(p%2==0){
      cnt++;
      p=p/2;
    }
    po[i]=cnt;
  }
  int n;
  cin>>n;
  string a;
  cin>>a;
  VI v(n);
  for(i=0;i<n;i++) v[i]=a[i]-'1';
  bool fl=1;
  for(i=0;i<n;i++){
    if(v[i]==1) fl=0;
  }
  if(fl){
    for(i=0;i<n;i++) v[i]=v[i]/2;
  }
  int tw=0;
  int ans=0;
  if(v[0]==1) ans=1;
  for(i=1;i<n;i++){
    tw+=po[n-i];
    tw-=po[i];
    if(v[i]==1&&tw==0) ans=1-ans;
  }
  if(fl) ans*=2;
  cout<<ans<<endl;

}

Measured memory_bytes: 13084
k,n = map(int,input().split())
lista = list(map(int,input().split()))


max = 0
for i in range(1,n):
    if lista[i]-lista[i-1]>=max:
        max = lista[i]-lista[i-1]

if k-lista[n-1]+lista[0]>=max:
    max = k-lista[n-1]+lista[0]

print(k-max)
    

Measured memory_bytes: 26420
#include <iostream>
#include <vector>
#include <algorithm>

int BubbleSort(std::vector<int>& arr)
{
	bool flag = true;
	int count = 0;
	while (flag)
	{
		flag = false;
		for (auto i = arr.size()-1; i >= 1; --i)
		{
			if (arr[i] < arr[i - 1])
			{
				std::swap(arr[i], arr[i - 1]);
				flag = true;
				++count;
			}
		}
	}
	return count;
}

template<typename T>
T Input()
{
	T value;
	std::cin >> value;
	return value;
}

int main()
{
	std::vector<int> arr;
	int num, count;
	std::cin >> num;
	for (auto i = 0; i < num; ++i)
		arr.push_back(Input<int>());

	count = BubbleSort(arr);

	for (auto i = 0; i < num;++i)
		std::cout << arr[i] << (i!=num-1? " ":"");
	std::cout << "\n" << count << "\n";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector <int> a(n);
  bool flg = false;
  for (int i = 0; i < n; i++) {
	  cin >> a[i];
	  if (a[i] == 1) {
		  flg = true;
		}
	}
  if (!flg) {
	  cout << -1 << endl;
	  return 0;
	}
  int ans = 0;
  int num = 1;
  for (int i = 0; i < n; i++) {
	  if (a[i] == num) {
		  num++;
		} else {
		  ans++;
		}
	}
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fo(i, n) for(int i = 1; i <= n; ++i)

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

const int N = 200200;
const int mod = 1e9 + 7;
ll k, a[N];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> k;
	fo(i, k)
		cin >> a[i];
	ll l = 0, r = 1e18;
	while(l + 1 < r)
	{
		ll m = l + r >> 1;
		ll cur = m;
		fo(i, k)
			cur = cur / a[i] * a[i];
		if(cur >= 2)
			r = m;
		else
			l = m;
	}	
	ll cur = r;
	fo(i, k)
		cur = cur / a[i] * a[i];
	if(cur != 2)
		return cout << -1, 0;
	cout << r << ' ';
	l = r, r = 1e18;
	while(l + 1 < r)
	{
		ll m = l + r >> 1;
		ll cur = m;
		fo(i, k)
			cur = cur / a[i] * a[i];
		if(cur > 2)
			r = m;
		else
			l = m;
	}	
	cout << l;
	return 0;            
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int mod=998244353;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int n,f[1000001];
char c[1000001],s[1000001];
int calc1(int x,int ans=0){
	for(int i=1;i<=x;i++)
		ans=((ans*2)+(s[i]-'0'))%mod;
	return ans;
}
int calc2(int x){
	for(int i=1;i<=x;i++)
		c[i]=s[i];
	for(int i=x+1;i<=n;i++)
		c[i]=c[i-x]^1;
	for(int i=1;i<=n;i++)
		if(c[i]!=s[i])
			return c[i]<s[i];
	return 1;
}
main(){
	n=read();
	scanf("%s",s+1);
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			if((n/i)%2==1)
				f[i]=calc1(i)+calc2(i);
			if(i%2==1)
				f[n/i]=calc1(n/i)+calc2(n/i);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(n%i==0)
			for(int j=1;j<i;j++)
				if(i%j==0)
					f[i]=(f[i]-f[j]+mod)%mod;
	for(int i=1;i<=n;i++)
		ans=(ans+2*i*f[i])%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from bisect import bisect_right

INF = float("inf")


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    dp = [INF]*N
    for i in range(N):
        j = bisect_right(dp, -A[i])
        dp[j] = -A[i]

    print(bisect_left(dp, INF))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17080
N = int(input())
A = list(map(int,input().split()))
INF = 2*N
DP = [[-INF]*(N+1) for _ in range(N+1)]
M = 0
rowM = [-INF]*(N+1)

def chmax(i,j,k):
    DP[i][j] = max(k,DP[i][j])
    DP[j][i] = max(k,DP[j][i])
    rowM[i] = max(rowM[i],DP[i][j])
    rowM[j] = max(rowM[j],DP[i][j])
    global M
    M = max(M,k)

ans = 0
DP[A[0]][A[1]] = 0
DP[A[1]][A[0]] = 0
rowM[A[0]] = 0
rowM[A[1]] = 0
for i in range(N-1):
    new = A[3*i+2:3*i+5]
    change = []
    if len(set(new)) == 1:
        ans += 1
        continue
    if len(set(new)) == 2:
        for j in range(3):
            if new.count(new[j]) == 2:
                X = new[j]
            else:
                Y = new[j]
        for j in range(1,N+1):
            change.append((j,Y,DP[X][j]+1))
    X,Y,Z = new
    change.append((X,Y,DP[Z][Z]+1))
    change.append((Y,Z,DP[X][X]+1))
    change.append((X,Z,DP[Y][Y]+1))
    change.append((X,Y,M))
    change.append((X,Z,M))
    change.append((Y,Z,M))
    for j in range(1,N+1):
        for k in range(3):
            change.append((j,new[k],rowM[j]))
    for j,k,l in change:
        chmax(j,k,l)
M = max(M,DP[A[-1]][A[-1]]+1)
print(ans+M)

Measured memory_bytes: 222912
L = []
L2 = []
for _ in range(5):
    a = input()
    if a[-1] == "0":
        L.append(int(a))
    else:
        last = int(a[-1])
        L.append(int(a) + 10 - last)
        L2.append(last)
if not L2:
    print(sum(L))
else:
    print(sum(L) + min(L2) - 10)

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

int main(){
    int N;
    cin>>N;
    vector<int> d;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        d.push_back(x);
    }

    sort(d.begin(),d.end());
    cout<<d.at(N/2)-d.at((N/2)-1)<<endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define MAXN	200005
struct edge {int dest; long long len; };
struct info {long long x, y; };
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
long long now; int n;
edge lc[MAXN], rc[MAXN];
vector <info> a[MAXN], tmp, tnp;
void debug() {
	for (unsigned i = 0; i < tmp.size(); i++)
		cerr << tmp[i].x << ' ' << tmp[i].y << ',';
	cerr << endl;
	for (unsigned i = 0; i < tnp.size(); i++)
		cerr << tnp[i].x << ' ' << tnp[i].y << ',';
	cerr << endl;
}
void dfs(int pos) {
	if (lc[pos].dest == 0) {
		a[pos].push_back((info) {0, 0});
		return;
	}
	dfs(lc[pos].dest);
	dfs(rc[pos].dest);
	if (a[lc[pos].dest].size() > a[rc[pos].dest].size()) swap(lc[pos], rc[pos]);
	if (a[lc[pos].dest].size() == 0) return;
	tmp.clear(); tnp.clear();
	int ls = a[lc[pos].dest].size();
	int rs = a[rc[pos].dest].size();
	int p = -1, l = lc[pos].dest, r = rc[pos].dest;
	//if (pos == 2) debug();
	for (int i = 0; i < ls; i++) {
		long long limit = now - lc[pos].len - rc[pos].len - a[l][i].y;
		while (p + 1 < rs && a[r][p + 1].x <= limit) p++;
		if (p != -1 && (tmp.size() == 0 || tmp[tmp.size() - 1].y > a[r][p].y + rc[pos].len))
			tmp.push_back((info) {a[l][i].x + lc[pos].len, a[r][p].y + rc[pos].len});
	}
	//if (pos == 4) debug();
	p = -1;
	for (int i = 0; i < rs; i++) {
		long long limit = now - lc[pos].len - rc[pos].len - a[r][i].y;
		while (p + 1 < ls && a[l][p + 1].x <= limit) p++;
		if (p != -1 && (tnp.size() == 0 || tnp[tnp.size() - 1].y > a[l][p].y + lc[pos].len))
			tnp.push_back((info) {a[r][i].x + rc[pos].len, a[l][p].y + lc[pos].len});
	}
	//if (pos == 4) debug();
	int q;
	p = 0, q = 0;
	ls = tmp.size();
	rs = tnp.size();
	while (p < ls || q < rs) {
		if (q == rs || (p != ls && tmp[p].x < tnp[q].x)) {
			if (a[pos].size() == 0 || a[pos][a[pos].size() - 1].y > tmp[p].y)
				a[pos].push_back(tmp[p]);
			p++;
		} else {
			if (a[pos].size() == 0 || a[pos][a[pos].size() - 1].y > tnp[q].y)
				a[pos].push_back(tnp[q]);
			q++;
		}
	}
}
bool check() {
	for (int i = 1; i <= n; i++)
		a[i].clear();
	dfs(1); 
	/*for (int i = 1; i <= n; i++) {
		for (unsigned j = 0; j < a[i].size(); j++)
			cerr << a[i][j].x << ' ' << a[i][j].y << ',';
		cerr << i << endl;
	}*/
	return a[1].size() != 0;
}
int main() {
	read(n);
	long long m = 0;
	for (int i = 2; i <= n; i++) {
		int x; long long y;
		read(x), read(y);
		m = max(y, m);
		if (lc[x].dest == 0) lc[x] = (edge) {i, y};
		else rc[x] = (edge) {i, y};
	}
	long long l = 0, r = m * n;
	while (l < r) {
		now = (l + r) / 2;
		if (check()) r = now;
		else l = now + 1;
	}
	cout << l << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    int N;
    cin >> N;
    std::priority_queue<double, std::deque<double>, std::greater<>> q;

    {
        int x;
        for (int i = 0; i < N; ++i) {
            cin >> x;
            q.emplace(static_cast<double>(x));
        }
    }

    while (q.size() > 1) {
        const auto x = q.top();
        q.pop();

        const auto y = q.top();
        q.pop();

        q.emplace((x + y) / 2.0);
    }

    std::cout << std::fixed << std::setprecision(10) << q.top() << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
 
using namespace std;
 
int main()
{
    int n,m;
    int a,b;
 
    vector<vector<int> > f;
    set<int> ans;
 
    cin >> n >> m;
    while(n!=0 && m!=0) {
        for(int i=0; i<=n; ++i) {
            f.push_back({});
        }
 
        for(int i=0; i<m; ++i) {
            cin >> a >> b;
            f[a].push_back(b);
            f[b].push_back(a);
        }
 
        ans.insert(f[1].begin(),f[1].end());
 
        for(int i=0; i<(int)f[1].size(); ++i) {
            ans.insert(f[f[1][i]].begin(), f[f[1][i]].end());
        }
        ans.erase(1);
        cout << ans.size() << endl;
 
        cin >> n >> m;
        f.clear();
        ans.clear();
    }
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>=k;i--)
int main(){
    long long ans=0,d=0;
    string s;
    cin>>s;
    f(i,0,s.size()){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            d++;
        }
        else{
            if(ans<d){
                ans=d;
            }
            d=0;
        }
    }
    if(ans<d){
        ans=d;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;


int main(){
    
    string x;
    cin>>x;
    int sum=0;
    for(int i=0;i<x.size();i++){
        if(x[i]=='1')
            sum++;
    }
    cout<<sum<<endl;
   
   
   
   
   return 0; 
}


Measured memory_bytes: 764
N, K = map(int, input().split())
H = [False] * N

for _ in range(K):
    d = int(input())
    A = map(int, input().split())
    for a in A:
        H[a-1] = True

ans = 0
for h in H:
    if not h:
        ans += 1

print(ans)


Measured memory_bytes: 9180
use std::vec::Vec;
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}

fn main() {
    let (n, T) = read_touple::<usize>();
    let mut t: Vec<usize> = read_vec();
    let mut diff = vec![0; n];

    for i in 1..n {
        diff[i] = t[i] - t[i-1];
    }


    let mut ans = 0;
    for i in 1..n {
        ans += min(T, diff[i]);
    }
    ans += T;

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


Measured memory_bytes: 8444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = Integer.parseInt(sc.next());
		final int K = Integer.parseInt(sc.next());
		int ans;
		if(K > 1) {
			ans = N - K;
		} else {
			ans = 0;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
using namespace std;
typedef long int li;
typedef long long int lli;
const int INF = 0xfffffff;
int x[200005] = { 0 }, y[200005] = { 0 };
int par[400007], rank_[400007];
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rank_[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rank_[x] < rank_[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank_[x] = rank_[y]) rank_[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	string a, b;
	cin >> a >> b;
	init(60);
	bool used[55],used2[55];
	for (int i = 0; i < 55; i++) {
		used[i] = false;
		used2[i] = false;
	}
 	for (int i = 0; i < a.size(); i++) {
		int anum = a[i] - 'a', bnum = b[i] - 'a' + 26;
		if (!used[anum] && !used2[bnum]) {
			unite(anum, bnum);
			used[anum] = true;
			used2[bnum] = true;
			//cout << "1" << endl;
		}
		else {
			if (!same(anum, bnum)) {
				cout << "No" << endl;
				return 0;
			}
			//cout << "2" << endl;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
  int X;
  cin >> X;

  int happy = 0;

  while(X >= 500){
    X -= 500;
    happy += 1000;
  }

  while(X >= 5){
    X -= 5;
    happy += 5;
  }

  cout << happy << endl;
}


Measured memory_bytes: 3580
import java.util.*;

public class Main {
    public static final long INF = Long.MAX_VALUE >> 2;
    public static long[] dp = new long[100010];
    public static void main(String[] args) throws Exception {
    for(int i=0;i<100010;++i)dp[i] = INF;
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int K = sc.nextInt();
       long[] steps = new long[N + 10];
       for(int i=0;i<N;i++){
           steps[i] = sc.nextLong();
       }
       //最初に考えたやり方
    //   for(int i=0;i<N;i++){
    //       if(i == 0){
    //           dp[i] = 0;
    //       }else if(i == 1){
    //           dp[i] = height(steps[0],steps[1]);
    //       }else{
    //           if(K == 1){
    //               dp[i] = dp[i - 1] + height(steps[i],steps[i-1]);
    //           }else{
    //             for(int j=1;j<=i && j<=K;j++){
    //             dp[i] = chmin(dp[i] ,dp[i-j] + height(steps[i],steps[i-j]));
    //             }
    //           }
    //       }
    //   }
    
     //こっちの方が記述しやすい
     for(int i=0;i<N;i++){
         if(i == 0){
             dp[i] = 0;
         }else{
            for(int j=1;j<=i && j<=K;j++){
                dp[i] = chmin(dp[i],(dp[i-j] + height(steps[i],steps[i-j])));
            }
         }
     }
       System.out.println(dp[N - 1]);
    }
    
    public static long height(long h1,long h2){
        return Math.abs(h1 - h2);
    }
    
    public static long chmin(long a , long b){
        return Math.min(a,b);
    }
}


Measured memory_bytes: 50744
import numpy as np
N, M ,C = map(int, input().split())
a = []
for i in range(N+1):
    a.append(list(map(int, input().split())))
all = np.array(a)
sum = 0
num = 0

for i in range(N):
    mul = np.sum(all[0] * all[i+1]) + C
    if mul > 0:
        num += 1
    mul = 0

print(num)

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

using namespace std;

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

	string s, ans = "Yes";
	cin >> s;
	for(int i = 0; i < (int) s.size(); i++) {
		if((i + 1) % 2 == 0 && s[i] == 'R') ans = "No";
		if((i + 1) % 2 == 1 && s[i] == 'L') ans = "No";
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
from functools import reduce

def fac(n, p):
    return reduce(lambda x, y: x * y % p, range(1, n + 1))

N, M = [int(x) for x in input().split()]
p = 10 ** 9 + 7
if abs(N - M) >= 2:
    ans = 0
elif N == M:
    ans = 2 * fac(N, p) * fac(M, p) % p
else:
    ans = fac(N, p) * fac(M, p) % p

print(ans)

Measured memory_bytes: 9576
import numpy as np
from scipy.optimize import minimize

L = int(input())

def objective(X):
    x = X[0]
    y = X[1]
    z = X[2]
    return - x * y * z

def constraint(X):
    x = X[0]
    y = X[1]
    z = X[2]
    return x + y + z - L

# 初期値
X0 = [0.1 * L, 0.2 * L, 0.7 * L]

# 取りうる範囲
b = (0.0, L)
bnds = (b, b, b)
cons = [{'type': 'eq', 'fun': constraint}]

sol = minimize(objective, X0, method='SLSQP', bounds=bnds, constraints=cons)
print(-sol.fun)

Measured memory_bytes: 26388