akhauriyash/Code-Regression huggingface dataset:
#####segfunc#####
def segfunc(x, y):
    return max(x, y)
#################

#####ide_ele#####
ide_ele = int(0)
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n, k = map(int, input().split())
a = [0]*300002

seg = SegTree(a, segfunc, ide_ele)
for _ in range(n):
    aa = int(input())

    m = seg.query(max(0,aa-k), min(aa+k,300000)+1)
    seg.update(aa, m+1)

print(seg.query(0, 300000))

Measured memory_bytes: 112740
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
from collections import defaultdict

class UnionFind:
    def __init__(self, N=None):
        if N is None or N < 1:
            self.parent = defaultdict(lambda: -1)
        else:
            self.parent = [-1]*int(N)

    def root(self, n):
        if self.parent[n] < 0:
            return n
        else:
            m = self.root(self.parent[n])
            self.parent[n] = m
            return m

    def merge(self, m, n):
        rm = self.root(m)
        rn = self.root(n)
        if rm != rn:
            if -self.parent[rm] < -self.parent[rn]:
                rm, rn = rn, rm
            self.parent[rm] += self.parent[rn]
            self.parent[rn] = rm

    def size(self, n):
        return -self.parent[self.root(n)]
    
    def connected(self, m, n):
        return self.root(m) == self.root(n)
    
    def groups(self):
        if isinstance(self.parent,list):
            return list(map(lambda x: x<0, self.parent)).count(True)
        else: # self.parent: defaultdict
            return list(map(lambda x: x<0, self.parent.values())).count(True) 

class CountUp:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

Xi = defaultdict(CountUp())
Yi = defaultdict(CountUp())
N = int(input())
xy = []
for _ in range(N):
    x, y = inpl()
    xi = Xi[x]
    yi = Yi[y]
    xy.append((xi,yi))
Nx = len(Xi)
Ny = len(Yi)
Nxy = Nx + Ny
uf = UnionFind(Nx+Ny)
for xi, yi in xy:
    uf.merge(xi,yi+Nx)

gi = defaultdict(CountUp())
Ng = uf.groups()
edges = [0]*Ng
nx = [0]*Ng
ny = [0]*Ng
for i in range(Nx):
    nx[gi[uf.root(i)]] += 1
for i in range(Nx,Nxy):
    ny[gi[uf.root(i)]] += 1
for xi, yi in xy:
    edges[gi[uf.root(xi)]] += 1

ans = 0
for g in range(Ng):
    ans += nx[g]*ny[g] - edges[g]
print(ans)

Measured memory_bytes: 84056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
const int N=10005;
const int mod=1e9+7;
const int maxn=1e7;

