akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

/// ans[i] = min{ acc[j - 1] / (i + 1 - j) | 1 <= j <= i }
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [usize1; n],
    }
    let mut f = vec![0; n];
    for &a in &a {
        f[a] += 1;
    }
    f.sort();
    f.reverse();
    let mut acc = vec![0; n + 1];
    for i in (0..n).rev() {
        acc[i] = acc[i + 1] + f[i];
    }
    let mut ans = vec![n + 1; n];
    let mut pos = 0;
    for i in 0..n {
        while pos < i {
            if acc[pos] * (i - pos) > acc[pos + 1] * (i - pos + 1) {
                pos += 1;
            } else {
                break;
            }
        }
        ans[i] = acc[pos] / (i - pos + 1);
    }
    let mut mi = n + 1;
    for a in ans {
        mi = min(mi, a);
        puts!("{}\n", mi);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 25468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
ll loop=0;
void Main(){
    ll n;cin>>n;
    ll k;cin>>k;
    vector<ll> a(n,-1);
    vector<vector<ll>> steps(n);
    For(i,0,n) {
        cin>>a[i];
        a[i]--;
    }
    ll now = 0;
    steps[now].push_back(0);
    For(i,1,n+10){
        now=a[now];
        if(i==k){
            cout << now+1 << endl;
            return;
        }
        steps[now].push_back(i);
    }
    For(i,0,n){
        if(steps[i].size()>1){
            loop = steps[i][1]-steps[i][0];
            now = i;
            k -= steps[i][1];
            break;
        }
    }
    k%=loop;
    For(i,0,k) now = a[now];
    cout << now + 1 << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;

void func(long long X, long long Y, long long Z) { cout << Z << " " << X << " " << Y << endl; }

int main() {
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    long long Z;
    scanf("%lld", &Z);
    func(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] c = new int[n][n];
		for(int i=0;i<n;i++) {
			Arrays.fill(c[i], 0);
		}
		
		int[][] e = new int[m][2];
		for(int i=0;i<m;i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			
			e[i][0] = a;
			e[i][1] = b;
			c[a][b] = 1;
			c[b][a] = 1;
		}
		
		int bridge = 0;
		for(int i=0;i<m;i++) {
			if(isBridge(c, e[i][0], e[i][1])) {
				bridge++;
			}
		}
		
		System.out.println(bridge);
	}
	static boolean isBridge(int[][] c, int s, int t) {
		c[s][t] = 0;
		c[t][s] = 0;
		
		int v = 0;
		boolean[] vis = new boolean[n];
		Arrays.fill(vis, false);
		Queue<Integer> que = new LinkedList<>();
		boolean start = false;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(c[i][j]==1) {
					que.offer(i);
					que.offer(j);
					vis[i] = true;
					vis[j] = true;
					start = true;
					v+=2;
					break;
				}
			}
			if(start)
				break;
		}
	
		
		while(que.size()>0) {
			int a = que.poll();
			
			for(int i=0;i<n;i++) {
				if(c[a][i]==1 && !vis[i]) {
					que.offer(i);
					vis[i] = true;
					v++;
				}
			}
		}
		
		c[s][t] = 1;
		c[t][s] = 1;
	
		if(v==n)
			return false;
		else
			return true;
	}
}

Measured memory_bytes: 23252
#include<stdio.h>

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

Measured memory_bytes: 596
#include<iostream>

using namespace std;

int main()
{
  int n, m, l;
  int a[100][100];
  int b[100][100];

  cin >> n >> m >> l;

  for ( int i = 0; i < n; i++ )
    {
      for ( int j = 0; j < m; j++ )
        {
          cin >> a[i][j];
        }
    }

  for ( int i = 0; i < m; i++ )
    {
      for ( int j = 0; j < l; j++ )
        {
          cin >> b[i][j];
        }
    }

  for ( int i = 0; i < n; i++ )
    {
      for ( int j = 0; j < l; j++ )
        {
          long long sum = 0;
          for ( int k = 0; k < m; k++ )
            {
              sum += a[i][k] * b[k][j];
            }
          if ( j ) cout << " ";
          cout << sum;
        }
      cout << endl;
    }
          
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int s[1000050],a;
int main()
{

    s[0] = 0;
    for(int i=1;i<100005;i++)
    {
        if(i<10)
            s[i] = 1;
        if(i>=100&&i<=999)
            s[i] = 1;
        if(i>=10000&&i<=99999)
            s[i] = 1;
        s[i] += s[i-1];
    }
    while(cin>>a)
    {
        printf("%d\n",s[a]);
    }
    return 0;
}


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

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

        int n = Integer.parseInt(sc.next());
        call(n);
        out.flush();
    }
    public static void call(int n) {
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0) {
                out.printf(" %d", i);
            } else {
                for (int j = i; j > 0; j /= 10) {
                    if (j % 10 == 3) {
                        out.printf(" %d", i);
                        break;
                    }
                }
            }
        }
        out.printf("\n");
    }
}


