akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

int main() {
  int n;
  cin>>n;
  set<string> s;
  set<string>::iterator it;
  char query[5]; string str;
    
  for(int i=0; i<n; i++) {
    scanf("%s", query);
    if(query[0] == 'i') {
      cin >> str;
      s.insert(str);
    }
    else {
      cin >> str;
      it = s.find(str);
      if(it == s.end()) cout << "no" << endl;
      else cout << "yes" << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 32652
K = int(input())
if K % 7 == 0:
    L = 9 * K / 7
else:
    L = 9 * K
if K % 2 == 0 or K % 5 ==0:
    ans = -1
else:
    ans = 1
m = 10 % L
while(ans >= 0):
    if (m == 1):
        break
    m *= 10
    m %= L
    ans += 1
print(ans)
















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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> tmp(n);
    rep(i, n){
        cin >> v.at(i);
        tmp.at(i) = v.at(i);
    }
    sort(all(tmp), greater<int>());

    rep(i, n) {
        if(v.at(i) >= tmp.at(n/2 -1)){
            cout << tmp.at(n/2) << endl;
        }else{
            cout << tmp.at(n/2 - 1) << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
int n, x, y, g[2001][2001], ans[2000] = {};
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans[min(j - i, max(x, i) - min(x, i) + max(y, j) - min(y, j) + 1)]++;
    }
  }
  for (int i = 1; i < n; i++) {
    printf("%d\n", ans[i]);
  }
}

Measured memory_bytes: 128
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    val n = readI()
    val aa = readIs()
    var x = 0L
    var a0 = aa[0]
    for (i in 1 until n) {
        val d = a0 - aa[i]
        if (0 < d) {
            x += d
        } else {
            a0 = aa[i]
        }
    }
    println(x)
}



Measured memory_bytes: 65104
import java.util.Scanner;

/**
 * A - Five Variabless
 * 変数xのうち、すぬけくんが0を代入した変数はどれか
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );

        for( int i = 0; i < 5; i++ ) {
            int x = sc.nextInt();
            if( x == 0 ) {
                System.out.println( i + 1 );
                break;
            }
        }

        sc.close();
    }
}


Measured memory_bytes: 35688
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut t = 1;
    let mut c:usize = 0;
    let mut r:[usize;2020] = [0;2020];
    for i in (0..s.len()).rev() {
        let x = (s[i as usize] as usize)-48;
        c = (c+x*t)%2019;
        r[c] += 1;
        t = (t*10)%2019;
    };
    c = 0;
    for i in 0..2019 {
        if &1 < &r[i] {
            c += (r[i]-1)*r[i]/2
        };
    };
    c += r[0];
    println!("{}", c);
}

Measured memory_bytes: 3032
N,X = map(int,input().split())
a=[1]
p=[1]
for i in range(1,N+1):
    a.append(a[i-1]*2+3)
    p.append(p[i-1]*2+1)
    
def f(n,x):#レベルnのハンバーガーをx段食べる
    if n ==0:#0段目の終了条件
        return 0 if x <=0 else 1

    if x <= 1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(N,X))


Measured memory_bytes: 9136
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type Edge struct {
	To   int
	Cost int
}

func main() {
	sc.Split(bufio.ScanWords)
	L, _ := strconv.Atoi(read())
	V := 1
	for ; (1 << uint(V)) <= L; V++ {
	}
	es := make([][]Edge, V)
	for i := 0; i < V-1; i++ {
		es[i] = make([]Edge, 0)
		es[i] = append(es[i], Edge{i + 1, 0}, Edge{i + 1, 1 << uint(i)})
	}
	for i := 0; i < V-1; i++ {
		if L&(1<<uint(i)) != 0 {
			tmp := (1 << 30) - 1
			tmp ^= (1 << uint(i+1)) - 1
			es[i] = append(es[i], Edge{V - 1, L & tmp})
		}
	}
	E := 0
	for _, e := range es {
		E += len(e)
	}
	fmt.Printf("%d %d\n", V, E)
	for i := 0; i < V; i++ {
		for _, e := range es[i] {
			fmt.Printf("%d %d %d\n", i+1, e.To+1, e.Cost)
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    int ans = INF;
    for(int num = -100; num <= 100; num++)
    {
        int cost = 0;
        for(int i = 0; i < n; i++)
        {
            cost += pow(abs(num - A[i]), 2);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<set<int>>;

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

int main() {
    double A, B, H, M; cin >> A >> B >> H >> M;

    double sinH = A*sin((pi/6.0)*H + (pi/360.0)*M);
    double cosH = A*cos((pi/6.0)*H + (pi/360.0)*M);

    double sinM = B*sin((pi/30.0)*M);
    double cosM = B*cos((pi/30.0)*M);

    double dist = pow(sinH - sinM, 2) + pow(cosH - cosM, 2);

    cout << std::fixed << std::setprecision(15) << sqrt(dist) << endl;
}


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

namespace CS_AtCoder {
	class Program {
		static void Main(string[] args) {
			new Calc().Solve();
		}
	}
	public class Calc {
		Scan cin = new Scan();
		public void Solve() {
			var N = cin.ReadInt();
			var a = cin.ReadLine().Split(' ').Select(long.Parse).ToList();
			var sum = a.Sum();
			long nSum = a[0];
			long min = 100000000;
			if (N == 2) {
				Math.Abs(a[0] - a[1]).WL();
				return;
			}
			for (int i = 1; i <N-1; i++) {
				var kSum = sum - nSum;
				min = Math.Min(min, Math.Abs(nSum - kSum));
				nSum += a[i];
			}
			min.WL();
			return;
		}


	}

	public class Scan {
		public Scan() { }
		public int ReadInt() => int.Parse(Console.ReadLine());
		public int[] ReadInt(char separator) => Console.ReadLine().Split(separator).Select(int.Parse).ToArray();
		public double ReadDouble() => double.Parse(Console.ReadLine());
		public double[] ReadDouble(char separator) => Console.ReadLine().Split(separator).Select(double.Parse).ToArray();
		public long ReadLong() => long.Parse(Console.ReadLine());
		public long[] ReadLong(char separator) => Console.ReadLine().Split(separator).Select(long.Parse).ToArray();
		public string ReadLine() => Console.ReadLine();
		public string[] ReadLine(char separator) => Console.ReadLine().Split(separator).ToArray();
	}
	public static class Utils {
		public static string Docking<T>(this IEnumerable<T> collection,Func<T,string> filter = null) {
			StringBuilder sb = new StringBuilder();
			long Length = collection.Count();
			foreach (var item in collection.Select((v, i) => new { V = v, I = i })) {
				sb.Append(filter != null ? filter(item.V) : item.V.ToString());
			}
			return sb.ToString();
		}
		public static void WL(this object obj) => Console.WriteLine(obj);
		public static int IntParse(this string s) => int.Parse(s);
		public static int IntParse(this char c) => c - '0';
		public static List<int> SieveOfEratosthenes(int max) {
			int prime;
			double sqMax = Math.Sqrt(max);
			var prList = new List<int>();
			var srList = new List<int>();
			for (int i = 2; i < max+1; i++) {
				srList.Add(i);
			}
			do {
				prime = srList[0];
				prList.Add(prime);
				srList.RemoveAll(x => x % prime == 0);
			} while (prime<sqMax);
			prList.AddRange(srList);
			return prList;
		}
		public static long NCR(int n,int r) {
			long p = 1;
			for (int i = 1; i <=r; i++) {
				p = p * (n - i + 1) / i;
			}
			return p;
		}
	}
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 200000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cout << "The value of " << #val << " is = " << val << endl;
#define testing cout << "--------------------------\n";

ll n,k,a[200005];

bool can(ll x) {
	ll sum=0;
	if(x==0) return 0;
	for(int i = 0; i < n; i++) {
		sum+=(a[i]+x-1)/x-1;
	}
	return (sum<=k);
}

int main() {
	IOS
	cin>>n>>k;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	ll l=1,r=mod;
//	cout<<can(4)<<endl;
	while(l<=r) {
		ll m=(l+r)/2;
		if(can(m)) {
			if(!can(m-1)) {
				cout<<m<<endl;
			}
			r=m-1;
		} else {
			l=m+1;
		}
	}
}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
int main(){
  long double n,k;
  cin >> n >> k;
  long double ans=0;
  long double w=1,j;
  for(long double i=1;i<=n;i=i+1){
    j=i;
    while(j<k){
      j=j*2;
      w=w*2;
    }
    ans+=1/(n*w);
    w=1;
  }
  cout << fixed << std::setprecision(15) << ans;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

        self.d = dict()
        for i in range(n+1):
            self.d[i] = 1

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

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # print(x, y, self.rank, self.par)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            ret = self.d[y] * self.d[x]
            self.d[y] += self.d[x]
            self.d[x] = 0
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
            ret = self.d[y] * self.d[x]
            self.d[x] += self.d[y]
            self.d[y] = 0
        elif self.rank[x] == self.rank[y]:
            self.par[y] = x
            self.rank[x] += 1
            if x == y:
                ret = 0
            else:
                ret = self.d[x] * self.d[y]
                self.d[x] += self.d[y]
                self.d[y] = 0

        # print(self.d)
        return ret

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


rev_ans = [0]
u = UnionFind(n)
for i in reversed(range(m)):
    # print(ab[i][0], ab[i][1])
    # union
    ret = u.union(ab[i][0], ab[i][1])
    rev_ans.append(rev_ans[-1] + ret)
# print(rev_ans)

tmp = n * (n-1) // 2
for i in reversed(range(m)):
    print(tmp - rev_ans[i])


Measured memory_bytes: 45648
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;

int main()
{
  int Q;
  while (cin >> Q) {
    while (Q--) {
      long long R;
      cin >> R;
      
      int ans = 0;
      set<long long> visited;
      while (R/10 > 0 && visited.find(R) == visited.end()) {
        visited.insert(R);

        long long next = -1;
        for (int i = 10; R/i > 0; i *= 10) {
          long long a = R / i;
          long long b = R % i;
          next = max(next, a*b);
        }
        R = next;
        ++ans;
      }

      if (visited.find(R) != visited.end())
        ans = -1;
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define TEST cout << "PASS" << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll INFL = 1e15 + 1e12 + 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
    ll k;
    cin >> k;
    ll p = k / 50;
    ll r = k % 50;
    cout << 50 << endl;
    rep(i, r) cout << (p + 100 - r)<<" ";
    rep(i, 50 - r) cout << p + 49 - r<<" ";
    cout << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
 
using namespace std;
 
const char nl = '\n';
 
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    double d, t, s;
    cin >> d >> t >> s;
    if(d / s <= t){
        cout << "Yes" << nl;
    }
    else{
        cout << "No" << nl;
    }
    return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };

ll modpow(ll r, ll n, ll mod) {
	ll ans = 1;
	ll tmp = r;
	while (n > 0) {
		if ((n & 1) > 0) ans = ans * tmp % mod;
		tmp = tmp * tmp % mod;
		n >>= 1;
	}
	return ans;
}

int main() {
	ll mod = 1e9 + 7;
	string s;
	cin >> s;
	ll N = s.size();
	vector<ll> NA(N), NC(N), QL(N), QR(N), NL(N), NR(N);
	QL[0] = 0; QR[N - 1] = 0;
	for (int i = 1; i < N; ++i) QL[i] = QL[i - 1] + (s[i - 1] == '?' ? 1 : 0);
	for (int i = N - 2; i >= 0; --i) QR[i] = QR[i + 1] + (s[i + 1] == '?' ? 1 : 0);
	REP(i, 0, N) {
		NL[i] = modpow(3, QL[i], mod);
		NR[i] = modpow(3, QR[i], mod);
	}
	NA[0] = 0; NC[N - 1] = 0;
	for (int i = 1; i < N; ++i) {
		if (s[i - 1] == '?') NA[i] = (3 * NA[i - 1] + NL[i-1]) % mod;
		else if (s[i - 1] == 'A') NA[i] = (NA[i - 1] + NL[i-1]) % mod;
		else NA[i] = NA[i - 1];
	}
	for (int i = N - 2; i >= 0; --i) {
		if (s[i + 1] == '?') NC[i] = (3 * NC[i + 1] + NR[i+1]) % mod;
		else if (s[i + 1] == 'C') NC[i] = (NC[i + 1] + NR[i+1]) % mod;
		else NC[i] = NC[i + 1];
	}
	ll ans = 0;
	REP(i, 0, N) {
		if (s[i] != 'B' && s[i] != '?')continue;
		ans += NA[i] * NC[i];
		ans %= mod;
	}
	PRI(ans);
	return 0;
}

Measured memory_bytes: 8224
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
using namespace std;

int main(){
    string S;
    cin >> S;
    int i = '0';
    bool YYMM = true;
    bool MMYY = true;

    if((S[2] == '0' && S[3] == '0') || (S[2] == '1' && S[3] - i > 2) || S[2] - i > 2){
        YYMM = false;
    }
    if((S[0] == '0' && S[1] == '0') || (S[0] == '1' && S[1] - i > 2) || S[0] - i > 2){
        MMYY = false;
    }

    if(YYMM && MMYY){
        cout << "AMBIGUOUS" << endl;
    } else if(!YYMM && !MMYY){
        cout << "NA" << endl;
    } else if(YYMM){
        cout << "YYMM" << endl;
    } else if(MMYY){
        cout << "MMYY" << endl;
    }
}



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

int main(){
  int a , b , c , d ; 
  cin >> a >> b >> c >> d ; 
  int M = 0 ; 
  
  if(a > b ){
    M += b ;  
  }
  else{
    M =+ a ; 
  }
  
  if(c>d) M += d ; 
  else M += c ; 
  
  cout << M << endl ; 
  
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int maxv=max(a,b);
	maxv=max(maxv,c);
	if(maxv==a)
		cout<<min(abs(b-c),abs(c-b))+min(a-b,a-c)<<endl;
	else if(maxv==b)
		cout<<min(abs(a-c),abs(c-a))+min(b-a,b-c)<<endl;
	else
		cout<<min(abs(a-b),abs(b-a))+min(c-a,c-b)<<endl;
	return 0; 
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int D;
vector<string> str_log;
void SGS(int digit,int value,int bit,string str){
	if(digit>=D){
		if((bit&14)==14){
			str_log.push_back(str);
		}
		return;
	}
	if(bit==1) SGS(digit+1,0,bit|1,str+'0');
	SGS(digit+1,3,bit|2,str+'3');
	SGS(digit+1,5,bit|4,str+'5');
	SGS(digit+1,7,bit|8,str+'7');
}

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

	ll N=in<ll>();
	string sN=to_string(N);
	D = sN.size();

	int bit=0;
	string str;
	SGS(1,0,bit|1,str+'0');
	SGS(1,3,bit|2,str+'3');
	SGS(1,5,bit|4,str+'5');
	SGS(1,7,bit|8,str+'7');

	sort(ALL(str_log));
	auto p = upper_bound(ALL(str_log),sN);

	cout << distance(str_log.begin(),p) << endl;
	return 0;
}


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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int main(void){
    vector<int> c(9);
    bool ans = 0;
    int a2, a3, b1, b2, b3;
    for(int i = 0; i < 9; i++) cin >> c[i];

    for(int a1 = 0; a1 <= c[0]; a1++){
        b1 = c[0] - a1;
        b2 = c[1] - a1;
        b3 = c[2] - a1;
        a2 = c[3] - b1;
        a3 = c[6] - b1;
        if(b1 >= 0 && b2 >= 0 && b3 >= 0 && a2 >= 0 && a3 >= 0 && a2 + b2 == c[4] && a2 + b3 == c[5] && a3 + b2 == c[7] && a3 + b3 == c[8]) ans = 1;
    }

    if(ans == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

using row_t = vector<char>;
using grid_t = vector<row_t>;

void trace(const string &title, const grid_t &grid) {
  cout << title << "\n";
  for(int i = 1; i <= grid.size(); ++i) {
    for(int j = 1; j <= grid[i - 1].size(); ++j) {
      cout << grid[i - 1][j - 1];
    }
    cout << "\n";
  }
  
  cout << "\n";
}

int main() {
  int m, n, k;
  cin >> m >> n >> k;
  
  grid_t grid(m, row_t(n, ' '));
  for(int i = 1; i <= m; ++i) {
    for(int j = 1; j <= n; ++j) {
      cin >> grid[i - 1][j - 1];
    }
  }
  
  int match_cnt = 0;
  for(int i = 0; i < pow(2, m); ++i) {
    bitset<8> bs_i(i);
    auto bs_i_str = bs_i.to_string();
    reverse(bs_i_str.begin(), bs_i_str.end());
    //cout << "i: " << i << " " << bs_i_str << "\n";
    
    //trace("grid", grid);
    
    for(int j = 0; j < pow(2, n); ++j) {
      bitset<8> bs_j(j);
      auto bs_j_str = bs_j.to_string();
      reverse(bs_j_str.begin(), bs_j_str.end());      
      //cout << "\tj: " << j << " " << bs_j_str << "\n";
      
      grid_t grid_copy(grid);
      for(int p = 0; p < bs_i_str.size(); ++p) {
        if(bs_i_str[p] == '1') {
          for(int q = 1; q <= grid_copy[p].size(); ++q) {
            grid_copy[p][q - 1] = '*';
          }
        }
      }
      
      for(int p = 0; p < bs_j_str.size(); ++p) {
        if(bs_j_str[p] == '1') {
          for(int q = 1; q <= grid_copy.size(); ++q) {
            grid_copy[q - 1][p] = '*';
          }
        }
      }
      
      //trace("grid_copy", grid_copy);
      
      int red_cnt = 0;
      for(int p = 1; p <= grid_copy.size(); ++p) {
        for(int q = 1; q <= grid_copy[p - 1].size(); ++q) {
          if(grid_copy[p - 1][q - 1] == '#') {
            ++red_cnt;
          }
        }
      }
      if(red_cnt == k) {
        //cout << ">>>>matched\n";
        ++match_cnt;
      }
    }
  }
  
  cout << match_cnt << "\n";
  return 0;
}

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

int main(){
	int n,f=0,t;
	scanf("%d",&n);
	t=n;
	while (t>0){
		f=f+t%10;
		t=t/10;
	}
	if (n%f==0) printf("Yes");
	else printf("No");
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >> s;
        vector<int> v;
        string t;
        for(int i=0; i< s.size(); i++){
            if(s[i] == '[' && s[i+1] == '[') t+="[";
            if('0' <= s[i] && s[i] <= '9'){
                int m = 0;
                while('0' <= s[i] && s[i] <= '9'){
                    m = m*10 + stoi(s.substr(i, 1));
                    i++;
                }
                v.push_back(m);
            }
            if(s[i] == ']' && s[i+1] == ']'){
                if(v.size() != 0){
                    sort(v.begin(), v.end());
                    int sum = 0;
                    for(int i=0; i< v.size()/2+1; i++) sum += v[i]/2+1;
                    t += to_string(sum);
                    v.clear();
                }
                t += "]";
            }
        }
        s = t;
        while(s.substr(0, 2) == "[["){
            string t;
            for(int i=0; i < s.size(); i++){
                if(s[i] == '[' && s[i+1] == '[') t+="[";
                if('0' <= s[i] && s[i] <= '9'){
                    int m = 0;
                    while('0' <= s[i] && s[i] <= '9'){
                        m = m*10 + stoi(s.substr(i, 1));
                        i++;
                    }
                    v.push_back(m);
                }
                if(s[i] == ']' && s[i+1] == ']'){
                    if(v.size() != 0){
                        sort(v.begin(), v.end());
                        int sum = 0;
                        for(int i=0; i< v.size()/2+1; i++) sum += v[i];
                        t += to_string(sum);
                        v.clear();
                    }
                    t += "]";
                }
            }
            s = t;
        }
        cout << s.substr(1, s.size()-2) << endl;
    }
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,output;
	bool flag;
	cin >> N;
	for (int i = 1; i <= 9;i++){
		for (int j = 1; j <= 9;j++){
			output = i * j;
			if(output == N){
				cout << "Yes";
				flag = true;
				exit(0);
			}
		}
	}
	if(!flag)
		cout << "No";
}

Measured memory_bytes: 256
// http://intsawadan.hatenablog.com/entry/2019/06/08/131920
#include <bits/stdc++.h>
using namespace std;

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

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

int m[1600][1600];
int dp[1600][1600][2];
bool prime[1000010];

int main() {
    int a = 800, b = 800;
    int dir;  // 今向いている方向
    m[a][b] = 1;
    b += 1;
    m[a][b] = 2;
    a -= 1;
    dir = 1;
    for (int i = 3; i <= 1000000; ++i) {
        m[a][b] = i;
        if (dir == 0) {  // →
            if (m[a - 1][b] != 0) {
                b += 1;
            } else {
                a -= 1;
                dir = 1;
            }
        } else if (dir == 1) {  // ↑
            if (m[a][b - 1] != 0) {
                a -= 1;
            } else {
                b -= 1;
                dir = 2;
            }
        } else if (dir == 2) {  // ←
            if (m[a + 1][b] != 0) {
                b -= 1;
            } else {
                a += 1;
                dir = 3;
            }
        } else {  // ↓
            if (m[a][b + 1] != 0) {
                a += 1;
            } else {
                b += 1;
                dir = 0;
            }
        }
    }

    for (int i = 0; i <= 1000000; ++i) {
        prime[i] = true;
    }
    prime[0] = prime[1] = false;
    for (int i = 2; i <= 1000000; ++i) {
        if (prime[i]) {
            for (int j = 2; i * j <= 1000000; ++j) {
                prime[i * j] = false;
            }
        }
    }

    int mm, n;
    while (true) {
        cin >> mm >> n;
        if (mm == 0 && n == 0) break;
        for (int i = 0; i < 1600; ++i) {
            for (int j = 0; j < 1600; ++j) {
                dp[i][j][0] = dp[i][j][1] = 0;
                if (m[i][j] == n) {
                    a = i;
                    b = j;
                }
            }
        }

        int aans = 0, bans = 0;
        if (prime[n]) {
            dp[a][b][0] = 1;
            dp[a][b][1] = n;
            aans = 1;
            bans = n;
        }
        for (int i = a + 1; i < 1500; ++i) {
            for (int j = b - (i - a); j <= b + (i - a); ++j) {
                if (m[i][j] == 0 || m[i][j] > mm) continue;
                int amax = 0, bmax = 0;
                for (int k = -1; k <= 1; ++k) {
                    if (amax < dp[i - 1][j + k][0]) {
                        amax = dp[i - 1][j + k][0];
                        bmax = dp[i - 1][j + k][1];
                    } else if (amax == dp[i - 1][j + k][0] && bmax < dp[i - 1][j + k][1]) {
                        bmax = dp[i - 1][j + k][1];
                    }
                }

                if (prime[m[i][j]]) {
                    amax++;
                    bmax = m[i][j];
                }
                dp[i][j][0] = amax;
                dp[i][j][1] = bmax;
                if (aans < amax) {
                    aans = amax;
                    bans = bmax;
                } else if (aans == amax && bans < bmax) {
                    bans = bmax;
                }
            }
        }
        cout << aans << " " << bans << endl;
    }
}


Measured memory_bytes: 30316
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000007
using namespace std;
long long a[3];
int main()
{
    cin>>a[0]>>a[1]>>a[2];
    long long res=0;
    sort(a,a+3);
    res+=a[2]-a[1];
    a[0]+=res;
    a[1]+=res;
    if((a[1]-a[0])%2)
        a[2]=a[1]=(res++,a[1]+1);
    res+=(a[1]-a[0])/2;
    cout<<res;



    return 0;
}


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

using namespace std;
string s;

bool checkPalindrome(int l, int r) {
    int n = r - l + 1;
    //cout << n << endl;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - i - 1]) {
            //    cout << i << n - i - 1 << endl;
            return 0;
        }
    }
    return 1;
}

int  main() {
    cin >> s;
    int n = s.size();
    (min(checkPalindrome(0, n - 1), min(checkPalindrome(0, n / 2 - 1), checkPalindrome(n / 2 + 1, n - 1)))) ? cout << "Yes" : cout << "No";
}


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

int X1, Y1, X2, Y2, X3, Y3, X4, Y4;
int DX, DY;

int main() {
  cin >> X1 >> Y1 >> X2 >> Y2;
  DX = X1 - X2;
  DY = Y1 - Y2;
  X3 = X2 + DY;
  Y3 = Y2 - DX;
  X4 = X2 + DX + DY;
  Y4 = Y2 - DX + DY;
  cout << X3 << " " << Y3 << " " << X4  << " " << Y4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<sstream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib> 
#include<vector>
#include<algorithm>
using namespace std;

const int maxn = 1e5+10;
int num[maxn];   //从1开始 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int pos;
		scanf("%d",&pos);
		num[pos] = i; 
	} 
	for(int i=1;i<=n;i++){
		if(i>1) printf(" ");
		printf("%d",num[i]);
	}
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int A = int.Parse(s[0]);
        int B = int.Parse(s[1]);
        int K = int.Parse(s[2]);
        List<int> list = new List<int>();
        int frontLast = Math.Min(A + K - 1, B);
        for (int i = A; i <= frontLast; i++)
            list.Add(i);
        int lastFront = Math.Max(A, B - K + 1);
        for (int i = lastFront; i <= B; i++)
            list.Add(i);
        int[] ans = list.Distinct().ToArray();
        for (int i = 0; i < ans.Length; i++)
            Console.WriteLine(ans[i]);
    }
}


Measured memory_bytes: 13280
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2


int main() {
	int Q;
	cin >> Q;
	priority_queue<ll>ql;
	min_priority_queue<ll>qr;
	ll lsum = 0;
	ll rsum = 0;
	ll bsum = 0;
	rep(i, 0, Q) {
		int q;
		ll a, b;
		cin >> q;
		if(i == 0){
			cin >> a >> b;
			ql.push(a);
			lsum += a;
			bsum += b;
			continue;
		}
		if (q == 1) {
			cin >> a >> b;
			bsum += b;
			if (ql.size() > qr.size()) {
				if (a >= ql.top()) {
					qr.push(a);
					rsum += a;
				}
				else {
					ll temp = ql.top();
					ql.pop();
					lsum -= temp;
					ql.push(a);
					lsum += a;
					qr.push(temp);
					rsum += temp;
				}
			}
			else {
				if (a <= qr.top()) {
					ql.push(a);
					lsum += a;
				}else{
					ll temp = qr.top();
					qr.pop();
					rsum -= temp;
					qr.push(a);
					rsum += a;
					ql.push(temp);
					lsum += temp;
				}
			}
		}else {
			ll x = ql.top();
			ll szl = ql.size();
			ll szr = qr.size();
			ll ans = (x*szl - lsum)+(rsum - x * szr)+bsum;
			cout << x << " " << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector

struct weighted_DisjointSet {
    vector<int> par; //根.連結成分の根にはその成分の要素数を符号反転して保存する．
    vector<int64_t> diff_weight;

    weighted_DisjointSet(int n) : par(n, -1), diff_weight(n, 0) {} //.0-indexed 
    void init(int n) {par.assign(n, -1);}// 初期化

    int root(int x) {
        if (par[x] < 0) return x; //根が負なら自身が根．
        else {
            int r = root(par[x]);//径路圧縮
            diff_weight[x] += diff_weight[max(0, par[x])];
            return par[x] = r; 
        }
    }
    
    // 連結判定
    bool issame(int x, int y) { return root(x) == root(y); }

    // weight(y) = weight(x) + w . 親x,子y.
    bool unite(int x, int y, int w) { // 結合が行われればtrue.行われなければfalse.
        w += weight(x) - weight(y);
        x = root(x); y = root(y); // 径路圧縮
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y), w = -w; 
        par[x] += par[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    int64_t size(int x){ return -par[root(x)]; }

    int weight(int x){ 
        root(x); // 径路圧縮
        return diff_weight[x];
    }
    int diff(int x, int y){ return weight(y) - weight(x); }
};

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


int n, q; cin >> n >> q;
weighted_DisjointSet DS(n);

rep(_, 0, q){
    int com, x, y, z; cin >> com;
    if (com) {
        cin >> x >> y;
        if (DS.issame(x, y)) cout << DS.diff(x, y) << "\n";
        else cout << "?\n";
    }
    else {
        cin >> x >> y >> z;
        DS.unite(x, y, z);
    }
}


}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．




Measured memory_bytes: 4040
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+8
#define EPS 1e-8
#define PB push_back
#define fi first
#define se second
#define rep(i,j) for(int  i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
using namespace std;
const int dx[]={1,0,-1,0},dy[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
    string str;
    cin >> str;
    if(str[0] == 'x' && str[str.size()-1] == 'x')puts("x");
    else puts("o");
    return 0;
}

Measured memory_bytes: 1152
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

class Pair implements Comparable<Pair> {
    Node node;
    int frequency;

    Pair(Node node, int frequency) {
        this.node = node;
        this.frequency = frequency;
    }

    public int compareTo(Pair p) {
        return frequency - p.frequency;
    }
}

class Node {
    char c;
    Node parent;

    Node(char c) {
        this.c = c;
    }

    int depth() {
        if(parent == null) return 0;
        return parent.depth() + 1;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        String s = sc.next();
        int[] frequency = new int[26];
        for(int i = 0; i < s.length(); i++) {
            frequency[s.charAt(i) - 'a']++;
        }

        PriorityQueue<Pair> que = new PriorityQueue<>();
        Map<Character, Node> map = new HashMap<>();
        for(int i = 0; i < 26; i++) {
            int tmp = frequency[i];
            if(tmp > 0) {
                char c = (char)('a' + i);
                Node node = new Node(c);
                que.add(new Pair(node, tmp));
                map.put(c, node);
            }
        }

        while(que.size() > 1) {
            Pair p1 = que.poll();
            Pair p2 = que.poll();
            Node n1 = p1.node;
            Node n2 = p2.node;

            Node parent = new Node('.');
            n1.parent = parent;
            n2.parent = parent;
            int newFreq = p1.frequency + p2.frequency;
            que.add(new Pair(parent, newFreq));
        }

        int res = 0;
        for(int i = 0; i < 26; i++) {
            int tmp = frequency[i];
            if(tmp > 0) {
                char c = (char)('a' + i);
                res += tmp * (map.get(c).depth());
            }
        }

        System.out.println(map.size() > 1? res : s.length());
        
        sc.close();
    }
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> C(m);
    for (int i = 0; i < m; i++) cin >> C[i];

    vector<int> dp(n+1);  // dp[i] : i 円を支払う時の最小枚数
    for (int i = 0; i <= n; i++) dp[i] = n;
    for (int i = 0; i < m; i++) dp[C[i]] = 1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i + C[j] <= n) dp[i + C[j]] = min(dp[i + C[j]], dp[i] + 1);
        }
    }
    cout << dp[n] << endl;

    return 0;
}



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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i,0,n/2) {
    if (s[i] != s[n-i-1]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  ll sum[n];
  sum[0]=a[0];
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+a[i];
  }
  int ans=0;
  for(int i=0;i<n-1;i++){
    if(sum[i]*2>=a[i+1]){
      ans++;
    }else{
      ans=0;
    }
  }
  cout<<ans+1<<endl;
  return 0;
}

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

int N, M;
int cn; //回答
vector<int> X;
vector<int> Y;
vector<int> Z;

/*Zとかはっきり言って関係がない？A_i+A_jの和は偶数か奇数である。*/
/*つまり、Zが偶数ならA_i+A_jも偶数、Zが奇数ならA_i+A_jも奇数*/
/*しかしAは1か2しかないので、A_iとA_jの一方が決まってしまえばもう一方も決定*/
/*よってグラフを作り、隣接するノード(A_i+A_jの条件があるならば隣接するとする)*/


struct UnionFind {
  vector<int> par;
  
  UnionFind(int n){ par.resize(n+1, -1); }
  void init(int n){ par.assign(n+1, -1); }

  int root(int x){
    if(par[x] < 0) return x;
    else return (par[x] = root(par[x]));  //根ノードを記録
  }

  bool is_same(int x, int y){
    return (root(x) == root(y));
  }

  bool merge(int x, int y){
    x = root(x); y = root(y);  //xとyの根を取得
    if(x == y) return false;  //結合の必要なし
    if(par[x] < par[y]) swap(x, y);   //基本的にはxの方を大きい木とする
    par[x] += par[y]; //サイズの合計(結合するので)
    par[y] = x; //par[y]はxを根とするようになる
    return true;
  }

  int size(int x){
    return -par[root(x)]; //サイズは負の値で記録されているので...
  }

};


int main(){
  scanf("%d %d", &N, &M);
  cn = N;

  int tx, ty, tz;
  for(int i = 0; i < M; i++){
    scanf("%d %d %d", &tx, &ty, &tz);
    X.push_back(tx); Y.push_back(ty); Z.push_back(tz);
  }

  UnionFind uf(N);
  uf.init(N);
  
  for(int i = 0; i < M; i++){
    if(uf.is_same(X[i], Y[i])) continue;
    if(uf.merge(X[i], Y[i])) cn--;
  }

  cout << cn << endl; 
  return 0;
}
    





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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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 gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> val = divisor(n);
  int size = val.size();
  ll res;
  if (size % 2 != 0) res = val[size/2] * 2;
  else res = val[size/2] + val[size/2-1];
  cout << res - 2 << endl;
  return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    int64_t N, K;
    long double ans = 0.0;

    scanf("%"PRId64"%"PRId64, &N, &K);

    for (int i = 1; i <= N; i++) {
        if (i <= (K - 1)) {
            ans += powl(0.5, ceill(log2l((long double)K / (long double)i)));
        } else {
            ans += 1.0;
        }
    }

    ans /= (long double)N;

    printf("%.10Lf\n", ans);
}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)