int main()
{
    int n;
    while(cin>>n){
        int a=n/100;
        int b=(b-a*100)/10;
        int c=n%10;
        if(a==c) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int s,h,m,ss;
  scanf("%d",&s);
  h=s/3600;
  m=(s-h*3600)/60;
  ss=s-(h*3600+m*60);
  printf("%d:%d:%d\n",h,m,ss);
  return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
typedef long long ll;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 7;
using namespace std;
int mod = 998244353, inv[maxn];
int g[maxn], prime[maxn], tot;
int cnt[maxn], f[maxn];
bool check[maxn];
ll qpow(ll a, ll n){
    ll ans = 1;
    for(a %= mod; n; n >>= 1){
        if(n & 1) ans = ans * a % mod;
        a = a * a % mod;
    }
    return ans;
}
ll invf(ll x){
    return qpow(x, mod - 2);
}
void init(int n){
    inv[1] = 1;
    for(int i = 2; i <= n; i++){
        inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
    }
    g[1] = 1;
    tot = 0;
    for(int i = 2; i <= n; i++){
        if(!check[i]){
            prime[tot++] = i;
            g[i] = (inv[i] - 1 + mod) % mod;
        }
        for(int j = 0, u; j < tot && (u = i * prime[j]) <= n; j++){
            check[u] = 1;
            if(i % prime[j] == 0){
                int x = i, tmp = 0;
                while(x % prime[j] == 0){
                    tmp++;
                    x /= prime[j];
                }
                ll res = (inv[prime[j]] - 1 + mod) * qpow(inv[prime[j]], tmp) % mod;
                g[u] = g[x] * res % mod;
                break;
            }else{
                g[u] = 1ll * g[i] * g[prime[j]] % mod;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j += i){
            f[i] += 1ll * j * cnt[j] % mod;
            f[i] %= mod;
        }
    }
    for(int j = 1; j <= n; j++){
        f[j] = 1ll * f[j] * f[j] % mod;
    }
}
int main(void){
#ifdef ljxtt
freopen("data.in", "r", stdin);
#endif
    int n; scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        int t; scanf("%d", &t);
        cnt[t]++;
    }
    init(maxn - 1);
    int ans = 0;
    for(int i = 1; i < maxn; i++){
        ans += 1ll * g[i] * f[i] % mod;
        ans %= mod;
    }
    int res = 0;
    for(int i = 1; i < maxn; i++){
        res += 1ll * i * cnt[i] % mod;
        res %= mod;
    }
    ans -= res;
    ans = (ans % mod + mod) % mod;
    ans = (ans * invf(2)) % mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 20744
if __name__ == '__main__':

    n = int(input())

    A = list(map(int,input().split()))

    top = A[0]
    ans = 0
    for i in range(n-1):
        if top > A[i+1]:
            ans += top - A[i+1]
        else:
            top = A[i+1]
    print(ans)

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

using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  int a, b;
  cin >> a >> b;
  cout << (b % a ? b - a : a + b) << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e5 + 3, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
string s;
int dp[N][2][2][2] = { };
int solve(int idx, bool a, bool b, bool c) {
	if (idx >= (int) s.size())
		return (a && b && c);
	int &ret = dp[idx][a][b][c];
	if (~ret)
		return (ret % mod);
	ret = 0;
	if (s[idx] == '?')
		ret += ((solve(idx + 1, a, b, c) * 3LL) % mod);
	else
		ret += solve(idx + 1, a, b, c);
	if (ret >= mod)
		ret %= mod;
	if (s[idx] == 'A' || s[idx] == '?') {
		if (!a)
			ret += solve(idx + 1, true, b, c);
	}
	if (ret >= mod)
		ret %= mod;
	if (s[idx] == 'B' || s[idx] == '?') {
		if (!b && a)
			ret += solve(idx + 1, a, true, c);
	}
	if (ret >= mod)
		ret %= mod;
	if (s[idx] == 'C' || s[idx] == '?') {
		if (!c && a && b)
			ret += solve(idx + 1, a, b, true);
	}
	if (ret >= mod)
		ret %= mod;
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	cin >> s;
	clr(dp, -1);
	cout << solve(0, 0, 0, 0) << "\n";
	return 0;
}

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

int compare(string A,string B){
  if(A.size()!=B.size()) return A.size()<B.size();

  for(int i=0;i<A.size();i++)
    if(A[i]!=B[i]) return A[i]<B[i];

  return -1;
  
}

int main(){
  string A,B;
  cin>>A>>B;

  int ans = compare(A,B);
  if(ans == 0)cout<<"GREATER"<<endl;
  if(ans == 1)cout<<"LESS"<<endl;
  if(ans == -1)cout<<"EQUAL"<<endl; 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mii map<int,int>
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define wh(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll bpow(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
vvl mat_mul(vvl mat1,vvl mat2,ll mod1){
        vvl res(sz(mat1),vl(sz(mat2[0]),0));
        far(i,0,sz(mat1)-1){
                far(j,0,sz(mat2[0])-1){
                        far(k,0,sz(mat1[0])-1){
                                res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%mod1)%mod1;          
                        }   
        }   
        }   
        return res;
}
vvl mat_exp(vvl mat,ll p,ll mod1){ 
        vvl res(sz(mat),vl(sz(mat[0]),0));
        far(i,0,sz(mat)-1) res[i][i]=1;
        while(p>0){
                if(p&1) res=mat_mul(res,mat,mod1);   
                mat=mat_mul(mat,mat,mod1);
                p>>=1;
        }   
        return res;
}
const int N=2*1e5+5;
ll n,m,q,t,k,x,y,z,ans;

int main()
{
	fio;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	x=c*d/gcd(c,d);
	ans+=b/c + b/d - b/x;
	a--;
	ans-=a/c + a/d - a/x;
	a++;
	cout << b-a+1-ans << nl;
}


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

using namespace std;

const int MAXN = 1005;
const double INF = 1e18;

int N;
double x[MAXN], y[MAXN], r[MAXN];
double dist[MAXN][MAXN];

double dis(double x1, double y1, double x2, double y2)
{
    return hypot(x1-x2, y1-y2);
}

int main()
{
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> N;
    r[0] = r[1] = 0;
    for(int i=0; i<N ; ++i)
        cin >> x[2+i] >> y[2+i] >> r[2+i];

    for(int i=0 ; i<N+2 ; ++i)
    {
        for(int j=0 ; j<N+2 ; ++j)
        {
            dist[i][j] = 0;
            if(i!=j)
            {
                double d = dis(x[i], y[i], x[j], y[j]);
                if(d > r[i]+r[j])
                {
                    dist[i][j] = d - r[i] - r[j];
                }
            }
        }
    }

    double d[MAXN];
    bool isInQ[MAXN];

    for(int i=0 ; i<MAXN ; ++i)
    {
        d[i] = INF;
        isInQ[i] = false;
    }

    d[0] = 0;
    queue<int> Q;
    Q.push(0);
    isInQ[0] = true;

    while(!Q.empty())
    {
        int cur = Q.front();
        Q.pop();
        isInQ[cur] = false;
        for(int i=0 ; i<2+N ; ++i)
        {
            if(i!=cur)
            {
                if(d[cur]+dist[cur][i] < d[i])
                {
                    d[i] = d[cur]+dist[cur][i];
                    if(!isInQ[i])
                    {
                        Q.push(i);
                        isInQ[i] = true;
                    }
                }
            }
        }
    }

    cout  << fixed  <<  setprecision(9) << d[1] << '\n';

    return 0;
}


Measured memory_bytes: 8192
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] inputstr = Console.ReadLine().Split(' ');
        int num = int.Parse(inputstr[3]);
        int[] card = new int[3];
        int[] cardnum = {1,0,-1};
        int cnt = 0;
        foreach(string s in inputstr)
        {
            card[cnt] = int.Parse(s);
            cnt++;
            if(cnt > 2)
            {
                break;
            }

        }

        int sum = 0;
        cnt = 0;
        foreach(int i in card)
        {
            if(i <= num )
            {
                num -= i;
                sum += (i * cardnum[cnt]);
            }
            else
            {
                sum += (num * cardnum[cnt]);
                num = 0;
            }
            if(num <= 0)
            {
                break;
            }
            cnt++;
        }
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 27496
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1195&lang=jp

vector<string> str;

bool check(string words, string& S) {
	int alpha[26] = { 0 }; alpha[0] = 1;
	for (int i = 0; i < words.length(); i++) {
		if (alpha[words[i] - 'a'] != 0) {
			if (words[i] != S[i])return false;
			continue;
		}
		alpha[words[i] - 'a'] = 1;
		words[i] = (char)(words[i] - 1);
		if (words[i] != S[i])return false;
	}
	return words == S;
}

void rec(int n,string words, string& S) {
	if (words.length() == S.length()) {
		if (check(words, S)) {
			str.push_back(words);
		}
		return;
	}

	rec(n + 1, words + S[n], S);
	rec(n + 1, words + char(S[n] + 1), S);
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	string S;
	while (cin >> S) {
		if (S == "#")break;
		str.clear();
		rec(0, "", S);

		cout << str.size() << endl;
		if (str.size() <= 10) {
			for (auto s : str) cout << s << endl;
		}
		else {
			for (int i = 0; i < 5;i++) cout << str[i] << endl;
			for (int i = str.size() - 5; i < str.size(); i++) cout << str[i] << endl;
		}
	}
}

Measured memory_bytes: 4364
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: i64,
        arr: [usize1; n]
    }
    let mut dist = vec![-1; n];
    let mut queue = VecDeque::new();
    let mut to = 0;
    let mut loopstartindex = 0;
    let mut loopendindex = 0;
    dist[0] = 0;
    queue.push_back(0);
    for i in 1..n+1 {
        let to2 = arr[to];
        if dist[to2] != -1 {
            loopstartindex = dist[to2];
            break;
        }
        dist[to2] = i as i64;
        queue.push_back(to2);
        to = to2;
        loopendindex = i;
    }
    let loopsize = loopendindex as i64 + 1 - loopstartindex;
    let distsize_without_loop = if k > loopstartindex {(k - loopstartindex) % loopsize + loopstartindex} else {k};
    for _ in 0..distsize_without_loop {
        queue.pop_front();
    }

    println!("{}", queue[0] + 1);
}


Measured memory_bytes: 6572
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()	
	{
		string S = Console.ReadLine();
		int flag = 0;
		for(int i = 0; i < S.Length; i++)
			flag |= (1 << (int)(S[i] - 'a'));
		if(flag == ((1 << 26) - 1))
		{
			Console.WriteLine("None");
		}
		else
		{
			for(int i = 0; i < 26; i++)
			{
				if(((flag >> i) & 1) == 1)
					continue;
				Console.WriteLine((char)(i + 'a'));
				break;
			}
		}
	}
}





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

const int size = 101;
int n;
double X[size];
double Y[size];
double D[size];
bool used[size];

double getCross( double x1, double y1, double x2, double y2 ) {
    return x1 * y2 - y1 * x2;
}

double getDistance( double x1, double y1, double x2, double y2 ) {
    double X = x2 - x1;
    double Y = y2 - y1;
    return X * X + Y * Y;
}

double getDistance( double x, double y ) {
    return getDistance( 0, 0, x, y );
}

void init() {
    for ( int i = 0; i < size; i++ ) {
        used[i] = false;
    }
}

int solve() {
    init();

    bool first = true;
    int pivot;
    double mind;
    for ( int i = 0; i < n; i++ ) {
        if ( first || D[i] < mind ) {
            pivot = i;
            mind = D[i];
            first = false;
        }
    }

    int cnt = 1;
    used[pivot] = true;

    for ( int k = 0; k < n-1; k++ ) {
        for ( int i = 0; i < n; i++ ) {
            if ( used[i] ) continue;
            bool flag = true;
            for ( int j = 0; j < n; j++ ) {
                if ( i == j ) continue;
                double c = getCross( X[i] - X[pivot], Y[i] - Y[pivot], X[j] - X[pivot], Y[j] - Y[pivot] );
                if ( c < 0.0 ) {
                    flag = false;
                    break;
                }
            }
            if ( flag ) {
                cnt++;
                used[i] = true;
                pivot = i;
                break;
            }
        }
    }
    
    return n - cnt;
}

int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; i++ ) {
            string line;
            cin >> line;
            replace( line.begin(), line.end(), ',', ' ' );
            istringstream is( line );
            is >> X[i] >> Y[i];
            X[i] += 2000.0;
            Y[i] += 2000.0;
            D[i] = getDistance( X[i], Y[i] );
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <vector>

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int k)
    {
        if (data[k] < 0)
            return k;
        data[k] = root(data[k]);
        return data[k];
    }

    int size(int k)
    {
        return (-data[root(k)]);
    }

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