Measured memory_bytes: 34612
n, k = map(int, raw_input().split())
h = map(int, raw_input().split())

a = [0, abs(h[0] - h[1])]
for i in range(2, n):
    a.append(min(a[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(k, i) + 1)))
print(a[-1])

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> h(n);
  vector<long long> dp(n, 1e18);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= i + 2 and j < n; ++j) {
      dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n - 1];

  return 0;
}

Measured memory_bytes: 1408
n,k = map(int,input().split())
s = list(input())
count = 0
l = []
count1 = 0
for i in range(n):
    if s[i] == "0":
        if count > 0:
            l.append(count)
            count = -1
        else:
            count -= 1
    else:
        if count < 0:
            l.append(count)
            count = 1
            count1 += 1
        else:
            count += 1
l.append(count)
if count < 0:
    count1 += 1
m = len(l)
count2 = 0
ans = []
if l[0] < 0:
    p = 0
else:
    p = 1
if count1 > k:
    x = 0
    ans1 = 0
    while count2 < k:
        if l[x] > 0:
            ans1 += l[x]
            x += 1
        else:
            ans1 += abs(l[x])
            x += 1
            count2 += 1
    ans1 += abs(l[x])
    ans.append(ans1)
    while x < m-2:
        if p > 0:
            ans1 = ans1 - abs(l[p]) - abs(l[p-1]) + abs(l[x+1]) + abs(l[x+2])
            p += 2
            x += 2
        else:
            ans1 = ans1 - abs(l[p]) + abs(l[x+1]) + abs(l[x+2])
            p += 2
            x += 2
        ans.append(ans1)
    if x == m-2:
        if p > 0:
            ans1 = ans1 - abs(l[p]) - abs(l[p-1]) + abs(l[x+1])
            p += 2
            x += 2
        else:
            ans1 = ans1 - abs(l[p]) + abs(l[x+1])
            p += 2
            x += 2
        ans.append(ans1)
    print(max(ans))
else:
    print(n)

Measured memory_bytes: 6264
#include <bits/stdc++.h>
#define REP(i,a,b,c) for(int i=a; i!=int(b); i+=int(c))
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