using namespace std;

typedef long long ll;
const ll mod=1e9+7;

using pear = pair<int,int>;

int main(){
    int n; cin >>n;
    int k;
    if(n % 2 == 0){
        k = n/2;
    }else{
        k = n/2+1;
    }
    printf("%f", (double)k/n );
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    FOR(i, 1, n + 1)
    FOR(j, 1, n + 1)
    FOR(k, 1, n + 1)
    ans += gcd(i, gcd(j, k));
    cout << ans << endl;
}

Measured memory_bytes: 3604
n = int(input())
s = [str(input()) for _ in range(n)]

cnt = 0
head_b_cnt = 0
end_a_CNT = 0
head_a_end_b_cnt = 0
for word in s:
    cnt += word.count('AB')
    if word[0] == 'B':
        head_b_cnt += 1
    if word[-1] == 'A':
        end_a_CNT += 1
    if word[0] == 'B' and word[-1] == 'A':
        head_a_end_b_cnt += 1

if (head_b_cnt ==  end_a_CNT ==  head_a_end_b_cnt and head_a_end_b_cnt > 0):
    cnt += min(head_b_cnt, end_a_CNT) - 1
else:
    cnt += min(head_b_cnt, end_a_CNT)

print(cnt)


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

int main() {
  int n,k;
  cin >> n >> k;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(i+k-1 <= n) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

const ll INF = (1LL<<60);
int n, w, we[111], v[111];
ll dp[111][111111];

main(){
    scanf("%d%d", &n, &w);
    for(int i=0; i<=n; i++){
        if(i)scanf("%d%d", &we[i-1], &v[i-1]);
        for(int j=0; j<100100; j++)dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<100100; j++){
            if(j >= v[i])dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + we[i]);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }
    int i = 100000;
    for(; dp[n][i] > w; i--);
    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 88064
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>

using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	double a, b;
	double h, m;
	cin >> a >> b >> h >> m;

	double th = abs(2 * M_PI * (h / 12 + m / 720) - 2 * M_PI * m / 60);
	double th2 = min(th, 2 * M_PI - th);

	double ans = sqrt(a * a + b * b - 2 * a * b * cos(th2));

	cout << fixed << setprecision(10);
	cout << ans << endl;
}


Measured memory_bytes: 4228