struct BipartiteGraph : UnionFind
{
    vector<int> color;

    BipartiteGraph(int N) : color(2 * N, -1), UnionFind(2 * N) {}

    /*
    color u, v by same color ->  unite(u, v) && unite(u + N, v + N)
    color u, v by different color -> unite(u + N, v) && unite(u, v + N)
    */

    bool BG_unite(int u, int v, bool same)
    {
        int N = ((int)color.size()) / 2;
        if (same == true)
        {
            unite(u, v);
            unite(u + N, v + N);
        }
        else
        {
            unite(u + N, v);
            unite(u, v + N);
        }
    }

    // 0, 1, ..., v - 1 -> left; v, v + 1, ..., 2 * v - 1 -> right;
    bool BG_coloring()
    {
        int N = ((int)color.size()) / 2;
        for (int i = 0; i < N; i++)
        {
            int s = root(i), t = root(i + N);
            if (s == t)
                return false;
            if (color[s] < 0)
                color[s] = 0, color[t] = 1;
        }
        return true;
    }

    //return k's color
    bool operator[](int v)
    {
        return (bool)(color[root(v)]);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;
    BipartiteGraph bg(N);

    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        bg.BG_unite(a, b, 0);
    }

    if (bg.BG_coloring() == false)
    {
        ll a = N, b = M;
        cout << a * (a - 1) / 2 - b << endl;
    }
    else
    {
        map<bool, int> mp;
        for (int i = 0; i < N; i++)
        {
            mp[bg[i]]++;
        }
        ll a = mp[false], b = mp[true], c = M;
        cout << a * b - c << endl;
    }
}