int n, m;
vector<PII> ab;
priority_queue<int> pq;
int main() {
  cin >> n >> m;
  ab.resize(n);
  REP(i,0, n, 1) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  int k=0;
  int ans = 0;
  REP(i, m-1, -1, -1) {
    while(k<n && ab[k].first+i<=m) {
      pq.push(ab[k].second);
      k++;
    }
    if(pq.empty()) continue;
    ans += pq.top();
    pq.pop();
  }

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

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int N;
  cin >> N;
  vector<pair<int,int> > a(N);
  int x[N];

  rep(i,N){
    cin >> x[i];
    a[i].first = x[i];
    a[i].second = i;
  }
  sort(all(a));
  map<int,int> mp;
  rep(i,N) mp[a[i].second] = i;


  rep(i,N){
    if( mp[i] < N/2 ){
    //  cout << "small " << i << endl;
      cout << a[N/2].first << endl;
    }else{
    //  cout << "high " << i << endl;

      cout << a[N/2-1].first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 13952
function main(input) {
	var jl = input.split("\n")[1].split(" ");
	var cl = input.split("\n")[2].split(" ");
	var r = 0;
	jl.forEach((j, i) => {
		var s = +j - +cl[i];
		if(s > 0) {
			r += s;
		}
	});
	console.log(r);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 6e18;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    int X[N],Y[N];
    rep(i,N){
        cin >> X[i] >> Y[i];
    }
    int ans=INF;
    rep(i,N){
        rep(j,N){
            rep(k,N){
                rep(l,N){
                    int a,b,c,d;
                    a=max({X[i],X[j],X[k],X[l]});
                    b=min({X[i],X[j],X[k],X[l]});
                    c=max({Y[i],Y[j],Y[k],Y[l]});
                    d=min({Y[i],Y[j],Y[k],Y[l]});
                    if(a==b || c==d) continue;
                    int cnt=0;
                    rep(n,N){
                        if(X[n]<=a && X[n]>=b && Y[n]<=c && Y[n]>=d){
                            cnt++;
                        }
                    }
                    if(cnt>=K){
                        chmin(ans,(a-b)*(c-d));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

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

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 4E3 + 10;
const ll M = 998244353;

ll c[N][N];
ll a[N][N], b[N][N][2];
ll e[N];
int n, K;

ll calc(int n, int A, int B){
	ll ret = 0;
	for (int i = 0; i <= n; ++i)
		ret = (ret + a[i][B] * (b[n - i][A][0] + b[n - i][A][1])) % M, eput(i, B, ret);
	return ret;
}

int main(){
	for (int i = 0; i < N; ++i){
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j < i; ++j)
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;
	}

	scanf("%d%d", &K, &n);
	e[0] = 1;
	for (int i = 1; i <= K; ++i)
		e[i] = e[i - 1] * 2 % M;
	for (int i = 0; i <= n; ++i){
		a[i][0] = i == 0;
		for (int j = 1; j <= K; ++j)
			a[i][j] = c[i - 1 + j][j - 1];
	}
	/*
	for (int i = 0; i <= n; ++i){
		b[i][0] = i == 0;
		for (int j = 1; j <= i; ++j)
			b[i][j] = c[i - 1][j - 1] * e[j] % M;
		for (int j = i + 1; j <= K; ++j)
			b[i][j] = 0;

		for (int j = 1; j <= K; ++j)
			b[i][j] = (b[i][j] + b[i][j - 1]) % M;
	}*/

	b[0][0][0] = 1;
	for (int j = 1; j <= K; ++j)
		b[0][j][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= K; ++j){
			b[i][j][0] = (b[i][j - 1][0] + b[i][j - 1][1]) % M;
			b[i][j][1] = ((b[i - 1][j - 1][0] + b[i - 1][j - 1][1]) * 2 + b[i - 1][j][1]) % M;
		}

	for (int i = 2; i <= 2 * K; ++i){
		int t1 = ~i & 1;
		int t2 = min(K, i - 1) - max(1, i - K) + 1 - t1;
		int t3 = K - t1 - t2;
		t2 >>= 1;

		eput(t1, t2, t3);
		eput(calc(n, t2, t3));
		eput(calc(n - 1, t2, t3));

		ll ans = (calc(n, t2, t3) + (t1 ? calc(n - 1, t2, t3) : 0)) % M;
		printf("%lld\n", (ans % M + M) % M);
	}

	return 0;
}


Measured memory_bytes: 317568
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9+7

N, M = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
l, r = 0, 10**6
while l+1 < r:
    m = (l+r)//2
    cnt = 0
    for a in A:
        cnt += N-bisect_left(A, m-a)
    if cnt < M:
        r = m
    else:
        l = m
f = [0]+A[::-1]
for i in range(N):
    f[i+1] += f[i]
cnt, ans = 0, 0
for a in A:
    i = bisect_right(A, l-a)
    ans += f[N-i]+(N-i)*a
    cnt += N-i
print(ans+(M-cnt)*l)


Measured memory_bytes: 14428
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 998244353
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define pii pair<int,int>
#define L LLONG_MAX
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<int>prime(15000005,0);
ll mM(ll a,ll b,ll p=hell){ll res = 0;if(a>=p)a %= p;while(b){if (b & 1ll)res = (res + a);if(res>=p) res%= p;a = (2 * a); if(a>=p)a%=p;b >>= 1ll;}return res;}
ll fpow(ll x,ll y,ll p=hell){if(x>=p)x=x%p;ll res=1;while(y){if(y&1ll)res*=x;if(res<0)res+=p;if(res>=p)res%=p;y=y>>1ll;x*=x;if(x<0)x+=p;if(x>=p)x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;ll temp=x+y;if(temp>=p)temp%=p;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(int i=2;i<=15000000;i++)
        if(!prime[i])
            for(int j=i;j<=15000000;j+=i)
            	if(!prime[j])
            		prime[j] = i;
}*/
int main(){
	ios
	int t = 1,tc = 0;
	//cin >> t;
	while(t--){
		int n, k;
		cin >> n >> k;
		vector<int>a(n), dp(n, INT_MAX);
		for (int i = 0; i < n; i++)
			cin >> a[i];
		dp[0] = 0;
		for (int i = 1; i < n; i++)
			for (int j = 1; j <= k; j++)
				if (i>=j)
					dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
		cout << dp[n-1] << "\n";
	}
}


Measured memory_bytes: 3996
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ret = r[0] - r[1];
            if (ret < 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(ret);
            }

        }
        
    }
}

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

#define ll long long

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		printf ("0\n");
		return 0;
	}
	if ((a + b) % 2 == 1)
		printf ("IMPOSSIBLE\n");
	else printf("%d\n", (a + b) / 2);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int N, M;
  int field[1001], op[1001];
  while(cin >> N >> M){
    if(N == 0 && M == 0) break;
    for(int i = 0 ; i < N ; i++) cin >> field[i];
    for(int i = 0 ; i < M ; i++) cin >> op[i];

    int now = 0, cnt = 0;
    for(int i = 0 ; i < M ; i++){
      if(now >= N-1) break;
      cnt++;
      now += op[i];
      now += field[now];
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main() {
    string n;
    cin >> n;
    if (n.at(0) == '7' || n.at(1) == '7' || n.at(2) == '7') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef pair<int, int> P;

P f(int x){
  int a = x % 10;
  int b;
  while(x){
    b = x;
    x /= 10;
  }
  return P(a, b);
}

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

  map<P, int> mp;

  for(int i = 1; i <= n; i++){
    P p = f(i);
    mp[p]++;
  }

  int ans = 0;
  for(int i = 1; i <= n; i++){
    P p = f(i);
    P q(p.second, p.first);
    ans += mp[q];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define pb          push_back
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pi          3.14159265358979323


void solve()
{
       ll n; cin>>n;
       ll a[n];
       rep(i,0,n) cin>>a[i];
       sort(a,a+n);
       if(n&1) {cout<<0<<endl; return; }
       ll mid=n/2-1;
       ll ans=a[mid+1] - a[mid];
       cout<<ans<<endl;
}


int main() {
	int T = 1;
//     pre();
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int m,n;
int i,j,set,mark[8][8][8][8][8][8][8],q[1000000][10];

void swap (int* x,int* y){
	int z;
	z=*x;
	*x=*y;
	*y=z;
}

int check(int a[]){
	int k;
	for(k=0;k<8;k++){if(a[k]!=k)return 0;}
	return 1;
}

int look(int a[],int dir){
	j++;
	int k;
	for(k=0;k<10;k++)q[j][k]=a[k];
	if(dir==0){swap(&q[j][q[j][8]],&q[j][q[j][8]-1]);q[j][8]--;}
	if(dir==1){swap(&q[j][q[j][8]],&q[j][q[j][8]+1]);q[j][8]++;}
	if(dir==2){swap(&q[j][q[j][8]],&q[j][q[j][8]-4]);q[j][8]-=4;}
	if(dir==3){swap(&q[j][q[j][8]],&q[j][q[j][8]+4]);q[j][8]+=4;}
	q[j][9]++;
	if(mark[q[j][0]][q[j][1]][q[j][2]][q[j][3]][q[j][4]][q[j][5]][q[j][6]]==set){j--;return 0;}
	else mark[q[j][0]][q[j][1]][q[j][2]][q[j][3]][q[j][4]][q[j][5]][q[j][6]]=set;
	if(check(q[j]))return q[j][9]; else return 0;
}

int inspect(int a[]){
	if(a[8]%4>0 && look(a,0))return q[j][9];
	if(a[8]%4<3 && look(a,1))return q[j][9];
	if(a[8]>3 && look(a,2))return q[j][9];
	if(a[8]<4 && look(a,3))return q[j][9];
	return 0;
}


int main(){
	while(1){
		set++;
		for(i=0;i<8;i++){
			if(scanf("%d",&q[0][i])==EOF)goto exit;
			if(q[0][i]==0)q[0][8]=i;
		}
		q[0][9]=0;
		if(check(q[0]))printf("0\n");
		else{
			i=0;j=0;
			mark[q[0][0]][q[0][1]][q[0][2]][q[0][3]][q[0][4]][q[0][5]][q[0][6]]=set;
			while(!inspect(q[i])){
				i++;
			}
			printf("%d\n",q[j][9]);
		}
	}
	exit:;
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& (a) : (x))
#define all(x) (x).begin (), (x).end ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair<int, int> pii;
#define fi first
#define se second
#define mkp(x) make_pair ((x))

typedef vector<int> vi;
#define pb(x) push_back ((x))

#define DEBUG 0
#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)


int main ()
{
    int i, j;
    int N;
    ll fat = 0;
    double m = 0;
    scanf ("%d", &N);
    vector <pii> pt (N);
    trav (a, pt)
        scanf ("%d %d", &(a.fi), &(a.se));
    sort (all (pt));
    do
    {
        fat++;
        ddprintf ("%lf | ", m);
        trav (a, pt)
            ddprintf ("<%d, %d> ", a.fi, a.se);
        ddprintf ("\n");
        for (i = 1; i < pt.size (); i++)
            m += hypot (pt[i - 1].fi - pt[i].fi,
                    pt[i - 1].se - pt[i].se);
    } while (next_permutation (all (pt)));
    printf ("%.10lf\n", m / fat);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

LL dfs(vector<map<PII,LL>> &memo, VP &order, VLL &a, int n, int idx, int l, int r) {
    if (idx == n) return 0;
    if (memo[idx].count(MP(l,r)) > 0) return memo[idx][MP(l,r)];
    LL ret = 0;
    chmax(ret, dfs(memo, order, a, n, idx+1, l + 1, r) + a[order[idx].second] * abs(order[idx].second - l));
    chmax(ret, dfs(memo, order, a, n, idx+1, l, r - 1) + a[order[idx].second] * abs(order[idx].second - r));
    //cerr << idx << ", " << "[" << l << ", " << r << "] " << ret << endl;
    return memo[idx][MP(l,r)] = ret;
}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    vector<map<PII,LL>> memo(n);
    VP order;
    REP(i,0,n) order.pb(a[i], i);
    sort(all(order), greater<PII>());
    //REP(i,0,n) cout << order[i].first << ", " << order[i].second << endl;
    //dfs(memo, order, a, n, 0, 0, n - 1);
    cout << dfs(memo, order, a, n, 0, 0, n - 1) << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 129104
n, m, c  = map(int, input().split())
b = list(map(int, input().split()))
s = 0
for i in range(n):
    a = list(map(int, input().split()))
    t = 0
    for j in range(m):
        t += a[j]*b[j]
    if t+c > 0:
        s += 1
print(s)

Measured memory_bytes: 3060
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    X = sorted(list(map(int,input().split())))

    if X[0] == X[1] and X[0] != X[2]:
        print("Yes")
    elif X[0] != X[1] and X[1] == X[2]:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
  main()


Measured memory_bytes: 12244
using System;
using System.Linq;

namespace AtCoder20170211 {
	class Program {
		static void Main(string[] args) {
			//QuestionOne();
			QuestionTwo();
		}

		static void QuestionOne() {
			decimal n = Convert.ToDecimal(Console.ReadLine());
			decimal k = Convert.ToDecimal(Console.ReadLine());
			decimal x = Convert.ToDecimal(Console.ReadLine());
			decimal y = Convert.ToDecimal(Console.ReadLine());

			decimal result = 0;

			if (n > k) {
				result = k * x;
				result += (n - k) * y;
			}
			else {
				result = n * x;
			}
			Console.WriteLine(result);
		}

		static void QuestionTwo() {
			var w = Console.ReadLine();

			for (var i = 'a'; i <= 'z'; i++) {
				var count = w.Where(c => c == i).Count();
				if(count % 2 != 0) {
					Console.WriteLine("No");
					return;
				}
			}
			Console.WriteLine("Yes");
		}
	}
}


Measured memory_bytes: 2776
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
long long p = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
int inf = 1000000000000000;
int sz = 524288;
vel seg(2*sz,inf);
void cha(int pot,int val) {
	pot += sz;
	while (pot > 0) {
		mmin(seg[pot],val);
		pot /=2;
	}
}
int mini(int l, int r) {
	int ans = inf;
	l += sz; r += sz;
	while (l <= r) {
		if (l % 2 == 1) { mmin(ans, seg[l]); }
		l += 1; l /= 2;
		if (r % 2 == 0) { mmin(ans, seg[r]); }
		r--; r /= 2;
	}
	return ans;
}
signed main() {
	int n, m; cin >> n >> m;
	vel l(m), r(m), c(m);
	V<V<pin>> list(n);
	rep(i, m) { 
		cin >> l[i] >> r[i] >> c[i]; l[i]--; r[i]--;
		list[l[i]].push_back(mkp(r[i], c[i]));
	}
	vel dp(n, inf); dp[n-1] = 0;
	cha(n-1, 0);
	for (int i = n - 1; i >= 0; i--) {
		for (auto x : list[i]) {
			mmin(dp[i], mini(i + 1, x.first) + x.second);
		}
		cha(i, dp[i]);
	}
	if (dp[0] == inf) { cout << -1 << endl; return 0; }
	cout << dp[0] << endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    sort(a.begin(),a.end());
    ll ans=1;
    rep(i,n){
        if(a[i]==0){
            ans=0;
            break;
        }
        if(ans>INF/a[i]){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4052
import java.util.*;
public class Main{
	public static final Scanner sc = new Scanner(System.in);
  	public static void main(String[] arg){
		 long a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt(), d=sc.nextInt();
         long n=sc.nextInt();
         a *= 4;
         b *= 2;
         long small = Math.min(Math.min(a, b), c);
         long ans;
      	 ans = Math.min(small*n, d*(n/2) + small*(n%2));
         System.out.println(ans);
    }
}


Measured memory_bytes: 35636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*V = map(int,read().split())

vals = []
for L in range(N+1):
    for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get))

answer = max(vals)
print(answer)


Measured memory_bytes: 9240
#include<iostream>
using namespace std;
int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++)
        for(int j=0;j<=k;j++){
            int ij=s-i-j;
            if(ij<=k&&ij>=0)ans++;
        }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,ans=1e9,cntw=0,cnte=0,cnt;
string s;
int main(){
  cin >> n >> s;
  for(int i=0;i<n;i++){
  	if(s[i]=='E'){
  		cnte++;
  	}
  }
  for(int i=0;i<n;i++){
  	cnt=0;
  	cnt+=cnte;
  	cnt+=cntw;
  	if(s[i]=='W'){
  		cntw++;
  	}
  	else{
  		cnte--;
  	}
  	ans=min(ans,cnt);
  }
  cnte=0;cntw=0;cnt=0;
  for(int i=0;i<n;i++){
  	if(s[i]=='W'){
  		cntw++;
  	}
  }
  for(int i=n-1;i>=0;i--){
  	cnt=0;
  	cnt+=cnte;
  	cnt+=cntw;
  	if(s[i]=='W'){
  		cntw--;
  	}
  	else{
  		cnte++;
  	}
  	ans=min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    string S; cin >> S;
    
    int ans = 0;

    for (int i = 0; i < S.size(); i++) {
        string a = S.substr(0, i + 1);
        string b = S.substr(i + 1, S.size() - (i + 1));
        vector<int> achars(26, 0);
        vector<int> bchars(26, 0);
        
        for (int k = 0; k < a.size(); k++)
            achars[a[k]-'a']++;
        for (int k = 0; k < b.size(); k++)
            bchars[b[k]-'a']++;

        int c = 0;
        for (int k = 0; k < 26; k++)
            if (achars[k] > 0 && bchars[k] > 0)
                c++;

        chmax(ans, c);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int x=1,y=1,i;
for(i=0;i<=3000;i++){
	cin>>x>>y;
	if(x==0&&y==0){
	break;
	}
	if(x<=y){cout<<x<<" "<<y<<endl;}
	else if(x>=y){cout<<y<<" "<<x<<endl;}
}
return 0;
}



Measured memory_bytes: 3064
import java.awt.Point;
import java.util.Arrays;
import java.util.Scanner;

public class Main{

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

	private Scanner scan;
	private int H,W;
	private char[][] tiles;

	private boolean[][] history;

	private void mainrun() {
		scan = new Scanner(System.in);

		while(true) {
			H = scan.nextInt();
			W = scan.nextInt();

			if(H == 0 || W == 0) {
				break;
			}

			tiles = new char[H][W];
			history = new boolean[H][W];

			for(int i = 0;i < H;i++) {
				tiles[i] = scan.next().toCharArray();
				Arrays.fill(history[i], false);
			}

			tileMove();
		}
		scan.close();
	}

	private Point p = new Point(0 , 0);

	private void tileMove() {
		p.x = p.y = 0;

		while(true) {
			if(history[p.y][p.x]) {
				System.out.println("LOOP");
				break;
			}else {
				history[p.y][p.x] = true;

				switch(tiles[p.y][p.x]) {
				case '>'	: p.x++ ; break;
				case '<'	: p.x-- ; break;
				case 'v'	: p.y++ ; break;
				case '^'	: p.y-- ; break;
				case '.'	:
					System.out.println(p.x + " " + p.y);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 28456
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    elif H % 2 == 0:
        for i in range(H//2):
            if W % 2 == 0:
                print('#.'*int(W//2))
                print('.#'*int(W//2))
            elif W % 2 == 1:
                print('#.'*int((W-1)//2)+'#')
                print('.#'*int((W-1)//2)+'.')
    elif H % 2 == 1:
        for e in range((H-1)//2):
            if W % 2 == 0:
                print('#.'*int(W//2))
                print('.#'*int(W//2))
            elif W % 2 == 1:
                print('#.'*int((W-1)//2)+'#')
                print('.#'*int((W-1)//2)+'.')
        if W % 2 == 0:
            print('#.'*int(W//2))
        elif W % 2 == 1:
            print('#.'*int((W-1)//2)+'#')
    print()

Measured memory_bytes: 7668
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();
        if(S.length() + 1 != T.length()) {
            System.out.println("No");
            return;
        }
        if(S.equals(T.substring(0, S.length()))) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");


    }
}


Measured memory_bytes: 35668
n,M=map(int,input().split())
from math import factorial
i=2
c_list=[]
m=M
while not m==1:
    count=0
    while m%i==0:
        m=m//i
        count=count+1
    if not count==0:
        c_list.append(count)
    i=i+1
if M==1:
    print(1)
else:
    INF=10**9+7
    Sum=1
    for i in c_list:
        Sum=Sum*(factorial(n-1+i)//(factorial(n-1)*factorial(i)))
        Sum=Sum%INF
    print(Sum)


Measured memory_bytes: 114396
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  int a,b;
  cin>>a>>b;
  if(a<2*b){
     cout<<0<<endl;
  }
  else{
     cout<<a-2*b<<endl;
  }
}



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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std;

ll digits(ll n)
{
    ll digits=1;

    while(n) {
        if(n/=10) digits++;
    }
    return digits;
}

void func(ll x, v_ll &ans)
{
    if(digits(x) > 10) { return; }

    ll d = x % 10;

    ans.push_back(x*10+d);
    func(x*10+d, ans);

    if(d != 0) {
        ans.push_back(x*10+(d-1));
        func(x*10+(d-1), ans);
    }
    if(d != 9) {
        ans.push_back(x*10+(d+1));
        func(x*10+(d+1), ans);
    }
}

int main(void)
{
    int k;
    cin >> k;
    v_ll ans = {1,2,3,4,5,6,7,8,9};
    
    for(ll i = 1; i < 10; i++) {
        func(i, ans);
    }

    sort(ans.begin(), ans.end());
     cout << ans[k-1] << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 7024
#重み付きUnion-Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)
  
n,m = [int(i) for i in input().split()]
par = [-1]*n
wei = [0]*n

for i in range(m):
  l,r,d = [int(i) for i in input().split()]
  if not same(l-1,r-1):
    unite(l-1,r-1,d)
  else:
    if diff(l-1,r-1) == d:
      continue
    else:
      print('No')
      exit()

print('Yes')

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long ll;
#define ALL(V) V.begin(), V.end()
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}


VI Main(int N, int M, VI &P, VS &S)
{
    VI ans(2, 0);
    VI ACs(N, 0);
    VI WAs(N, 0);
    REP(i, M) {
        if(S[i] == "WA" && ACs[P[i]-1] == 0) WAs[P[i]-1]++;
        else if (S[i] == "AC" && ACs[P[i]-1] == 0) ACs[P[i]-1]++;
        else continue;
    }
    REP(i, N) {
        if(ACs[i] == 0) WAs[i] = 0;
    }
    ans[0] = accumulate(ALL(ACs), 0);
    ans[1] = accumulate(ALL(WAs), 0);
    return ans;
}

int main(void){
    int N, M;
    cin >> N >> M;
    VI P(M);
    VS S(M);
    REP(i, M) cin >> P[i] >> S[i];
    VI out = Main(N, M, P, S);
    cout << out[0] << ' ' << out[1] << endl;
    return 0;
}

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

int n;

int main()
{
	cin >> n;
	if(n % 2){
        cout << n * 2 << endl;
	}
	else{
        cout << n << endl;
	}


	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){

  int x,y;
  cin >> x >> y;
  if(x==0&&y==0) return 0;
  if(x>y) swap(x,y);
  cout << x SP y << endl;
  }
  return 0;
}



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

int main(){
  int n, p=1;
  cin >> n;
  for(int i=0; i<8; i++){
    if(n<p){
      cout << p/2;
      return 0;
    }
    else if(n==p){
      cout << p;
      return 0;
    }
    p*=2;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a)
typedef long double ld;
int main(){
  ll a,b;
  cin>>a>>b;
  
  ll ans =(a+b)/2;
  if((a+b)%2!=0)ans++;
  cout<<ans<<endl;
  
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; ++i)
        cin >> L[i];
    sort(L.begin(), L.end());

    int maxL = L.back();
    int sum = 0;
    for (int i = 0; i < N; ++i)
        sum += L[i];
    sum -= maxL;
    if (sum > maxL)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*(n)
b=[0]*(n)
c=[0]*(n)
for _ in range(n):a[_],b[_],c[_]=map(int,input().split())

INF=float("inf")
dpa=[-INF]*n
dpb=[-INF]*n
dpc=[-INF]*n
dpa[0]=a[0]
dpb[0]=b[0]
dpc[0]=c[0]

for i in range(1,n):
    dpa[i]=a[i]+max(dpb[i-1],dpc[i-1])
    dpb[i]=b[i]+max(dpc[i-1],dpa[i-1])
    dpc[i]=c[i]+max(dpa[i-1],dpb[i-1])
    
print(max(dpa[-1],dpb[-1],dpc[-1]))
    




Measured memory_bytes: 58328
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

long long nC2(long long n) {
    return n * (n - 1) / 2;
}

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

    int n;
    cin >> n;

    vector<int> a(n);
    REP(i, n) cin >> a[i];
    REP(i, n) a[i]--;

    vector<int> count(n);
    REP(i, n) count[a[i]]++;

    long long total = 0;
    REP(i, n) total += nC2(count[i]);

    REP(i, n) {
        long long ans = total;
        ans -= nC2(count[a[i]]);
        ans += nC2(count[a[i]] - 1);
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#define data m_data
using namespace std;
const int maxn=500000+5;
map<int,int> mp;
int data[maxn],a[maxn],ans[4*maxn];
struct node{
    int l,r,id;
    bool operator<(node t)const{
        return r<t.r;
    }
}q[4*maxn];
 
int lowbit(int x)
{
    return x&-x;
}
 
int Get_sum(int i)
{
    int ans=0;
    while(i>0){
        ans+=data[i];
        i-=lowbit(i);
    }
    return ans;
}
 
void Update(int i,int x)
{
    while(i<maxn){
        data[i]+=x;
        i+=lowbit(i);
    }
}
 
void solve(int T)
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].id=i;
    }
    sort(q,q+m);
    int pre=1;
    for(int i=0;i<m;i++)
    {
        for(int j=pre;j<=q[i].r;j++)
        {
            if(mp[a[j]]!=0)
                Update(mp[a[j]],-1);
                Update(j,1);
                mp[a[j]]=j;
            }
            pre=q[i].r+1;
            ans[q[i].id]=Get_sum(q[i].r)-Get_sum(q[i].l-1);
    }
    for(int i=0;i<m;i++)
        printf("%d\n",ans[i]);
    return;
}

int main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


Measured memory_bytes: 38880
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

const int MAXN = 100000;

int h[MAXN];


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    rep(i, n) cin >> h[i];

    Graph G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int res = 0;
    rep(v, n) {
        bool ok = true;
        for (auto nv : G[v]) {
            if (h[nv] >= h[v]) ok = false;
        }

        if (ok) res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8740