akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, N: int):
        """
        N:要素数
        root:各要素の親要素の番号を格納するリスト.
             ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
        rank:ランク
        """
        self.N = N
        self.root = [-1] * N
        self.rank = [0] * N

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def find(self, x: int) -> int:
        """頂点xの根を見つける"""
        if self.root[x] < 0:
            return x
        else:
            while self.root[x] >= 0:
                x = self.root[x]
            return x

    def union(self, x: int, y: int) -> int:
        """x,yが属する木をunion"""
        # 根を比較する
        # すでに同じ木に属していた場合は何もしない.
        # 違う木に属していた場合はrankを見てくっつける方を決める.
        # rankが同じ時はrankを1増やす
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x: int, y: int) -> bool:
        """xとyが同じグループに属するかどうか"""
        return self.find(x) == self.find(y)

    def count(self, x):
        """頂点xが属する木のサイズを返す"""
        return - self.root[self.find(x)]

    def members(self, x):
        """xが属する木の要素を列挙"""
        _root = self.find(x)
        return [i for i in range(self.N) if self.find == _root]

    def roots(self):
        """森の根を列挙"""
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        """連結成分の数"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = UnionFind(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.union(u, v)


Measured memory_bytes: 75140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
int main() {
    string s;
    cin >> s;
    ll x,y;
    cin >> x >> y;
    int direction = -1;
    vector<ll> tmpX = vector<ll>(0);
    vector<ll> tmpY = vector<ll>(0);
    vector<int> ss = vector<int>(0);
    int tmp = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'F'){
            tmp++;
        }else{
            ss.push_back(tmp);
            tmp = 0;
        }
    }
    if(tmp != 0){
        ss.push_back(tmp);
    }
    for(int i = 0; i < ss.size(); i++){
        //cout << ss[i] << endl;
        if(i == 0){
            continue;
        }
        if(i % 2 == 0){
            tmpX.push_back(ss[i]);
        }else{
            tmpY.push_back(ss[i]);
        }
    }
    sort(tmpX.begin(),tmpX.end(),greater<ll>());
    sort(tmpY.begin(),tmpY.end(),greater<ll>());
    ll currentX = ss[0];
    //cout << ss[0];
    ll currentY = 0;
    for(int i = 0; i < tmpX.size(); i++){
        if(currentX < x){
            currentX += tmpX[i];
        }else{
            currentX -= tmpX[i];
        }
    }
    for(int i = 0; i < tmpY.size(); i++){
        if(currentY < y){
            currentY += tmpY[i];
        }else{
            currentY -= tmpY[i];
        }
    }
    if(currentX == x && currentY == y){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
using bset = bitset<maxn>;
bool dpl[maxn][maxn], dpr[maxn][maxn];
bset beat[maxn], beatl[maxn], beatr[maxn], pl[maxn];
int main(){
	int n; cin >> n;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < i; j++){
			char c; cin >> c;
			if(c == '1') beat[i][j] = 1;
			else beat[j][i] = 1;
		}
	}
	for(int i = 1; i <= n; i++){
		pl[i] = pl[i - 1];
		pl[i].set(i - 1);
	}
	for(int i = 0; i < n; i++) dpl[i][i] = 1, dpr[i][i] = 1, beatl[i][i] = 1, beatr[i][i] = 1;
	for(int i = 2; i <= n; i++){
		for(int j = 0; j + i - 1 < n; j++){
			int from = j, to = j + i - 1;
			bset fr = beatr[from + 1];
			bset bk = beatl[to];
			bset now = beat[from];
			now &= fr;
			now &= bk;
			now >>= from + 1;
			now &= pl[i - 1];
			if(now.any()){
				dpl[from][to] = 1;
				beatl[to][from] = 1;
			}
		}
		for(int j = n - 1; j - i + 1 >= 0; j--){
			int from = j, to = j - i + 1;
			bset fr = beatr[to];
			bset bk = beatl[from - 1];
			bset now = beat[from];
			now &= bk;
			now &= fr;
			now >>= to;
			now &= pl[i - 1];
			if(now.any()){		
				dpr[from][to] = 1;
				beatr[to][from] = 1;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) if(dpr[i][0] && dpl[i][n - 1]) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10240
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = 0;
            while ((n = int.Parse(Console.ReadLine())) != 0)
            {
                int a = 0, b = 0;
                while (n-- != 0)
                {
                    var AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    if (AB[0] > AB[1])
                    {
                        a += AB[0] + AB[1];
                    }
                    else if (AB[0] < AB[1])
                    {
                        b += AB[0] + AB[1];
                    }
                    else
                    {
                        a += AB[0];
                        b += AB[1];
                    }
                }
                Console.WriteLine("{0} {1}", a, b);
            }
        }
    }
}

Measured memory_bytes: 6092
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

ll A[100001];

void solve(){
	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];
	int m=1;
	int ans = INT_MIN;
	for(int i=1; i<n; i++){
		if(A[i] <= A[i-1]){
			m++;
		}
		else{
			ans = max(ans,m);
			m = 1;

		}
	}
	cout<<max(ans,m)-1;


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


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

//ki
vector<int> to[200005];
vector<int> ans;

void dfs( int v, int p=-1){
    for(int u : to[v]){
        if( u==p )
            continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; ++i){
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(N);
    for (int i = 0; i < Q; ++i){
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    for (int i = 0; i < N; ++i){
        cout << ans[i] << endl;
    }

    return 0;
}

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

constexpr int MAX_NUM = 100000;
struct Node{int p, l, r;};
Node T[MAX_NUM];
int D[MAX_NUM] = {};
int buf[MAX_NUM];

int getChild(int id, int* child_ary) {
    int n = 0;
    if (T[id].l == -1) return n;
    else {
        int c= T[id].l;
        while (c != -1) {
            child_ary[n++] = c;
            c = T[c].r;
        }
    }
    return n;
}

void printNode(int id) {
    std::string type;
    if (T[id].p == -1) {
        type = "root";
    }else{
        if (T[id].l != -1) type = "internal node";
        else type = "leaf";
    }
    int n = getChild(id, buf);
    std::printf("node %d: parent = %d, depth = %d, %s, ",
                id, T[id].p, D[id], type.c_str());
    std::printf("[");
    for (int i = 0; i < n; i++) {
        if(i) std::printf(", ");
        std::printf("%d", buf[i]);
    }
    std::printf("]\n");
}

void setDepth(int r, int d) {
    D[r] = d;
    if (T[r].l > -1) setDepth(T[r].l, d + 1);
    if (T[r].r > -1) setDepth(T[r].r, d);
}


int main(int argc, char** argv) {
    int Node = {};
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].l = -1;
        T[i].r = -1;
        T[i].p = -1;
    }
    for (int i = 0; i < n; i++) {
        int id, k, l, c;
        std::cin >> id >> k;
        for (int j = 0; j < k; j++) {
            std::cin >> c;
            if (j == 0) T[id].l = c;
            else {
                T[l].r = c;
            }
            l = c;
            T[c].p = id;
        }
    }

    int root = -1;
    for (int i = 0; i < n; i++) {
        if (T[i].p == -1) {
            root = i;
        }
    }

    setDepth(root, 0);
    for (int i = 0; i < n; i++) {
        printNode(i);
    }
}



Measured memory_bytes: 5188
import sys

x = sys.stdin.readline()
x = x.split(' ')
(h,n)=[int(str) for str in x]
x = sys.stdin.readline()
x = x.split(' ')

sum = 0
for i in x:
  sum += int(i)

if(h > sum):
  print("No")
else:
  print("Yes")

sys.stdout.flush()


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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<double> x(n, 0.0);
    for(int i=0; i<n; i++){
        cin >> x[i];
        x[i] = (x[i] + 1.0) / 2.0;
    }
    vector<double> sum(n+1, 0.0);
    for(int i=0; i<n; i++) sum[i+1] = sum[i] + x[i];
    double ans = 0.0;
    for(int i=k; i<=n; i++) ans = max(ans, sum[i] - sum[i-k]);
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace  std;
#define ll long long
#define vll vector<long long>
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    nitro;
    ll n;
    set<string>s;
    cin>>n;
    string str;
    while(n--)
    {
        cin>>str;
        s.insert(str);
    }
    cout<<s.size();

}


Measured memory_bytes: 19180
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n;

int get(int x){
	cout<<x<<endl;
	string s;
	cin>>s;
	if(s[0]=='V')exit(0);
	return s[0]=='M';
}
int a[maxn];

int main(){
	cin>>n;
	a[0]=get(0);	
	a[n-1]=get(n-1);
	int l=0,r=n-1;
	while(l<r){
		int mid=(l+r)>>1;
		a[mid]=get(mid);
		if((0^a[0])%2==(mid^a[mid])%2){
			l=mid+1;
		}else{
			r=mid;
		}
	}
	for(int i=-1;i<=1;i++)
		get((l+i+n)%n);
	return 0;
}

Measured memory_bytes: 852
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int n,m;
int ans;
int k[1000];
int main(){
  cin >> n >> m;
  REP(i,n){
    int a;
    cin >>a;
    REP(j,a){
      int b;
      cin >> b;
      k[b-1] ++;
    }
  }
  REP(i,m){
    if(k[i]==n) ans ++;
  }

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


Measured memory_bytes: 256
n,m = map(int, input().split())
coin = list(map(int,input().split()))
dp = [float("inf") for i in range(n+1)]
dp[0] = 0
for i in range(n+1):
    for j in coin:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)

print(dp[n])


Measured memory_bytes: 7384
use proconio::input;

fn main() {
    input! {
        n: i64,
    }

    let mut ans = 0;
    for (_, count) in factor(n) {
        let mut n = count;
        let mut b = 1;
        while b <= n {
            n -= b;
            b += 1;
            ans += 1;
        }
    }
    println!("{}", ans);
}

// O(n^(1/2)) で与えられた値の素因数分解を求める
use std::collections::HashMap;

fn factor(num: i64) -> HashMap::<i64, i64> {
    let mut map = HashMap::new();
    let mut n = num;

    let mut i = 2;
    loop {
        if n == 1 { 
            // 割り切れたら抜ける
            break;
        }
        if i * i >= num {
            // n^(1/2)まで試す
            // 残っていたら追加して抜ける
            map.insert(n, 1);
            break;
        }
        if n % i == 0 {
            // Mapに無ければ追加、あれば1増やす
            *map.entry(i).or_insert(0) += 1;
            n /= i;
            continue;
        }
        i += 1;
    }
    map
} 


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

int main() {
  int N,X,T;
  cin>>N>>X>>T;
  if(N%X==0){cout<<N/X*T<<endl;}else{cout<<(N/X+1)*T<<endl;}

}

Measured memory_bytes: 3624
import java.util.Scanner;

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

    int n = sc.nextInt();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      if (isTriangle(a, b, c)) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }

  static boolean isTriangle(int a, int b, int c) {
    if (a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b) {
      return true;
    } else {
      return false;
    }
  }
}

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

const int M = 1000;
const int N = 1000;
const int K = 100000;

char joi[M][N];
int jc[M][N] = {};
int oc[M][N] = {};
int ic[M][N] = {};
/*
void check(int a, int b, int c, int d)
{
	int jn = 0;
	int on = 0;
	int in = 0;
	for(int i = a; i <= c; ++i){
		for(int j = b; j <= d; ++j){
			if(joi[i][j] == 'J') jn++;
			if(joi[i][j] == 'O') on++;
			if(joi[i][j] == 'I') in++;
		}
	}
	cout << jn << " " << on << " " << in << endl;
}
*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int m, n, k;
	cin >> m >> n >> k;
	
	for(int i = 1; i <= m; ++i){
		for(int j = 1; j <= n; ++j){
			char c;
			cin >> c;
			
			jc[i][j] = jc[i - 1][j] + jc[i][j - 1] - jc[i - 1][j - 1];
			oc[i][j] = oc[i - 1][j] + oc[i][j - 1] - oc[i - 1][j - 1];
			ic[i][j] = ic[i - 1][j] + ic[i][j - 1] - ic[i - 1][j - 1];
			
			if(c == 'J') jc[i][j]++;
			if(c == 'O') oc[i][j]++;
			if(c == 'I') ic[i][j]++;
			
			joi[i][j] = c;
			//cout << jc[i][j] << " " << oc[i][j] << " " << ic[i][j] << endl;
		}
	}
	
	for(int i = 0; i != k; ++i){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		
		cout << 
			jc[c][d] - jc[c][b - 1] - jc[a - 1][d] + jc[a - 1][b - 1] << " " <<
			oc[c][d] - oc[c][b - 1] - oc[a - 1][d] + oc[a - 1][b - 1] << " " <<
			ic[c][d] - ic[c][b - 1] - ic[a - 1][d] + ic[a - 1][b - 1] << endl;
		
		//a--, b--, c--, d--;
		//check(a, b, c, d);
	}
	
	return 0;
}

Measured memory_bytes: 13880
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll n;
    ll ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        ans+=a;
    }
    cout<<ans-n<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	D := nextInt()

	vector := make([][]int, N)

	for i := 0; i < N; i++ {
		vector[i] = make([]int, D)

		for j := 0; j < D; j++ {
			vector[i][j] = nextInt()
		}
	}

	c := 0

	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			d2 := float64(0)

			for k := 0; k < D; k++ {
				d2 += float64(vector[i][k]-vector[j][k]) * float64(vector[i][k]-vector[j][k])
			}

			d := int(math.Sqrt(d2))

			if d2 == float64(d*d) {
				c++
			}
		}
	}

	fmt.Println(c)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author PRANJAL AGNIHOTRI
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            int max = 0;
            int gcd = 0;
            for (int i = 0; i < N; i++) {
                int a = in.nextInt();
                max = Math.max(max, a);
                gcd = findGCD(gcd, a);
            }
            if (K <= max && K % gcd == 0) {
                out.println("POSSIBLE");
            } else {
                out.println("IMPOSSIBLE");
            }
        }

        private int findGCD(int a, int b) {
            while (b > 0) {
                int t = a % b;
                a = b;
                b = t;
            }
            return a;
        }

    }
}



Measured memory_bytes: 49816
#include<stdio.h>

int main(void)
{
	int N;
	int l1, l2, l3;
	int m1, m2, m3;
	int i, t;
	
	scanf("%d", &N);
	for(i = N; i > 0; i--){
		scanf("%d %d %d", &l1, &l2, &l3);
		m1 = l1, m2 = l2, m3 = l3;
		if(m1 < m2){
			t = m2;
			m2 = m1;
			m1 = t;
		}if(m1 < m3){
			t = m3;
			m3 = m1;
			m1 = t;
		}if(m2 < m3){
			t = m3;
			m3 = m2;
			m2 = t;
		}
		if((m1 * m1) == (m2 * m2) + (m3 * m3)){
			puts("YES");
		}else{
			puts("NO");
		}
	}
	
	return 0;
}	

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
const int N=2e5+10 , MOD=1e9+7 ;
ll ans,n ;
string s ;
int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        cin >> s ;
        for ( int i=0 ; i<s.size() ; i++ )
                (s[i]=='B') ? n++ : ans+=n ;
        cout << ans << '\n' ;
        return 0 ;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>    
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second 
#define mod 1000000007     
using namespace std;

main()
{    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n, k;
    cin >> n >> k;
    int arr[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    vector<int> visit(n + 1, -1);
    int entry = 0;
    int cur = 1;
    while(visit[cur] == -1 and k){
        if(entry == k){
            cout << cur;
            return 0;
        }
        visit[cur] = entry++;
        cur = arr[cur];
    }
    int cycle = entry - visit[cur];
    int left = (k - entry) % cycle;
    while(left--){
        cur = arr[cur];
    }
    cout << cur;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
const int MX = 1e6;
const int inf = 1e9;
//const int mod = 1e9+7;
using ll = long long;
const int mod = 1000000007;

signed main(){
    int x, y;
    cin >> x >> y;
    if(y%2==1){
        cout << "No" << endl;
        return 0;
    }
    if(x*2<=y && y<=x*4) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    


    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
int A[1000000],n;

/*二分搜索*/
int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid]) return 1; //发现key
        if(key > A[mid]) left = mid +1;//搜索后半部分
        else if(key < A[mid]) right = mid;//搜索前半部分
    }
    return 0;
}


int main(){
    int i, q, k, sum=0;

    scanf("%d",&n);
    for(i=0;i <n;i++){
        scanf("%d",&A[i]);
    }

    scanf("%d",&q);
    for(i = 0; i<q; i++) {
        scanf("%d", &k);
        if (binarySearch(k)) sum++;
    }
    printf("%d\n",sum);
    return 0;
}





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,d;
ll ans=0;
cin>>n>>d;
d*=d;
while(n--)
{
    ll x,y;
    cin>>x>>y;
    x*=x,y*=y;
    if(x+y<=d)
        ans++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String[] b = a.split("");
        int count = 0;
        if (b.length % 2 == 0) {
            for (int i = 0; i < b.length / 2; i++) {
                if (!(b[i].equals(b[b.length - 1 - i]))) {
                    count++;
                }
            }
        }
        if (b.length % 2 == 1) {
            for (int i = 0; i < (b.length-1) / 2; i++) {
                if (!(b[i].equals(b[b.length - 1 - i]))) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#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<ll,ll>;

int main (){
  int n;
  cin>>n;
  vector<int> v(3);
  rep(i,3){
    v.at(i) = n%10;
    n/= 10;
  }
  bool ok = false;
  rep(i,3){
    if (v.at(i) == 7){
      ok = true;
    }
  }
  if (ok){
    cout <<"Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  n = n % 10;
  if (n == 3) {
    cout << "bon" << endl;
  } else if (n == 0 or n == 1 or n == 6 or n == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	string C1, C2;
	cin >>C1 >>C2;
	if (
		(C1.at(0)==C2.at(2))
		&& (C1.at(1)==C2.at(1))
		&& (C1.at(2)==C2.at(0))
	  ) {
		cout <<"YES" <<endl;
	} else
		cout <<"NO" <<endl;
	return 0;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n, m;
vector<vector<int>> g;
int ans = 0;

void dfs(int v, vector<bool> seen) {
    bool end = true;
    for (int i = 0; i < seen.size(); ++i) {
        if (!seen[i] && i != v) end = false; //入力のv以外で見ていないところがあるか
    }

    if (end) {
        ++ans;
        return;
    }

    for (auto nv : g[v]) {
        if (seen[nv]) continue;

        seen[nv] = true;
        dfs(nv, seen);
        seen[nv] = false;
    }
}

int main() {

    cin >> n >> m;
    g.resize(n);

    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<bool> seen(n, false);

    seen[0] = true;
    dfs(0, seen);

    cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.List as L
 
main :: IO ()
main = do
  [n, m] <- getNums <$> getLine
  as <- replicateM n getLine
  bs <- replicateM m getLine
  let msg = if (solve as bs (n, m)) then "Yes" else "No"
  putStrLn msg
  
getNums :: String -> [Int]
getNums = map read . words
 
solve :: [String] -> [String] -> (Int, Int) -> Bool
solve as bs (n, m) = _solve as bs 0 0
  where
    _solve :: [String] -> [String] -> Int -> Int -> Bool
    _solve as bs x y = if matrixEquals ass bs
                       then True
                       else if x + 1 > n
                            then if y + 1 > n
                                 then False
                                 else _solve as bs 0 (y+1)
                            else _solve as bs (x+1) y
                       where
                         ass = getSubMatrix m x y (n, m) as     
 
getSubMatrix :: Int -> Int -> Int -> (Int, Int) ->  [String] -> [String]
getSubMatrix size x y (n, m)as =
  map _getSubMatrix ass
  where
    ass = if size + x > n
          then ["a"]
          else (take size . drop x) as
    _getSubMatrix ls
      | null ls = "a"
      | otherwise = (take size . drop y) ls
 
matrixEquals :: [String] -> [String] -> Bool
matrixEquals as bs = all (\(a, b) -> a == b) $ zip as bs 

Measured memory_bytes: 1020
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vector<ll> s(n+2), t(m+2);
	rep(i,n) cin >> s[i+1];
	rep(i,m) cin >> t[i+1];
	s[0] = t[0] = -INF;
	s[n+1] = t[m+1] = INF;
	rep(i,q){
		ll x;
		cin >> x;
		auto Rsh = lower_bound(s.begin(), s.end(), x);
		auto Rte = lower_bound(t.begin(), t.end(), x);
		auto Lsh = Rsh;
		auto Lte = Rte;
		--Lsh; --Lte;
		ll ans = INF;
		chmin(ans, x - min(*Lsh, *Lte));
		chmin(ans, max(*Rsh, *Rte) - x);
		chmin(ans, (*Rsh - *Lte) + min((*Rsh - x), (x - *Lte)));
		chmin(ans, (*Rte - *Lsh) + min((*Rte - x), (x - *Lsh)));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4748
#include<cstdio>
#include<iostream>
#include<string>
#include<climits>
#include<algorithm>

using namespace std;
typedef int Node;
class CompleteBinaryTree {
    Node* Tree;
    Node nil = -2000000001;
    int size;
    
    public :CompleteBinaryTree(int c){
        size = c;
        Tree = new Node[size+1];
        for(int i =1;i <= c;++i) Tree[i] = nil;
    }
    
    void AddChild(int c, int n) {
            Tree[n] = c;
	}
    
    int GetParent(int n){
        return (n/2) != 0 ? n/2:nil;
    }
    
    int GetRightChild(int n){
        return (2*n+1) <= size ? 2*n+1:nil;
    }

    int GetLeftChild(int n){
        return (2*n) <= size ? 2*n:nil;
    }
    void MaxHeapify(int i){
        int l = GetLeftChild(i), r = GetRightChild(i),largest;
        if(l != nil && Tree[l] > Tree[i]){
            largest = l;
        } else{
            largest = i;
        }
        if(r != nil && Tree[r] > Tree[largest]){
            largest = r;
        }
        if(largest != i){
            swap(Tree[i],Tree[largest]);
            MaxHeapify(largest);
        }
    }
    
    void BuildMaxHeap(){
        for(int i = size/2;i >= 1;i--) MaxHeapify(i);
    }
    
    void print(){
        for(int i = 1;i <=size;++i) printf(" %d",Tree[i]);
    }
};

int main(){
    int n,k;
    CompleteBinaryTree *cbt;
    scanf("%d",&n);
    cbt = new CompleteBinaryTree(n);
    for(int i = 1;i <= n;++i){
        scanf("%d",&k);
	    cbt -> AddChild(k,i);
    }
    cbt -> BuildMaxHeap();
    cbt -> print();
    printf("\n");
    
}






Measured memory_bytes: 5108
import sys
from copy import copy
sys.setrecursionlimit(10**7)

n, a, b, c = map(int, input().split())
k = sorted([a, b, c])
l = [int(input()) for _ in range(n)]
ans = float("inf")

def dfs(i, num, nk):
    global ans
    if i == n:
        if not all(nk): return
        nk.sort()
        cost = (num - 3) * 10
        for j in range(3): cost += abs(k[j] - nk[j])
        ans = min(ans, cost)
        return
    
    nxt = l[i]
    dfs(i+1, num, nk)
    for j in range(3):
        nnk = copy(nk)
        nnk[j] += nxt
        dfs(i+1, num+1, nnk)

dfs(0, 0, [0] * 3)
print(ans)


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

typedef long long int llint;

int main()
{
  map<string, bool> mp;
  string s;
  int k;
  cin>> s >> k;

  vector<string> v;
  
  char tar = 'a';
  while(v.size() < k) {

    for(int i = 0; i < s.size(); i++) {
      if(s[i] == tar) {
	string sub; sub += s[i];
	if(!mp[sub]) v.push_back(sub);
	mp[sub] = true;
	for(int j = i + 1; j < i + 5; j++) {
	  if(j >= s.size()) break;
	  sub += s[j];
	  if(!mp[sub]) v.push_back(sub);
	  mp[sub] = true;
	}
      }
    }

    tar++;

  }

  
  sort(v.begin(), v.end());

  cout<< v[k - 1] <<endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <stack>
#include <map>
using namespace std;
int N;

int main() {
    while(cin >> N, N){
        vector<pair<int, int> > vp;
        vp.push_back({0, 0});
        for(int i=1; i<N; ++i){
            int n, d; cin >> n >> d;
            int x, y;
            if(d==0){
                x = vp[n].first-1;
                y = vp[n].second;
            }else if(d==1){
                x = vp[n].first;
                y = vp[n].second-1;
            }else if(d==2){
                x = vp[n].first+1;
                y = vp[n].second;
            }else if(d==3){
                x = vp[n].first;
                y = vp[n].second+1;
            } 
            vp.push_back({x, y});            
        }
        int ansxu=0, ansxd=0, ansyl=0, ansyr=0;
        for(int i=0; i<vp.size(); ++i){
            ansxu = max(ansxu, vp[i].first);
            if(vp[i].first<0){
                ansxd = min(ansxd, vp[i].first);
            }
            ansyr = max(ansyr, vp[i].second);
            if(vp[i].second<0){
                ansyl = min(ansyl, vp[i].second);
            }
        }
        cout << ansxu-ansxd+1 << " " << -ansyl+ansyr+1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    if(x>y)swap(x,y);
    for(int i=x; i >= 1; i--){
        if(i == 1)return 1;
        else if( x % i  == 0 && y % i == 0)return i;
        //最大公約数、lcm = x*y/gcd 僕のVSCではgcd関数が使えませんでした(泣)だれか教えてください。
    }}
int main(){
	int a;
	cin >> a;
	char op;
	cin >> op;
	int b;
	cin >> b; 
	if(op == '+')cout << a + b << endl;
	else cout << a -b <<endl;		
}



Measured memory_bytes: 256
n = int(input())

ans = [0] * n
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if a >= 1 and a <= n:
                ans[a - 1] += 1

for a in ans:
    print(a)


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
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();}

bool notRoot[101010];
VVI edge(101010);
bool used[101010];
int N,M;

VI tsortArray;

void dfs(int node){
  if(used[node]) return;
  used[node] = true;

  //cerr << "in dfs " << node << endl;
  rep(i,edge[node].size()) dfs(edge[node][i]);

  tsortArray.push_back(node);
}


void tsort(int rootIdx){
  dfs(rootIdx);
  //rep(i,N)cerr << "tsort " << tsortArray[i] << endl;
  reverse(all(tsortArray));
  //rep(i,N)cerr << "tsort " << tsortArray[i] << endl;

}
int main(){
  cin >> N >> M;

  rep(i,N+M-1){
    int to,from;
    cin >> to >> from;
    to--; from--;
    notRoot[from] = true;
    edge[to].push_back(from);
  }

  //search Root
  int rootIdx = -1;
  rep(i,N){
    if(notRoot[i] == false){
      rootIdx = i;
      break;
    }
  }
  assert(rootIdx != -1);

  tsort(rootIdx);

  map<int,int> tsortIdx;
  rep(i,tsortArray.size()) tsortIdx[tsortArray[i]] = i;

  //first 実際の親の値 / second 親のトポロジカル順序
  vector<PII> ans(N,make_pair( 0 , 0 ));
  rep(i,N){
    rep(j,edge[i].size()){
      int childIdx = edge[i][j]; //子のidx
      //cout << "parent:" << i+1 << ",child:" << childIdx+1 << endl;
      if(ans[childIdx].second <= tsortIdx[i] ){
        ans[childIdx].second = tsortIdx[i];
        ans[childIdx].first = i+1;
      }
    }
  }
  rep(i,N){
    cout << ans[i].first << "\n";
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

char buf[2000000];
void solve() {
  scanf("%s", buf);
  int len = strlen(buf);
  ll ret = 0;
  int curr = 0;
  for(int i = 0; i < len; i++) {
    if(buf[i] == 'B') curr++;
    else {
      ret += curr;
    }
  }
  printf("%lld\n", ret);
}


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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 0;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
    string huj[16];
    huj[0] = "KIHBR";
    huj[1] = "KIHBRA";
    huj[2] = "KIHBAR";
    huj[3] = "KIHBARA";
    huj[4] = "KIHABR";
    huj[5] = "KIHABRA";
    huj[6] = "KIHABAR";
    huj[7] = "KIHABARA";
    huj[8] = "AKIHBR";
    huj[9] = "AKIHBRA";
    huj[10] = "AKIHBAR";
    huj[11] = "AKIHBARA";
    huj[12] = "AKIHABR";
    huj[13] = "AKIHABRA";
    huj[14] = "AKIHABAR";
    huj[15] = "AKIHABARA";

    string s;
    cin >> s;
    for (int i = 0; i < 16; i++)
    {
        if (s == huj[i])
        {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int m, f, r, i = 0;
		String score[] = new String[50];
		try (Scanner sc = new Scanner(System.in)) {
			while (true) {
				m = sc.nextInt();
				f = sc.nextInt();
				r = sc.nextInt();
				if(m == -1 && f == -1 && r == -1) {
					for(int j = 0; j < i; j++) {
						System.out.println(score[j]);
					}
					break;
				}if(m == -1 || f == -1) {
					score[i] = "F";
				}else if(m + f >= 80) {
					score[i] = "A";
				}else if(m + f >= 65) {
					score[i] = "B";
				}else if(m + f >= 50) {
					score[i] = "C";
				}else if(m + f >= 30) {
					score[i] = "D";
					if(r >= 50) score[i] = "C";
				}else {
					score[i] = "F";
				}
				i++;
			}
			
		}
	}
}




Measured memory_bytes: 26216
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int a[100001];
int b[100001];

int bin(int a[],int d,int g,int b)
{
    int sredina;
    if(d>g)
       return -1;
     else
    {
        sredina=(d+g)/2;
        if(b==a[sredina])
        return sredina;
        else
        {
            if(b<a[sredina])
        bin(a,d,sredina-1,b);
        else
        bin(a,sredina+1,g,b);

        }
    }

}
int main()
{
    int z,i,n,ii,m,c,l;
    m=0;
scanf("%d",&n);
 for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);

}
scanf("%d",&l);
 for(i=0;i<l;i++)
{
    scanf("%d",&b[i]);
    if((bin(a,-1,n,b[i]))>(-1))
        m=m+1;

}

printf("%d\n",m);
return 0;
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define pb push_back 
using namespace std;

const int maxn=1e6;
typedef long long ll;

int n,m,ans;
int a[maxn];

int main()
{
	int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x!=1) a[x]++;
		if(y!=1) a[y]++;
	}
	
	for(i=1;i<=n;++i)
	{
		if(a[i]%2!=0)
		{
			printf("NO");
			return 0;
		}
	}
	
	printf("YES");
	return 0;
}


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

//--------------------------------------------
#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 LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string s;

  cin >> s;

  if (s.find("YAKI") == 0) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = min(a, b) + min(c, d);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; ++i){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int maxABC = d[N/2-1];
    int minARC = d[N/2];
    cout << minARC-maxABC;
    return 0;
}

Measured memory_bytes: 640
#1回の実行にかかるじかんをx、答えとなる時間(全体実行時間の総和の期待値)をYとする
#n回目までで成功する時の実行時間の総和の期待値をy(n)とおくとY=lim(n→∞)y(n)である
#ここでx=1900M+100(N-M)で固定ある。
#ここで各試行で成功する率p=1/2^Mである。
#ここでn回目までで成功する時の実行時間の総和の期待値をy(n)からn+1回目までで成功する時の実行時間の総和の期待値をy(n+1)を求めることを考える
#(i)n=1の時
#1回目までやった時の実行時間の総和の期待値は1通りしかなくxであるためy(1)=xで固定である。
#2回目までやった時の実行時間の総和の期待値は2回目の実行時間xに、1回目までの期待値y(1)のうち、成功せず2回目まで続く1-p分を重みづけ加算して
#y(2)=x+(1-p)y(1)である
#(ii)n=2の時
#3回目までやった時の実行時間の総和の期待値は
#3回目での実行時間xに2回目までの期待値y(2)のうち成功せず3回目まで続く1-p分を重み付け加算して
#y(3)=x+(1-p)y(2)である
#(iii)n=kの時
#y(k+1)=x+(1-p)y(k)
#であることが容易に予想できる
#
#ここでn→∞にした時y(n+1)とy(n)は共にYとなることより
#Y=x+(1-p)Y
#Y=x/p=x*2^Mである
import math
N,M=map(int,input().split())
time=max(0,N-M)*100+1900*M
print(time*pow(2,M))

Measured memory_bytes: 38484
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	int n; cin >> n;
	if (n < 1200) cout << "ABC\n";
	else cout << "ARC\n";
	return 0;   
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


const ll INF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> l(n+1);
    vector<ll> r(n+1);
    for(int i=1;i<=n;i++){
        l[i]=__gcd(l[i-1],a[i-1]);
    }
    for(int i=n-1;i>=0;i--){
        r[i]=__gcd(r[i+1],a[i]);
    }
    ll M = 0;
    rep(i,n){
        M=max(M,__gcd(l[i],r[i+1]));
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 2560
#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>;
vector<ll> ans;

void dfs(vector<ll> &A,int keta, ll now) {
  if (keta == 10)
  {
    A.push_back(now);
    return;
  }

  A.push_back(now);
  for (int i = -1; i <= 1; i++)
  {
    if((now % 10 == 0 && i == -1) || (now % 10 == 9 && i == 1)) continue;
    dfs(A, keta + 1, now * 10 + now % 10 + i);
  }
  
  
}

int main() {
  int K;
  cin >> K;
  
  for (int i = 1; i <= 9; i++)
  {
    dfs(ans, 1, i);
  }
  sort(ans.begin(), ans.end());
  cout << ans[K - 1] <<endl;
  return 0;
}


Measured memory_bytes: 5340
#include <bits/stdc++.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <stdio.h>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF 1e9
#define precise cout << std::setprecision(10) << std::fixed;
using namespace std;

vector<int> v[100005];
bool vis[100005];
int ans[100005];
void bfs(int src)
{
    vis[src]=1;
    queue<int> q;
    q.push(src);
    while(!q.empty())
    {
        int cn=q.front();
        q.pop();
        for(auto x:v[cn])
        {
            if(!vis[x])
            {
                vis[x]=1;
                ans[x]=cn;
                q.push(x);
            }
        }
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        fr(i,0,m)
        {
            int a,b;
            cin>>a>>b;
            v[a].pb(b);
            v[b].pb(a);
        }
        bfs(1);
        fr(i,1,n+1)
        {
            if(!vis[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
        fr(i,2,n+1) cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 10596
import sys
input = sys.stdin.readline
from collections import defaultdict
 
class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        p = x
        
        while not self.par[p]<0:
            p = self.par[p]
        
        while x!=p:
            tmp = x
            x = self.par[x]
            self.par[tmp] = p
        
        return p
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx==ry: return False
        
        if self.rank[rx]<self.rank[ry]:
            rx, ry = ry, rx
        
        self.par[rx] += self.par[ry]
        self.par[ry] = rx
    
        if self.rank[rx]==self.rank[ry]:
            self.rank[rx] += 1
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, M, K = map(int, input().split())
uf = Unionfind(N)
sub = [0]*N

for _ in range(M):
    A, B = map(int, input().split())
    uf.unite(A-1, B-1)
    sub[A-1] += 1
    sub[B-1] += 1
    
for _ in range(K):
    C, D = map(int, input().split())
    
    if uf.is_same(C-1, D-1):
        sub[C-1] += 1
        sub[D-1] += 1

for i in range(N):
    ans = uf.count(i)-1
    ans -= sub[i]
    
    if i<N-1:
        print(ans, end=' ')
    else:
        print(ans)

Measured memory_bytes: 62552
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[200001],ans,pd[1000001];
bool cmp(int x,int y)
{
	return x<y;
}
void zh(int x)
{
	for(int i=x;i<=1000000;i+=x)
	pd[i]=1;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	if(pd[a[i]]==0)
	{
		if(a[i]!=a[i+1])
		ans++;
		zh(a[i]);
	}
	printf("%lld",ans);
    return 0;
}

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

int main(){

    int a, b, x, tot;
    cin >> a >> b >> x;
    tot = a + b;

    if(x - a >= 0 && x - a + a <= tot) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;

int main() {
    cin >> N >> M;
    vi C(M);
    for (int i = 0; i < M; i++) {
        cin >> C[i];
    }

    vi DP(N + 1, INF);  // i円払うのに必要な最小コイン枚数
    DP[0] = 0;
    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: 3184
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    long long cnt = 0;
    vector<int> A(N);
    vector<vector<int>> num(N + 1);
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        num[A[i]].push_back(i);
    }
    for(int i = 1; i <= N; i++){
            cnt += num[i].size() * (num[i].size() - 1) / 2; //nCrの組み合わせは、n*(n-1)/rで求められる
    }
    for(int i = 0; i < N; i++){
        cout << cnt - (num[A[i]].size()-1) << endl;
    }
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };
static const char Move[] = { 'E', 'W', 'N', 'S' };

int N, Q, M, Max = 0, max_cnt = 0, max_day = 0;
VVI Date;

void solve( int now_Day ) {
	int cnt = 0;
	if ( now_Day > Max ) {
		return;
	}
	for ( int i = 0; i < N; i++ ) {
		cnt += binary_search( Date[ i ].begin(), Date[ i ].end(), now_Day );
	}
	if ( cnt >= Q ) {
		if ( max_cnt < cnt ) {
			max_day = now_Day;
			max_cnt = cnt;
		}
	}
	solve( now_Day + 1 );
}

int main() {
	while ( ~scanf( "%d %d", &N, &Q ) && N && Q ) {
		Date.resize( N );
		for ( int i = 0; i < N; i++ ) {
			scanf( "%d", &M );
			Date[ i ].resize( M );
			for ( int j = 0; j < M; j++ ) {
				scanf( "%d", &Date[ i ][ j ] );
				Max = max( Max, Date[ i ][ j ] );
			}
		}
		solve( 1 );
		printf( "%d\n", max_day );
		max_cnt = max_day = Max = 0;
	}
	return 0;
}

Measured memory_bytes: 1224