Measured memory_bytes: 1792
def GCD(a, b):
    if(a % b == 0):
        return(b)
    return(GCD(b, a % b))

N, X = map(int, input().split())
x = []
x = list(map(int, input().split()))
for i in range(N):
    x[i] = abs(X - x[i])
if(N == 1):
    print(x[0])
else:
    gcd = GCD(x[0], x[1])
    for i in range(N - 2):
        gcd = GCD(gcd, x[i + 2])
    print(gcd)

Measured memory_bytes: 14480
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n, c, k;
    cin >> n >> c >> k;
    VI t(n);
    REP(i, n) {
        cin >> t[i];
    }
    SORT(t);

    int ans = 0, temp = 0, limit = INT_MAX;
    REP(i, n) {
        if (temp >= c || limit < t[i]) {
            ans++;
            temp = 0;
            limit = INT_MAX;
        }
        temp++;
        limit = min(t[i] + k, limit);
    }

    if (temp > 0) {
        ans++;
    }

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


Measured memory_bytes: 1024
N, C = [int(_) for _ in input().split()]
xv = [[int(_) for _ in input().split()] for i in range(N)]

def solve(N, C, xv):
    
    from itertools import accumulate

    xs = [0] + [_[0] for _ in xv] + [C]
    vs = [0] + [_[1] for _ in xv] + [0]
    xs_rev = [C - x for x in xs[::-1]]
    vs_rev = vs[::-1]

    ts = accumulate(vs)
    txs = [t - x for x, t in zip(xs, ts)]
    maxtxs = list(accumulate(txs, max))

    ts_rev = accumulate(vs_rev)
    txs_rev = [t - x for x, t in zip(xs_rev, ts_rev)]
    maxtxs_rev = list(accumulate(txs_rev, max))

    result = 0
    for i, tx in enumerate(txs_rev[:-1]):
        r = tx - xs_rev[i] + maxtxs[N - i]
        result = max(result, r)
    for i, tx in enumerate(txs[:-1]):
        r = tx - xs[i] + maxtxs_rev[N - i]
        result = max(result, r)

    return result

