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

const string YES = "Yes";
const string NO = "No";


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    long long sum = 0;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        
        scanf("%lld",&A[i]);
        sum += A[i];
    }
    long long max = sum / (4*M);
    if(sum%(4*M) != 0){
        max++;
    }
    int count =0;
    for(int i = 0 ; i < N ; i++){
        if(max <= A[i] ){
            count++;
        }
    }
    if(count >= M){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }

    return 0;
}


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

template<int mod>
struct ModInt{
	int x;

	ModInt() : x(0){}
	ModInt(long long y) : x(y>=0 ? y%mod : (mod-(-y)%mod)){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}

	ModInt operator-() const{return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{return ModInt (*this)+=p;}
	ModInt operator-(const ModInt &p) const{return ModInt (*this)-=p;}
	ModInt operator*(const ModInt &p) const{return ModInt (*this)*=p;}
	ModInt operator/(const ModInt &p) const{return ModInt (*this)/=p;}
	bool operator==(const ModInt &p) const{return x==p.x;}
	bool operator!=(const ModInt &p) const{return x!=p.x;}
	friend ostream &operator<<(ostream &os, const ModInt &p){return os<<p.x;}
	friend istream &operator>>(istream &is,ModInt &a){
		int t;
		is>>t;
		a=ModInt<mod>(t);
		return (is);
	}

	ModInt inverse() const{
		int a=x, b=mod, u=1, v=0, t;
		while(b>0){
			t=a/b;
			a-=t*b;
			swap(a,b);
			u-=t*v;
			swap(u,v);
		}
		return ModInt(u);
	}
	
	ModInt pow(int e) const{
		long long a=1,p=x;
		while(e>0){
			if(e%2==0){p=(p*p)%mod; e/=2;}
			else {a=(a*p)%mod; e--;}
		}
		return ModInt(a);
	}
};

vector<bool> seen;
vector<int> dist1,dist2;
using graph=vector<vector<int>>;
using modint=ModInt<1000000007>;
graph G;


signed main(){
    int N,K; cin>>N>>K;
    seen.assign(N,false);
    G.assign(N,vector<int>(0));
    dist1.assign(N,0);
    dist2.assign(N,0);
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> que;
    que.push(0);
    seen[0]=true;
    modint ans=1;
    while(!que.empty()){
        int now=que.front();
        que.pop();
        ans*=(K-dist1[now]-dist2[now]);
        for(auto nv : G[now]){
            if(seen[nv])continue;
            seen[nv]=true;
            dist2[nv]=dist1[now];
            dist1[now]++;
            dist1[nv]++;
            que.push(nv);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8948
from collections import defaultdict,Counter,deque

N, X, Y = map(int, input().split())
d = defaultdict(list)
d[X].append(Y)
d[Y].append(X)
for i in range(1,N):
    d[i].append(i+1)
    d[i+1].append(i)

ans=defaultdict(int)

for i in range(N):
    dist = [None]*N
    s=i+1
    q=deque()
    q.append(s)
    dist[i]=0

    while len(q)!=0:
        From = q.popleft()
        for To in d[From]:
            if dist[To-1] == None:
                q.append(To)
                dist[To-1] = dist[From-1]+1
    c=Counter(dist)
    for i,m in c.items():
        ans[i]+=m


for i in range(1,N):
    print(ans[i]//2)

Measured memory_bytes: 78940
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

for i in range(x, -1, -1):
  if not i in p:
    a1 = i
    break

for i in range(x, 100 + 2):
  if not i in p:
    a2 = i
    break

if x - a1 <= a2 - x:
  print(a1)
else:
  print(a2)


Measured memory_bytes: 9188
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();
        int c = sc.nextInt();

        int t;
        if(a > b) {
            t = a; a = b; b = t;
        }
        if(b > c) {
            t = b; b = c; c = t;
        }
        if(a > b) {
            t = a; a = b; b = t;
        }

        System.out.println(a + " " + b + " " + c);
    }
}

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

typedef long long ll;

int n;
int a[100005][4];
ll dp[100005][4];

ll solve(int d,int l){
    if(d==n+1) return 0;
    if(dp[d][l]!=-1) return dp[d][l];
    ll ret=0;
    for(int i=1;i<=3;i++){
        if(i!=l){
            ret=max(ret, solve(d+1,i)+a[d][i]);
        }
    }
    return dp[d][l]=ret;

}


int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=3;j++)
            cin>>a[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,-1);

    return 0;
}


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

int main(){
	float m,n;
	float products[105];
	cin >> n >> m;
	float total = 0.0;
	for(int i = 1;i<=n;i++){
		cin >> products[i];
		total += products[i];
	}
	float x = total/(m*4);
	float count = 0.0;
	for(int i = 1;i<=n;i++){
		if(products[i]>=x) count ++;
	}
	if(count >= m) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int h;
    while (cin >> h, h) {
        vector<vector<int>> vvi;
        for (int i = 0; i < h; i++) {
            vector<int> vi;
            for (int j = 0; j < 5; j++) {
                int n;
                cin >> n;
                vi.push_back(n);
            }
            vvi.push_back(vi);
        }

        int score = 0;
        while (true) {
            int prescore = score;
            // delete
            for (int j = 0; j < h; j++) {
                for (int i = 0; i < 5; i++) {
                    if (vvi[j][i] == -1)
                        continue;
                    int count = 0;
                    int num = vvi[j][i];
                    for (int k = i; k < 5; k++) {
                        if (vvi[j][k] == num)
                            count++;
                        else
                            break;
                    }
                    if (count < 3)
                        continue;
                    for (int k = i; k < i+count; k++)
                        vvi[j][k] = -1;
                    score += num * count;
                }
            }

            if (prescore == score) {
                cout << score << endl;
                break;
            }

            // fall
            bool loop = true;
            while (loop) {
                loop = false;
                for (int j = 0; j < h; j++) {
                    for (int i = 0; i < 5; i++) {
                        if (vvi[j][i] != -1)
                            continue;
                        for (int k = j; k >= 0; k--) {
                            if (vvi[k][i] == -1)
                                continue;
                            int a = vvi[k][i];
                            vvi[k][i] = -1;
                            vvi[j][i] = a;
                            loop = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n){
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    int ans = 0;
    if(d.size() % 2 == 0){
        if(d[n/2 - 1] != d[n/2]){
            ans = d[n/2] - d[n/2 - 1];
        }
    }
    cout << ans << endl;
}

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


int main() {
    int x;
    cin >> x;
    double ans = 0;
    if(x == 1){
        cout << 1 << endl;
        return 0;
    }else{
        for(int i = 2;i<=x;i++){
            double p = 1;
            for(int j = 2;pow(i,j) <= x;j++){
                p = pow(i,j);
            }
            ans = max(p,ans);
        }
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	string S;
	cin >> S;
	ll ans = 0;
	ll tmp;//+で分割したものを代入
	for (int bit = 0; bit < (1 << S.size()-1); ++bit) {
		ll sm = 0;
		ll tmp = S[0] - '0';
		for (int i = 0; i < S.size()-1; ++i) {
			if (bit&(1 << i)) {
				ans += tmp;
				tmp = 0;
			}
			tmp = tmp * 10 + (S[i + 1] - '0');
		}
		sm += tmp;
		ans += sm;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

vector<string> s;
vector<string> sp;
map<string, int> mp;
signed main(){
	int k;
	string str;
	cin >> str;
	scanf("%lld", &k);
	int cnt = 0, n = str.size();
	rep(i,n){
		int tmp = min(n-i, (int)10);
		rrep(j,tmp){
			//cout << str.substr(i, j) << endl;
			string ss = str.substr(i, j);
			if(mp[ss])continue;
			mp[ss]++;
			s.pb(ss);
		}
	}
	int m = s.size();
	sort(all(s));
	cout << s[k-1] << endl;
	return 0;
}




Measured memory_bytes: 4984
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

K = I()
que = deque([1,2,3,4,5,6,7,8,9])
lst = [1,2,3,4,5,6,7,8,9]
cnt = 9
while cnt < K:
    s = que.popleft()
    t = int(str(s)[-1])
    for i in range(max(0,t-1),min(10,t+2)):
        cnt += 1
        lst.append(int(str(s)+str(i)))
        que.append(int(str(s)+str(i)))
print(lst[K-1])

Measured memory_bytes: 49624
package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		cnt := 0
		// 37以上のとき組み合わせは存在しないが省くのめんどくさいのでまとめて計算
		for a:=0; a<=9; a++{
			for b:=0; b<=9; b++{
				for c:=0; c<=9; c++{
					for d:=0; d<=9; d++{
						if a+b+c+d==n{
							cnt++
						}
					}
				}
			}
		}
		fmt.Println(cnt)
	}
}

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

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 1056
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <limits>

int main( void ) {
    int n;
    std::cin >> n;

    std::vector< int > ss;

    for( size_t i = 0; i < n; ++i ) {
        int s;
        std::cin >> s;
        ss.push_back( s );
    }

    // 結局全てを足したとして、3つのケースしか生じない
    // X: 10の倍数の数しかなかった
    //   このときどんなことをしても10の倍数しかないため出力は0
    // Y-A: 全合計値が10の倍数であった
    //   このときは、一番小さい10の倍数ではない数を引けば10の倍数ではなくなるのでこれを出す
    // Y-B: 全合計値は10の倍数ではなかった
    //   このときはそのまま採用すればよい

    const int sum = std::accumulate( ss.begin(), ss.end(), 0 );

    int min = std::numeric_limits<int>::max();  // 番兵
    for( size_t i = 0; i < ss.size(); ++i ) {
        if( ss[ i ] % 10 == 0 ) continue;
        min = std::min( min, ss[ i ] );
    }

    if( min == std::numeric_limits<int>::max() ) {
        // 全ての点数が10の倍数だったので0しか出せない
        std::cout << 0 << std::endl;
    } else if( sum % 10 == 0 ) {
        // 全ての点数の合計が10の倍数だったので
        // どれか1つ10の倍数でない小さな数を引くことで
        // 次点として小さな数を探す
        std::cout << sum - min << std::endl;
    } else {
        // 合計値が10の倍数でなかったのでこれが最大値
        std::cout << sum << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
#define n_max 1000

int h[n_max];

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

    double min_dif = 1 << 29;
    int min_dif_ind = 0;

    for(int i = 0; i < n; i++){
        if(abs(a - (t - h[i] * 0.006)) < min_dif){
            min_dif = abs(a - (t - h[i] * 0.006));
            min_dif_ind = i;
        }
    }
    cout << min_dif_ind + 1;
    return 0;
}

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

int main() {
    string s, t;
    int cnt = 0;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3916
import Foundation

func isFull(_ s: String) -> Bool {
  var c: Int = 0
  for si in s {
    switch si {
    case "(": c += 1
    case ")" where c < 1 : return false
    case ")": c -= 1
    default:  break
    }
  }
  return c == 0
}

func suffix(_ s: String, e: Character) -> Int {
  let a = Array(s)
  var c = 0
  for i in 0..<a.count {
    if a[a.count - i - 1] == e {
      c += 1
    } else {
      return c
    }
  }
  return c
}

let nl = readLine()!.split(separator: " ").map { Int($0)! }
let n = nl[0]
var l = [(String, Int, Int)]()
var r = [(String, Int, Int)]()
for _ in (0..<n) {
  let si = readLine()!
  let ai = si.prefix { $0 == ")" }.count - si.prefix { $0 == "(" }.count
  let bi = suffix(si, e: "(") - suffix(si, e: ")")
  if bi - ai >= 0 {
    l.append((si, ai, bi))
  } else {
    r.append((si, ai, bi))
  }
}

l.sort { $0.1 < $1.1 }
r.sort { $0.2 > $1.2 }
print("\(isFull(l.map{$0.0}.joined() + r.map{$0.0}.joined()) ? "Yes": "No")")

Measured memory_bytes: 54668
#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MSIZE = 3003;
const long long mod = 1e9 + 7;

long long dp[MSIZE][MSIZE];

long long fact[MSIZE];
long long invf[MSIZE];

long long fastPow(long long a, long long p) {
    long long ans = 1;
    while (p) {
        if (p & 1) {
            ans *= a;
            ans %= mod;
        }
        a *= a;
        a %= mod;
        p >>= 1;
    }
    return ans;
}

void Init() {
    fact[0] = 1;
    invf[0] = 1;
    for (int i = 1; i < MSIZE; i++) {
        fact[i] = fact[i - 1] * i % mod;
        invf[i] = fastPow(fact[i], mod - 2);
    }
}

long long C(int n, int m) {
    if (m > n) return 0;
    return (fact[n] * invf[m] % mod) * invf[n - m];
}

long long pref[MSIZE];

long long Sum(int l, int r) {
    return (mod + pref[r] - (l ? pref[l - 1] : 0LL)) % mod;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Init();
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    for (int i = 0; i < n; i++) {
        dp[0][i] = 1;
    }
    

    for (int i = 1; i < n; i++) {
        memcpy(pref, dp[i - 1], sizeof pref);
        for (int j = 1; j < n; j++) {
            pref[j] += pref[j - 1];
            pref[j] %= mod;
        }

        if (s[i - 1] == '<') {
            for (int j = 0; j < n - i; j++) {
                dp[i][j] = Sum(0, j);
            }
        } else {
            for (int j = 0; j < n - i; j++) {
                if (n - i - j - 1 >= 0) dp[i][n - i - j - 1] = Sum(n - i - j, n - i);
            }
        }
    }
    cout << dp[n - 1][0] << endl;
}

Measured memory_bytes: 70016
n  = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1,n-1):
    p_1 = p[i-1]
    p_2 = p[i]
    p_3 = p[i+1]
    if p_1 < p_2 < p_3 or p_1 > p_2 > p_3:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>


int main(){
    int a,b;
    std::cin >> a >> b;
    if(a>b) std::swap(a,b);
    if(a==1&&b==2)std::cout << 3;
    if(a==2&&b==3)std::cout << 1;
    if(a==1&&b==3)std::cout << 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007
 
int N,M,Q;
vector<int> a,b,c,d;
ll ans = 0;
 
void DFS(vector<int> &V){
    if(V.size()==N+1){
        ll tmp = 0;
        rep(i,Q){
            if(V[b[i]]-V[a[i]]==c[i]){
                tmp += d[i];
            }
        }
        ans = max(ans,tmp);
        return;
    }else{
        int tail = V.back();
        for(int i=tail;i<=M;i++){
            V.push_back(i);
            DFS(V);
            V.pop_back();
        }
    }
}
int main(){
    cin >> N >> M >> Q;
    rep(i,Q){
        int a_,b_,c_,d_;
        cin >> a_ >> b_ >> c_ >> d_;
        a.push_back(a_);
        b.push_back(b_);
        c.push_back(c_);
        d.push_back(d_);
    }
    vector<int> V(1,1);
    DFS(V);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>a>>b;
    printa((a-1)*(b-1));
    return 0;
}

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

ll ans;
int n,m,p[10005];
vector<pair<ll,pair<int,int>>>E;

int find(int x) {
	return (p[x]==x?x:find(p[x]));
}

int main() {
	cin>>n>>m;
	for (int i=0;i<n;i++) p[i]=i;
	for (int i=0;i<m;i++) {
		int u,v,w; cin>>u>>v>>w;
		E.push_back({w,{u,v}});
	}
	sort(E.begin(),E.end());
	for (auto i:E) {
		int x=find(i.ss.ff) , y=find(i.ss.ss);
		if (x!=y) {
			ans+=i.ff;
			p[y]=x;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 4968
n = int(input())
a = list(map(int, input().split()))
b = a[n:2*n]

import heapq

q = a[:n]
heapq.heapify(q)

res = [0]*(n+1)
res[0] = sum(q)
for i, x in enumerate(b):
    heapq.heappush(q, x)
    y = heapq.heappop(q)
    res[i+1] = res[i]+x-y

b.reverse()
q = [-x for x in a[2*n:]]
heapq.heapify(q)
s = -sum(q)
res[-1] -= s

for i, x in enumerate(b):
    heapq.heappush(q, -x)
    y = heapq.heappop(q)
    s += x+y
    res[-2-i] -= s

print(max(res))


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

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> m[i];
    X-=m[i];
  }
  sort(m.begin(),m.end());
  int ans = N-1;
  while (0<=X) {
    ans++;
    X-=m[0];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
  int H, A;
  cin >> H >> A;
  int ans = H / A;
  if (H % A != 0)
    ans++;
  cout << ans << endl;
  return 0;
}

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

int calc_ans(string x,string y){
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++){  //文字列もaから+していけば走査できる
    bool found_x = false,found_y = false;
    
    for (int i = 0; i < x.size(); i++){
      if(x[i]==c)found_x = true;
    }
    for (int i = 0; i < y.size(); i++){
      if(y[i]==c)found_y = true;
    }
    
    if(found_x && found_y)ans++;
  }
  return ans;  
}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans=0;

  for (int i = 0; i < N; i++){
    int tmp_ans = 0;
    string X,Y;
    X = S.substr(0,i);
    Y = S.substr(i);

    tmp_ans = calc_ans(X,Y);
    //cout << ans;
    ans = max(ans,tmp_ans);
  }
    
  cout << ans << endl;
}

/*
解説放送見た擬似コードで実装
☆ 文字列の分割 → ！！！substr！！！
Aの値を大きい方に更新 → A = max(A,temp_A)
文字列strもcharをaから始めてインクリメントすることで全探索できる！

*/

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    sc.close();

    String ans = null;
    for (long i = -1000; ans == null && i <= 1000; i++)
      for (long j = -1000; ans == null && j <= 1000; j++)
        if (i * i * i * i * i - j * j * j * j * j == X)
          ans = i + " " + j;
    System.out.println(ans);
  }
}


Measured memory_bytes: 38780
#include<bits/stdc++.h>
#define int        long long
#define MOD        1000000007
#define MAX        100005
#define pb         push_back
#define mp         make_pair
#define pii        pair<int,int>
#define mii        map<int,int>
#define vi         vector<int>
#define ff         first
#define ss         second
#define T          int t;cin>>t;while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define umi        unordered_map<int,int>
#define maxheap    priority_queue<int>
#define minheap    priority_queue<int,vector<int>,greater<int> >
#define inp(n)     for(int i=0;i<n;i++)
#define N          200005
#define mxN		   2000005
#define all(v)		v.begin(),v.end()
#define lb(v,val)  (int)(lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (int)(upper_bound(v.begin(),v.end(),val)-v.begin())
using namespace std;
using namespace std::chrono;

int v[N];

void solve(){
	int x;
	cin >> x;
	int ans = 1000*(x/500);
	x%=500;
	ans += x/5*5;
	cout << ans;
}

signed main(){
/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif   */
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int t = 1,tt=0; 
	//cin >> t;
	while(t--){
	tt++;
	//cout << "Case #" <<tt<<": ";
	solve(); 
	cout << "\n";
	}
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

void solve(long long N) {
  vector<vector<long long>> num(10, vector<long long>(10, 0));
  LL res = 0;

  for (int i = 1; i <= N; i++) {
    vector<int> d;
    int nn = i;
    while (nn) {
      d.push_back(nn % 10);
      nn /= 10;
    }

    int a = d[0];
    int b = d.back();

    if (!a || !b) continue;
    num[a][b]++;
  }

  for (int a = 1; a < 10; a++) {
    for (int b = 1; b < 10; b++) {
      res += num[a][b] * num[b][a];
    }
  }

  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
n,l=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
j=-1
0.upto(a.size-2){|i|
  (j=i;break)if a[i]>=l
  (j=i;break)if a[i]+a[i+1]>=l
  }
puts "Impossible" or exit if j==-1
if j==n-1
  j-=1
end
puts "Possible"
0.upto(j-1){|i| puts i+1}
(n-2).downto(j+1){|i| puts i+1}
puts j+1

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

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

N, M = [int(x) for x in input().split()]
city = []

for n in range(M):
    P, Y = [int(x) for x in input().split()]
    city.append([n, P, Y])
city = np.array(city)
city = city[np.argsort(city[:, 2])]
counts = np.array([1]*N)

city2 = []

for n in range(M):
    city2.append([city[n, 0], city[n, 1], city[n, 2], counts[city[n, 1]-1]])
    counts[city[n, 1]-1] += 1

city2 = np.array(city2)
city2 = city2[np.argsort(city2[:, 0])]
for c in city2:
    print(str(c[1]).zfill(6) + str(c[3]).zfill(6))


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

using namespace std;
typedef long long LL;

const int MAXN = 123456;
int presum[MAXN * 3][2];
char s[MAXN * 3];

int main() {
    int N;
    scanf("%d", &N);
    scanf("%s", s + 1);
    for (int i = 1; i <= N; i++) {
        presum[i][0] = presum[i - 1][0];
        presum[i][1] = presum[i - 1][1];
        if (s[i] == 'E') presum[i][0]++;
        else presum[i][1]++;
    }
    int ans = N - 1;
    for (int i = 1; i <= N; i++) {
        int toF = presum[N][1] - presum[i][1];
        int toB = presum[i - 1][0];
        int sum = (N - i - toF) + (i - 1 - toB);
        ans = min(ans, sum);
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
  int N, M, C; cin >> N >> M >> C;

  vector<int> B( M );
  rep( i, 0, M ) cin >> B.at( i );

  vector<vector<int>> A( N, vector<int>( M ) );
  rep( i, 0, N ) {
    rep( j, 0, M ) cin >> A.at( i ).at( j );
  }

  vector<int> Hantei( N, 0 );

  rep( i, 0, N ) {
    rep( j, 0, M) {
      Hantei.at( i ) += A.at( i ).at( j ) * B.at( j );
    }
  Hantei.at( i ) += C;
  }

  int Ans = 0;
  rep( i, 0, N ) {
    if ( Hantei.at( i ) > 0 ) Ans++;
  }

  cout << Ans << endl;
}


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

int main() {
  int N, M; cin >> N >> M;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> AB;
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    AB.push(make_pair(a, b));
  }
  priority_queue<int> pq;
  long long ans = 0;
  for (int i = 1; i <= M; i++) {
    while (1) {
      if (AB.top().first != i || AB.empty()) break;
      pq.push(AB.top().second);
      AB.pop();
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1908
# D
s = str(input())
RLlist = []
i = 0
length = len(s)
Rcount=0
Lcount=0
RLplace=-1
ans = [0 for i in range(length)]
while i < length:
    Rcount=0
    while i < length and s[i] == 'R':
        Rcount+=1
        i+=1
    if i < length and s[i] == 'L':
        RLplace = i-1
        Lcount=0
    while i < length and s[i] == 'L':
        Lcount+=1
        i+=1
    RLlist.append((RLplace, Rcount, Lcount))

for t in RLlist:
    if t[1]%2 == 0 and t[2]%2 == 0:
        ans[t[0]]+=(t[1]//2 + t[2]//2)
        ans[t[0]+1]+=(t[1]//2 + t[2]//2)
    elif t[1]%2 != 0 and t[2]%2 == 0:
        ans[t[0]]+=(t[1]//2 + 1 + t[2]//2)
        ans[t[0]+1]+=(t[1]//2 + t[2]//2)
    elif t[1]%2 == 0 and t[2]%2 != 0:
        ans[t[0]]+=(t[1]//2 + t[2]//2)
        ans[t[0]+1]+=(t[1]//2 + 1 + t[2]//2)
    else:
        ans[t[0]]+=(t[1]//2 + 1 + t[2]//2)
        ans[t[0]+1]+=(t[1]//2 + 1 + t[2]//2)
print(*ans ,sep=' ')

Measured memory_bytes: 53388
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  char s[MAX];
  scanf("%d", &n);
  scanf("%s", s);
  rep(i, 0, strlen(s)) s[i] = (char) (((int)s[i] + n - 65) % 26 + 65);
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 128
function main(input) {
    r = input.filter((i) => {return parseInt(i,10) <= 9})
    if(r.length == 2) {
        console.log(parseInt(input[0],10)*parseInt(input[1],10))
    }else{
        console.log("-1")
    }
}

const input  = require('fs').readFileSync("/dev/stdin","utf8").split("\n")[0].split(" ")
main(input)

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int a[maxn],n,temp,vis[maxn];
ll k;
vector<int>v1,v2;
int main()
{
    cin>>n>>k;
    For(i,1,n)
    {
        cin>>temp;
        a[i]=temp;
    }
    ll cur=1,cnt1=0,cnt2=0;
    vis[1]=1;cur=a[cur];
    while(1)
    {
        //next=a[cur];
        if(vis[cur]==1)v2.push_back(cur),cnt2++;
        v1.push_back(cur);
        vis[cur]++;
        if(vis[cur]>2)
        {
            v2.pop_back();v1.pop_back();
            break;
        }
        cnt1++;
        cur=a[cur];
    }
    //cout<<cnt1<<' '<<cnt2<<endl;
    if(k<=cnt1)cout<<v1[k-1]<<endl;
    else
    {
        //For(i,0,2)cout<<v2[i]<<' ';
       // cout<<endl;
        ll pos=(k-cnt1-1)%cnt2;
        ll ans=v2[pos];
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> v(2, vector<int>(n, 0));
	
	for (int i = 0; i < n; ++i)
		cin >> v[0][i];

	for (int i = 0; i < n; ++i)
		cin >> v[1][i];

	vector<vector<int>> dp(2, vector<int>(n, 0));
	dp[0][0] = v[0][0];
	for (int i = 1; i < n; ++i)
		dp[0][i] = dp[0][i - 1] + v[0][i];
	dp[1][0] = v[1][0] + dp[0][0];

	for (int i = 1; i < n; ++i)
		dp[1][i] = max(dp[0][i], dp[1][i - 1]) + v[1][i];
	cout << dp[1][n - 1]; 
}		

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

int main() {
	map<char, long long int> mp;
	long long int N, count = 0;
	string S;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		mp[S[0]]++;
	}
	long long int M = mp['M'], A = mp['A'], R = mp['R'], C = mp['C'], H = mp['H'];
	count += M * A * (R + C + H);
	count += (M + A) * R * (C + H);
	count += (M + A + R) * C * H;
	cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	for (int i = K; i < N; ++ i) {
		if (A[i-K] < A[i]) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define endl			"\n"
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <ll,ll>
#define vii				vector <ii>
#define ull				unsigned long long
const double PI = 2 * acos(0.0);
void run() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
}

int main() {

	run();
	ll a, b;
	cin >> a >> b;
	cout << a * b / __gcd(a, b);
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
P=list(map(int,input().split()))
from collections import deque
smin,smax=deque(),deque()
x,r,r2=0,0,0
for i,p in enumerate(P):
    while len(smin)>0 and P[smin[-1]]>p:
        smin.pop()
    smin.append(i)
    if smin[0]<=i-K:
        smin.popleft()
    while len(smax)>0 and P[smax[-1]]<p:
        smax.pop()
    smax.append(i)
    if smax[0]<=i-K:
        smax.popleft()
    if i>0 and P[i-1]<P[i]:
        x=min(x+1,K-1)
    else:
        x=0
    if i==K-1 or (i>=K and not (P[i-K]<P[smin[0]] and smax[0]==i)):
        if x!=K-1:
            r+=1
        else:
            r2=1
print(r+1 if r2 else r)

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

int euclid(int a, int b) {
	int r = b, s = a;
	while (r != 0) {
		int dum = r;
		r = s % r;
		s = dum;
	}
	return s;
}

int main() {
	int A, B;
	cin >> A >> B;
	int64_t a = A, b = B;
	int r = euclid(A,B);

	cout << a*b/r << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv){
    long long int N;
    cin >> N;
    long long int ans = 0;
    for (long long int i=1; i*i<N; i++){
        if ((N % i == 0) && (N / i - i >= 2)) ans += N / i - 1;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;

int main()
{
    int N,M;
    cin >> N >> M;
    int A[N][N] = {};
    for (int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        A[a-1][b-1] = 1;
        A[b-1][a-1] = 1;
    }

    int B[N-1];
    for (int i=2; i <= N; i++){
        B[i-2] = i;
    }
    int ans = 0;
    do {
        int c = 1;
        if (A[0][B[0]-1] == 0) {
            c = 0;
        }
        for (int i = 0; i < N-2; i++) {
            if (A[B[i]-1][B[i+1]-1] == 0 || c == 0){
                c = 0;
                break;
            }
        }
        if (c == 1) {
            ans++;
        }
    } while(next_permutation(B,B+N-1));
    cout << ans << endl;

}


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

int main(void) {

	long long int H, N;
	cin >> H >> N;
	
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	// 全部足す
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}

	if (H > sum) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	ll n, k;
	cin >> n >> k;
	V<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	V<bool> seen(n, false);

	V<ll> loop = { 0 };
	seen[0] = true;
	int i = 0;

	while (true) {
		i = a[i];
		if (!seen[i]) {
			seen[i] = true;
			loop.emplace_back(i);
		}
		else break;
	}


	rep(j, loop.size()) {
		if (loop[j] == i) {
			i = j;break;
		}
	}

	if (k < loop.size()) {
		cout << loop[k] + 1 << endl;
		return 0;
	}
	
	k -= i;
	k %= (ll)loop.size() - i;
	cout << loop[i + k] + 1 << endl;

}

Measured memory_bytes: 6960
#include <iostream>

using namespace std;

int main(void){
    int N, T;
    cin >> N >> T;
    int c[N];
    int t[N];
    int ans = 0;
    int min = T;
    int cost = 10000;

    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];
        if(min >= t[i] && cost >= c[i]){
            ans = c[i];
            cost = c[i];
        }
    }
    if(ans == 0)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#バブルソート
number=eval(input())
swap=0
arr=list(map(int, input().split(' ')))
for i in range(0,number-1):
    j=number-1
    while j>i:
        if arr[j]<arr[j-1]:
            arr[j],arr[j-1]=arr[j-1],arr[j]
            swap+=1
        j-=1

print(' '.join(map(str, arr)))
print(swap)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
map <string, int> mp;
int main(){
    int n, ans = 0;
    scanf("%d", &n);
    while(n--) {
        string s;
        cin >> s;
        if(!mp[s]) ans++;
        mp[s] = 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 19308
sumOfDigitp :: Int -> Int -> Int
sumOfDigitp total 0 = total
sumOfDigitp total n = sumOfDigitp (total + r) q
  where
    q = n `div` 10
    r = n `mod` 10

sumOfDigit :: Int -> Int
sumOfDigit = sumOfDigitp 0

func :: Int -> Int
func n = case np of
  1 -> 10
  otherwise -> np
  where
    np = sumOfDigit n

main = do
  line <- getLine
  let
    n = read line :: Int
    ans = func n
  putStrLn $ show ans


Measured memory_bytes: 508
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

vector<int> graph[200001], group[200001];
vector<pii> ans;
int scc[200001], sccnumber, dfsn[200001], dfsnumber, finished[200001];
stack<int> s;

int dfs(int node)
{
    dfsn[node] = ++dfsnumber;
    s.push(node);

    int topmost = dfsn[node];
    for (int i = 0; i < graph[node].size(); i++)
    {
        if (!dfsn[graph[node][i]])
            topmost = min(topmost, dfs(graph[node][i]));
        else if (!finished[graph[node][i]])
            topmost = min(topmost, dfsn[graph[node][i]]);
    }

    if (topmost == dfsn[node])
    {
        int t;
        sccnumber++;
        while (true)
        {
            t = s.top();
            s.pop();
            finished[t] = true;
            scc[t] = sccnumber;
            group[sccnumber].push_back(t);
            if (t == node)
                break;
        }
    }

    return topmost;
}

int main(void)
{
	int n, m, a, b;
	scanf("%d %d", &n, &m);
    while (m--)
    {
        scanf("%d %d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    for (int i = 1; i <= n; i++)
        if (!dfsn[i])
            dfs(i);

    int ans = 0;
    for (int i = 1; i <= sccnumber; i++)
        ans = max(ans, (int)group[i].size());
    printf("%d", ans);
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int c=0;
  int s=1;
  while(true) {
    s=a.at(s-1);
    c++;
    if(s==2) {
      cout<<c<<endl;
      break;
    }
    if (b.at(s-1)==1) {
      cout<<"-1"<<endl;
      break;
    }
    b.at(s-1)=1;
  }
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main()
{
  int n,k,ans;
  scanf("%d %d",&n,&k);
  if(k==1)
  {
    printf("0");
    return 0;
  }
  ans=n-k;
  printf("%d",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	
	string a,b,c; int x,y; cin >> a >> b >> x >> y >> c;
	if(a == c) cout << x-1 << " " << y;
	else cout << x << " " << y-1;

	return 0;
}

Measured memory_bytes: 256
char s[9];
a[99];
main(){
	scanf("%*d");
	while(scanf("%s",s)+1){
		a[s[0]]++;
	}
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", a[65], a[87], a[84], a[82]);
	return 0;
}


Measured memory_bytes: 1696
import java.util.*;

class Main{

    int n;
    void solve(){
	Scanner sc = new Scanner(System.in);
	while(true){
	    n = sc.nextInt();
	    if(n==0) break;

	    int[][] p = new int[n][n];
	    for(int i=0; i<n ;i++){
		int m = sc.nextInt();
		for(int j=0; j<m; j++){
		    int num = sc.nextInt();
		    p[i][num-1] = 1;
		}
	    }
	    int k = sc.nextInt();
	    int[] klist = new int[k];
	    for(int i=0; i<k; i++){
		klist[i] = sc.nextInt();
	    }

	    int ans = -1; 
	    for(int i=0; i<n; i++){
		boolean boo = true;
		for(int j=0; j<k; j++){
		    if(p[i][klist[j]-1]==0){
			boo = false;
			break;
		    }
		}
		if(boo && ans==-1)ans = i;
		else if(boo && ans!=-1){
		    ans = -1;
		    break;
		}
	    }
	    if(ans+1==0)ans = -2;
	    System.out.println(ans+1);
	}
    }
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define maxn 1010
using namespace std;
typedef long long ll;
ll n,m,a[maxn],b[maxn],c[maxn];
ll sm(bool f1,bool f2,bool f3)
{
	vector<ll> v;
	for(ll i=0;i<n;i++)
	{
		ll tmp=0;
		if(f1)
			tmp+=a[i];
		else
			tmp-=a[i];
		if(f2)
			tmp+=b[i];
		else
			tmp-=b[i];
		if(f3)
			tmp+=c[i];
		else
			tmp-=c[i];
		v.push_back(tmp);
	}
	sort(v.rbegin(),v.rend());
	ll sum=0;
	for(ll i=0;i<m;i++)
		sum+=v[i];
	return sum;
}
int main()
{
	cin>>n>>m;
	for(ll i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll res=-1;
	res=max(res,max(sm(0,0,0),max(sm(0,0,1),max(sm(0,1,0),max(sm(1,0,0),max(sm(1,1,0),max(sm(1,0,1),max(sm(0,1,1),sm(1,1,1)))))))));
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
M = 10**9 + 7
s = int(input())

f = [1]
for i in range(1, s - 2):
  f.append(f[-1] * i % M)

r = 0
for k in range(s // 3):
  t = s - 2 * k - 3
  r += f[t] * pow(f[k], M - 2, M) * pow(f[t - k], M - 2, M)

print(r % M)


Measured memory_bytes: 9028
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func QuickSortInt(s []int) []int {
	if len(s) <= 1 {
		return s
	}
	if len(s) == 2 {
		if s[0] > s[1] {
			return []int{s[1], s[0]}
		}
		return s
	}
	head := 0
	tail := len(s) - 1
	var base int
	if s[0] > s[1] {
		base = s[0]
	} else {
		base = s[1]
	}
	leftFound := false
	rightFound := false
	for head <= tail {
		if !leftFound {
			if base <= s[head] {
				leftFound = true
			} else {
				head++
			}
		}
		if !rightFound {
			if base >= s[tail] {
				rightFound = true
			} else {
				tail--
			}
		}
		if leftFound && rightFound {
			s[head], s[tail] = s[tail], s[head]
			leftFound = false
			rightFound = false
			head++
			tail--
		}
	}
	return append(QuickSortInt(s[0:head]), QuickSortInt(s[head:])...)
}

func QuickSortBytes(s []byte) []byte {
	if len(s) <= 1 {
		return s
	}
	if len(s) == 2 {
		if s[0] > s[1] {
			return []byte{s[1], s[0]}
		}
		return s
	}
	head := 0
	tail := len(s) - 1
	var base byte
	if s[0] > s[1] {
		base = s[0]
	} else {
		base = s[1]
	}
	leftFound := false
	rightFound := false
	for head <= tail {
		if !leftFound {
			if base <= s[head] {
				leftFound = true
			} else {
				head++
			}
		}
		if !rightFound {
			if base >= s[tail] {
				rightFound = true
			} else {
				tail--
			}
		}
		if leftFound && rightFound {
			s[head], s[tail] = s[tail], s[head]
			leftFound = false
			rightFound = false
			head++
			tail--
		}
	}
	return append(QuickSortBytes(s[0:head]), QuickSortBytes(s[head:])...)
}


func init() {
	// read one word/char/int separated by space(s).
	sc.Split(bufio.ScanWords)

	// read one line.
	// sc.Split(bufio.ScanLines)
}

func main() {
	N := nextInt()
	m := map[string]int{}
	for i := 0; i < N; i++ {
		str := nextStr()
		m[string(QuickSortBytes([]byte(str)))]++
	}
	ans := 0
	for _, v := range m {
		ans += v*(v-1) / 2
	}
	fmt.Println(ans)
}

Measured memory_bytes: 9856
#include<map>
#include<set>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 5010
#define int long long
#define mod 1000000007
#define debug cerr<<__LINE__<<" "<<__FUNCTION__<<"\n"

inline int read(){
    int x=0,y=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')y=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*y;
}
void put(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar((x%10)+48);
}
int n,siz[N],f[N][N],g[N];
int tot,head[N];
struct{
	int nxt,to;
}edge[N<<1];
inline void add(int u,int v){
	edge[++tot].nxt=head[u];
	edge[tot].to=v;
	head[u]=tot;
}
int tmp[N];
void dfs(int x,int fa){
	siz[x]=1;f[x][1]=1;
	for(int i=head[x];i;i=edge[i].nxt){
		if(edge[i].to==fa) continue;
		dfs(edge[i].to,x);
		for(int j=1;j<=siz[x]+siz[edge[i].to];j++) tmp[j]=0;
		for(int j=1;j<=siz[x];j++){
			for(int k=1;k<=siz[edge[i].to];k++){
				tmp[j]=(tmp[j]-f[x][j]*f[edge[i].to][k]%mod*g[k]%mod)%mod;
				tmp[j+k]=(tmp[j+k]+f[x][j]*f[edge[i].to][k]%mod)%mod;
			}
		}
		siz[x]+=siz[edge[i].to];
		for(int j=1;j<=siz[x];j++) f[x][j]=tmp[j];
	}
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1,u,v;i<n;i++){
		u=read();v=read();
		add(u,v);add(v,u);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=(i-1)*g[i-2]%mod;
	dfs(1,0);
//	for(int i=1;i<=n;i++){
//		for(int j=0;j<=n;j++) cerr<<f[i][j]<<" ";
//		cout<<"\n";
//	}
	int ans=0;
	for(int i=1;i<=n;i++) ans=(ans+f[1][i]*g[i]%mod)%mod;
	cout<<(ans+mod)%mod<<"\n";
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


Measured memory_bytes: 195072
#!/usr/bin/env python3
import sys

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def solve(A: int, B: int):
    A = set(prime_factorize(A))
    B = set(prime_factorize(B))

    print(len(A & B) + 1)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

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();
        int d = sc.nextInt();

        if((Math.abs(c-a) <= d)||(Math.abs(b-a) <= d && Math.abs(c-b) <= d)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24020