print(solve(N, C, xv))


Measured memory_bytes: 38448
from collections import deque

n, q = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

res = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    res[p-1] += x

d = deque()
d.append(0)
visited = [False] * n
while d:
    node = d.pop()
    visited[node] = True
    for next_node in edge[node]:
        if not visited[next_node]:
            res[next_node] += res[node]
            d.append(next_node)

for c in res:
    print(c, end=' ')

Measured memory_bytes: 104908
#include<bits/stdc++.h>
using namespace std;
int main()
{
      long long n,x,t;
      string str;
      cin>>str;
      long long l=str.size();
      long long sum=0;
     for(int i=0;i<l;i++)
     {
           x=str[i]-'0';
           sum+=x;

     }
     if(sum%9==0)
      cout<<"Yes"<<endl;
      else
      cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3720
#include <iostream>

using namespace std;

const int N = 200005;
const int Q = 200005;

string s;
int n, q;

char letters[Q];
char dir[Q];

int main() {
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; i++) {
        cin >> letters[i] >> dir[i];
    }

    int left = 0;
    int right = n - 1;

    while (left <= right) {
        int mid = (left + right) / 2;
        int pos = mid;
        for (int i = 0; i < q; i++) {
            if (letters[i] == s[pos]) {
                if (dir[i] == 'L') pos--;
                else pos++;
            }
            if (pos == -1) {
                break;
            }
        }

        if (pos == -1) {
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }

    int ans_left = right;

    left = 0;
    right = n - 1;

    while (left <= right) {
        int mid = (left + right) / 2;
        int pos = mid;
        for (int i = 0; i < q; i++) {
            if (letters[i] == s[pos]) {
                if (dir[i] == 'L') pos--;
                else pos++;
            }
            if (pos == n || pos == -1) {
                break;
            }
        }

        if (pos == n) {
            right = mid - 1;
        }
        else {
            left = mid + 1;
        }
    }

    int ans_right = left;

    cout << n - (ans_left + 1) - (n - ans_right);

}

Measured memory_bytes: 900
N = int(input())
A = list(map(int, input().split()))
max_A = max(A)
min_A = min(A)
if max_A - min_A >= 2:
    print("No")
elif max_A - min_A == 1:  # 他の猫とと色がかぶらない猫と、色が被る猫の両方が存在する
    M = A.count(max_A)
    print("Yes") if N - M + 1 <= max_A <= (N - M) + M // 2 else print("No")
else:  # 他の猫とと色がかぶらない猫が存在しない or 皆違う色
    print("Yes") if max_A <= N // 2 or max_A == N - 1 else print("No")


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

def getsum(p):
  s=str(p)
  sum=0
  for i in range(len(s)):
    sum+=int(s[i])
  return sum

min=n
for a in range(1,n):
  b=n-a
  w=getsum(a)+getsum(b)
  if min>w:
    min=w
print(min)

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

fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn cnt(s:&String)->Vec<u32>{
    let mut ret:Vec<u32> =vec![0;26];
    for c in s.chars(){
        ret[((c as i32) - ('a' as i32)) as usize] += 1;
    }
    ret.clone()
}

use std::cmp::min;

fn solve(v1:&Vec<u32>,v2:&Vec<u32>)->Vec<u32>{
    let mut v:Vec<u32> = vec![];
    for i in 0..26{
        v.push(min(v1[i], v2[i]));
    }
    v.clone()
}

fn prnt(v:&Vec<u32>){
    for i in 0..26{
        for _ in 0..v[i as usize]{
            print!("{}", (i+('a' as u8)) as char);
        }
    }
    println!("");
}

fn main() {
    let n: i32 = read();
    let ss: Vec<String> = read_col(n as u32);
    let mut cvv: Vec<Vec<u32>> = vec![];


    for i in 0..n{
        cvv.push(cnt(&ss[i as usize]));
    }

    let mut min = cvv[0].clone();

    for i in 1..n{
        min = solve(&min,&cvv[i as usize]);
    }

    prnt(&min);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k;
ll ans,mod=1000000007,c[100010],a[100010],f[100010];
ll po(ll x,ll p)
{
    if(p==0)
    {
        return 1;
    }
    ll ret=1;
    if(p%2)
    {
        ret=x;
        ret%=mod;
    }
    ll tem=po(x,p/2);
    ret*=tem;
    ret%=mod;
    ret*=tem;
    ret%=mod;
    return ret;
}
int main()
{
    scanf("%lld%lld",&n,&k);
    f[0]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",a+i);
        f[i]=f[i-1]*i;
        f[i]%=mod;
    }
    sort(a+1,a+n+1);
    for(ll i=k-1;i<=n;i++)
    {
        c[i]=f[i]*po(f[k-1],mod-2);
        c[i]%=mod;
        c[i]*=po(f[i-k+1],mod-2);
        c[i]%=mod;
    }
    for(int i=1;i<=n;i++)
    {
        ans-=c[n-i]*a[i];
        ans+=mod*1000000000;
        ans%=mod;
        ans+=c[i-1]*a[i];
        ans%=mod;
    }
    printf("%lld",ans);
}

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

using namespace std;

int main()
{
    int N,i;
    cin >> N;
    vector<int> p(N);
    for(i=0; i<N; i++){
        cin >> p.at(i);
    }

    int m=200000;
    int cnt =0;
    for(i=0; i<N; i++){
        if(p.at(i) <= m){
            m = p.at(i);
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    vector<vector<int>> c(3, vector<int>(3));
    for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> c[i][j];
    vector<int> a(3), b(3);
    b[0] = 0; a[0] = c[0][0]; b[1] = c[0][1] - c[0][0];
    b[2] = c[0][2] - c[0][0]; a[1] = c[1][0]; a[2] = c[2][0];
    string ans = "Yes";
    for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) {
        int test = a[i] + b[j];
        if(test != c[i][j]) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
let arr=readLine()!

 let characters = arr.characters

var c = 0
var o1 = ""
var o2 = ""
var p : String = ""
for var s in characters {

        if( c < 2 ) {
        p = String(s)
        o1 += p
    } else {
                p = String(s)
        o2 += p
        }
        c += 1
}

var x : Int = Int( o1 )!
var y : Int = Int( o2 )!

if( ( ( x > 0 ) && ( x <= 12 ) ) && ( ( y < 1 ) || ( y > 12 ) ) ) {
  print( "MMYY" )
} else if( ( ( x > 12 || x < 1 ) ) && ( ( y <= 12  ) && ( y > 0 ) ) ) {
  print( "YYMM" )
} else if( ( ( x > 0 ) && ( x <= 12 ) ) && ( ( y <= 12 ) && ( y > 0 ) ) ) {
  print( "AMBIGUOUS" )
} else {
  print( "NA" )
}

Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int K, S, c = 0;

  std::cin >> K >> S;

  for (int i = 0; i <= K; i ++)
    for (int j = 0; j <= K; j ++) {
      int Z = S - (i + j);

      if (0 <= Z && Z <= K)
        c ++;
    }

  std::cout << c << std::endl;
    
  return 0;
}


Measured memory_bytes: 888
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n;
    cin>>n;
    vector<string> s(n);
    ll sc[200009];
    rep(i,200009) sc[i]=0;
    rep(i,n){
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    ll cmax=0,cct=1;
    rep(i,n){
        if(i==0){
            sc[i]=1;
            cct=1;
            cmax = max(cmax,cct);
        }else{
            if(s[i]!=s[i-1]){
                sc[i]=1;
                cct=1;
                cmax = max(cmax,cct);
            }else{
                sc[i-cct]++;
                cct++;
                cmax = max(cmax,cct);
            }
        }
    }
    rep(i,n){
        if(sc[i]==cmax){
            cout<<s[i]<<endl;
        }
    }
}


Measured memory_bytes: 15872
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int h[200005],dp[200005];
void solve()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for (int i = 3; i <= n; i++)
	{
		dp[i] = min(abs(h[i - 1] - h[i]) + dp[i - 1], abs(h[i - 2] - h[i]) + dp[i - 2]);
	}
	cout << dp[n];
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner
import java.lang.Math.*

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val s1 = scn.next()
	val s2 = scn.next()
	val dp = Array(s1.length+1){IntArray(s2.length+1)}
	for (i in 1..s1.length) dp[i][0] = i
	for (j in 1..s2.length) dp[0][j] = j

	for (i in 1..s1.length){
		for(j in 1..s2.length){
			dp[i][j] = dp[i-1][j-1]
			if (s1[i-1]!=s2[j-1]) dp[i][j]++
			dp[i][j] = min( dp[i][j], min(dp[i-1][j], dp[i][j-1])+1 )
		}
	}
	println(dp[s1.length][s2.length])
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 50005

int main()
{
    _FastIO;

    int a , b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++){
        int x = i / 10000;
        int y = (i / 1000) % 10;
        int r = (i / 10) % 10;
        int t = i % 10;
        if(x == t && y == r)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  char s;
  cin >> s;
  if(s=='A') co('T');
  if(s=='C') co('G');
  if(s=='G') co('C');
  if(s=='T') co('A');
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()

{
	int build[4][3][10];
	int i,j,k;
	for(int i = 0;i<4;i++)
	{
		for(int j = 0;j<3;j++)
		{
			for(int k = 0;k<10;k++)
			{
				build[i][j][k] = 0;
			}
		}
	}
	int n = 0;
	scanf("%d",&n);
	while(n--)
	{
		int b,f,r,v;
		scanf("%d %d %d %d",&b,&f,&r,&v);
		build[--b][--f][--r]+=v;
	}
	for(i = 0;i<4;++i)
	{
		for(j = 0;j<3;++j)
		{
			for(k = 0;k<10;++k)
			{
				printf(" %d",build[i][j][k]);
			}
			printf("\n");
		}
		if(i !=3)
		{
			printf("####################\n");
		}
	
		
	}
	
	
}


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

int main() {
  int n;cin>>n;
  int a;
  ll s=0;
  vi dp(1e5+1, 0);
  rep(i,n) {
    cin>>a;
    dp[a]+=1;
    s += a;
  }
  
  int q;cin>>q;
  int b, c, x;
  rep(k,q) {
    cin>>b>>c;
    x = dp[b];
    if (x>0) {
      dp[b]=0;
      dp[c]+=x;
      s+= (c-b)*x;
    }
    cout<<s<<endl;
  }
  
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007


lli data[26];

string func(){
	string s="";
	for(lli i=0;i<26;i++){
		while(data[i]!=0){
			s.push_back(i+'a');
			data[i]--;
		}
	}
	if(DEBUG)cout<<s<<endl;
	return s;
}

signed main(){

	lli n;
	cin>>n;

	map<string,lli> ans;
	for(lli i=0;i<n;i++){
		string s;
		cin>>s;
		for(lli i=0;i<26;i++)data[i]=0;
		for(lli i=0;i<10;i++)data[s.at(i)-'a']++;

		ans[func()]++;
	}
	lli sum = 0;

	for(auto e:ans){
		lli tmp = e.second*(e.second-1)/2;
		sum += tmp;
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	if(d>e)swap(d,e);
	cout<<a+d-50<<endl;
	return 0;
	}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;

using namespace std;
ll calc(ll n)
{
	ll ans = 0;
	while(n)
		ans++,n/=10;
	return ans;
}
int main()
{
	abdelrahman001
	ll n,ans=1e9;
	cin >> n;
	for(int i = 1;i<=sqrt(n);i++)
		if(n%i == 0)
			ans = min(ans,max(calc(i),calc(n/i)));
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string S;
    cin >> S;
    int ret = 700;
    for (char c : S)
        if (c == 'o')
            ret += 100;
    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


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

const long double eps = 1e-10;

long double between_two(double ax, double ay, double bx, double by){
  return sqrt(pow(ax-bx,2) + pow(ay-by,2));
}

bool incircle(double x, double y, double r, double ax, double ay){
  return between_two(x,y,ax,ay) <= r + eps;
}

long double gaisin_y(double a, double b, double c, double d, double e, double f){
  long double bunshi = (e-a)*(a*a + b*b - c*c - d*d) - (c-a)*(a*a + b*b - e*e - f*f);
  long double bunbo = 2*(e-a)*(b-d) - 2*(c-a)*(b-f);
  return bunshi / bunbo;
}

long double gaisin_x(double a, double b, double c, double d, double e, double f){
  long double bunshi, bunbo;
  if(c != a){
    bunshi = 2*(b-d)*gaisin_y(a,b,c,d,e,f) - a*a - b*b + c*c + d*d;
    bunbo = 2*(c-a);
  }
  else{
    bunshi = 2*(b-f)*gaisin_y(a,b,c,d,e,f) - a*a - b*b + e*e + f*f;
    bunbo = 2*(e-a);
  }
  return bunshi / bunbo;
}
  

int main(){
  int N;
  cin >> N;
  vector<vector<double>> vec(N,vector<double>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec[i][j];
    }
  }
  double ans = 1000000;
  //2点の中点が中心の場合
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      double x = (vec[i][0] + vec[j][0])/2.0;
      double y = (vec[i][1] + vec[j][1])/2.0;
      double r = between_two(vec[i][0], vec[i][1], vec[j][0], vec[j][1]) / 2.0;
      bool ok = true;
      for(int k=0; k<N; k++){
        if(!incircle(x,y,r,vec[k][0],vec[k][1])){
          ok = false;
        }
      }
      if(ok){
        ans = min(ans,r);
      }
    }
  }
  
  
  //3点の外接円が中心の場合
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        double x = gaisin_x(vec[i][0],vec[i][1],vec[j][0],vec[j][1],vec[k][0],vec[k][1]);
        double y = gaisin_y(vec[i][0],vec[i][1],vec[j][0],vec[j][1],vec[k][0],vec[k][1]);
        double r = between_two(vec[i][0], vec[i][1],x,y);
        bool ok = true;
        for(int l=0; l<N; l++){
          if(!incircle(x,y,r,vec[l][0],vec[l][1])){
            ok = false;
          }
        }
        if(ok){
          ans = min(ans,r);
        }
      }
    }
  }
  cout << setprecision(20) << ans << endl;
}
  

Measured memory_bytes: 256