akhauriyash/Code-Regression huggingface dataset:
a = [list(map(int, input().split())) for _ in range(3)]

n = int(input())

bingo = [[0] * 3 for _ in range(3)]

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                bingo[i][j] = 1

ok = False

for i in range(3):
    count = 0
    for j in range(3):
        count += bingo[i][j]
    if count == 3:
        ok = True
for i in range(3):
    count = 0
    for j in range(3):
        count += bingo[j][i]
    if count == 3:
        ok = True
count = 0
for i in range(3):
    count += bingo[i][i]
    if count == 3:
        ok = True
count = 0
for i in range(3):
    count += bingo[2-i][i]
    if count == 3:
        ok = True

print("Yes" if ok else "No")


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string = "";
		
		while((string = reader.readLine()) != null){
		char str[] = string.toCharArray();
		int[] n = new int[10];
		for(int i = 0; i < 10; i++) n[i] = str[i] - '0';
		
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10 - 1 - i; j++){
			   string = String.valueOf(n[j] + n[j + 1]);
				n[j] = Integer.parseInt(
						String.valueOf(
						string.charAt(
						string.length() - 1)));
			}
		}
		System.out.println(n[0]);
		}
		reader.close();
	}
}

Measured memory_bytes: 24104
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K = I()

    rem = 7 % K
    ans = 0
    is_ok = True
    seen = [False] * K
    while rem != 0:
        if seen[rem]:
            is_ok = False
            break
        seen[rem] = True
        rem = rem * 10 + 7
        rem %= K
        ans += 1

    if is_ok:
        print(ans + 1)
    else:
        print(-1)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 17540
#include <iostream>
using namespace std;
int N;
int main(){
  cin >> N;
  if(N==1) cout << 1 << endl;
  else if(N<=3) cout << 2 << endl;
  else if(N<=7) cout << 4 << endl;
  else if(N<=15) cout << 8 << endl;
  else if(N<=31) cout << 16 << endl;
  else if(N<=63) cout << 32 << endl;
  else cout << 64 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    string s;
    cin >> s;
    string x[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
    for(int i = 0 ; i < 7; ++i){
        if(s == x[i]){
            cout << 7 - i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>
using namespace std;

#define sf scanf

int main() {
	int n, k; sf("%d %d", &n, &k);
	int x[55];
	for(int i=0; i<n; i++) 
		sf("%d", &x[i]);
	sort(x, x+n);
	int sum = 0;
	for(int i=n-1; i>=n-k; i--) {
		sum += x[i];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n, k;
int a[N];
ll pos[N];
ll sum[N];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
		pos[i + 1] = pos[i];
		if (a[i] > 0)
			pos[i + 1] += a[i];
	}
	ll res = 0;
	for (int i = 0; i <= n - k; i++) {
		res = max(res, max(0LL, sum[i + k] - sum[i]) + pos[i] - pos[0] + pos[n] - pos[i + k]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2176
n = int(input())
F = [0]
for i in range(1, n+1):
    A = [F[i-1]+1]
    j = 1
    while i-6**j >= 0:
        A.append(F[i-6**j]+1)
        j += 1
    j = 1
    while i-9**j >= 0:
        A.append(F[i-9**j]+1)
        j += 1
    F.append(min(A))
print(F[n])


Measured memory_bytes: 3860
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

#define ll long long int
#define INF 1e18

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, P> PP;

typedef struct edge_ {
		int from, to;
		int cost;
		edge_(int a, int b, int c) : from(a), to(b), cost(c){};
} edge;

ll d[100001];
int y[100001];

int main(int argc, char const* argv[])
{
	int n, m, x;
	cin >> n >> m >> x;
	int *h = new int[n];
	vector<edge> *vec = new vector<edge>[n];
	for(int i = 0; i < n; i++)cin >> h[i];
	for(int i = 0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			vec[a - 1].push_back(edge(a - 1, b - 1, c));
			vec[b - 1].push_back(edge(b - 1, a - 1, c));
	}
	for(int i = 0; i < n; i++)d[i] = INF;
	priority_queue<PP, vector<PP>, greater<PP> > q;
	q.push(make_pair(0, make_pair(0, x)));
	d[0] = 0;
	while(!q.empty()){
			PP p = q.top(); q.pop();
			ll cost = p.first;
			int v = p.second.first;
			int height = p.second.second;
			if(cost > d[v])continue;

			for(int i = 0; i < vec[v].size(); i++){
					if(h[v] < vec[v][i].cost)continue;
					if(height > vec[v][i].cost && height - vec[v][i].cost < h[vec[v][i].to]){
							ll dis = cost + vec[v][i].cost;
							if(d[vec[v][i].to] > dis){
									q.push(make_pair(dis, make_pair(vec[v][i].to, height - vec[v][i].cost)));
									d[vec[v][i].to] = dis;
									y[vec[v][i].to] = height - vec[v][i].cost;
							}
					}else if(height > vec[v][i].cost){
							ll dis = cost + vec[v][i].cost + (height - vec[v][i].cost - h[vec[v][i].to]);
							if(d[vec[v][i].to] > dis){
									q.push(make_pair(dis, make_pair(vec[v][i].to, h[vec[v][i].to])));
									d[vec[v][i].to] = dis;
									y[vec[v][i].to] = h[vec[v][i].to];
							}
					}else{
							ll dis = cost + vec[v][i].cost + (vec[v][i].cost - height);
							if(d[vec[v][i].to] > dis){
									q.push(make_pair(dis, make_pair(vec[v][i].to, 0)));
									d[vec[v][i].to] = dis;
									y[vec[v][i].to] = 0;
							}
					}
			}
	}
	if(d[n - 1] != INF){
			cout << d[n - 1] + h[n - 1] - y[n - 1] << endl;
	}else{
			cout << -1 << endl;
	}
	return 0;
}



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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

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

    int n; cin >> n;

    auto f = [&](int u){
        int v = u + n;
        return v;
    };

    if ((n & (n - 1)) == 0){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    cout << 1 << " " << 2 << endl;
    cout << 1 << " " << 3 << endl;
    cout << 3 << " " << f(2) << endl;
    cout << f(3) << " " << 2 << endl;
    cout << f(1) << " " << f(3) << endl;

    for (int i = 4; i + 1 <= n; i += 2){
        cout << 1 << " " << i << endl;
        cout << 1 << " " << i + 1 << endl;
        cout << i << " " << f(i + 1) << endl;
        cout << i + 1 << " " << f(i) << endl;
    }

    if (n % 2 == 0){
        int a = 1 << __lg(n);
        int b = n - a + 1;

        cout << n << " " << a << endl;
        cout << f(n) << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 2304
ROADS = 3

range_city = list(range(1, 4+1))
appearance = []
for i in range(ROADS):
    a, b = map(int, input().split())
    appearance.append(a)
    appearance.append(b)

count = [appearance.count(city) for city in range_city]
if ROADS not in count:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

using dat = tuple<ll, int, int>;
int main() {
    init();

    int n; cin >> n;
    vector<dat> a;
    FOR(i, 0, n)FOR(j, 0, n) {
        ll in; cin >> in;
        if (j <= i)continue;
        a.emplace_back(in, i, j);
    }

    SORT(a);
    auto dis = defvec<ll>(LLINF, n, n);
    FOR(i, 0, n)dis[i][i] = 0;

    ll ans = 0;
    each(i, a) {
        ll cost; int x, y;
        tie(cost, x, y) = i;
        if (dis[x][y] < cost) {
            ans = -1;
            break;
        }
        if (chmin(dis[x][y], cost) && chmin(dis[y][x], cost)) {
            ans += cost;
        }
        FOR(j, 0, n) {
            chmin(dis[x][j], dis[x][y] + dis[y][j]);
            chmin(dis[j][x], dis[j][y] + dis[y][x]);
            chmin(dis[y][j], dis[y][x] + dis[x][j]);
            chmin(dis[j][y], dis[j][x] + dis[x][y]);
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 1652
#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char const *argv[])
{
    short a,b;

    cin >> a >> b;

    if (a < b)
    {
        puts("a < b");
    }
    else if (a > b)
    {
        puts("a > b");
    }
    else
    {
        puts("a == b");
    }
    return 0;
}



Measured memory_bytes: 3024
#include <stdio.h>


int main(void){
  int n,k,count=0;
  scanf("%d",&n );
  scanf("%d",&k );

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

  for (int i = 0; i < n; i++) {
    if (h[i]>=k) {
      count++;
    }
  }

  printf("%d\n",count );

  return 0;
}


Measured memory_bytes: 512
n=int(input())
arr=[]
for i in range(n):
	arr.append(list(map(int,input().split())))
flag=0
for i in range(n-2):
	if(arr[i][0]==arr[i][1] and arr[i+1][0]==arr[i+1][1] and arr[i+2][0]==arr[i+2][1]):
		flag=1
		print("Yes")
		break
if(flag==0):
	print("No")

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

int main() {
   int N;
  cin>>N;
  int L_max=0;
  int total=0;
  for(int i=0;i<N;i++){
    int L;
    cin>>L;
    
    L_max=max(L,L_max);
    total+=L;}
  if(L_max<total-L_max)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	vector<pair<int, int>>ab(n);
	rep(i, n) {
		cin >> ab[i].first >> ab[i].second;
	}
	sort(all(ab), ps3);
	ll time = 0;
	bool ans = true;
	rep(i, n) {
		time += ab[i].F;
		if (ab[i].S < time) {
			ans = false;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 1920
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a;
		int box = 0;
		
		for(int i = 1;i<6;i++) {
			a = scan.nextInt();
			if(a==0) {
				box = i;
			}
		}
		System.out.print(box);
	}

}

Measured memory_bytes: 35764
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001], check[100001];
std::vector<long long int>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;

bool relation[1000][1000];
int twod[1001][1001];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char rev[100001];


int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int N, M;//はんい
int bfs() {
	queue<pair<int, int>> que;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			twod[i][j] = INF;
		}
	}
	que.push(pair<int, int>(sx, sy));
	twod[sx][sy] = 1;
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
		if (p.first == gy && p.second == gx) {
			break;
		}
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (1 <= nx && nx <= N && 1 <= ny && ny <= M && maze[nx][ny] != '#'&&twod[nx][ny] == INF) {
				que.push(pair<int, int>(nx, ny));
				twod[nx][ny] = twod[p.first][p.second] + 1;
			}
		}
	}
	return twod[gy][gx];
}
vector <int> g[100100];
int main()
{
	cin >> a >> b;
	if (a == b) {
		cout << a + b << endl;
	}
	else {
		cout << std::max(a, b) * 2 - 1 << endl;
	}
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>

using namespace std;

#define N 50

int main() {
	long long int K; 
	long long int a[N];

	cin >> K;

	for (int i = 0; i < N; i++) a[i] = i;

	long long int div = K / N;
	long long int rem = K % N;

	for (int i = 0; i < N; i++) a[i] += div;

	if (rem != 0){
		for (int i = 1; i <= rem; i++) {
			for (int j = 0; j < N; j++) {
				if (j == i - 1) a[j] += N;
				else a[j]--;
			}
		}
	}

	cout << N << endl;
	for (int i = 0; i < N; i++) {
		if (i == N - 1) cout << a[i] << endl;
		else cout << a[i] << ' ';
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge{
  ll to,id;
};
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

ll f(vi v) {
  sort(ALL(v));
  ll ret=0;
  for(ll i=0;i<v.size();i++) ret=max(ret,((ll)v.size()-i)+v[i]);
  return ret;
}

int main() {
  ll N; cin>>N;
  Graph G(N);

  REP(i,N-1) {
    ll a; cin>>a; a-=1;
    G[a].PB(i+1);
  }

  vi depth(N); depth[0]=0;
  queue<ll> q; q.push(0);

  while(q.size()) {
    ll from=q.front(); q.pop();
    for(ll to:G[from]) {
      depth[to]=depth[from]+1;
      q.push(to);
    }
  }

  vi order(N); REP(i,N) order[i]=i;
  sort(ALL(order),[&depth](ll i,ll j){return depth[i]>depth[j];});



  vi v(N,0);

  for(ll i:order) {
    vi a;
    for(ll to:G[i]) a.PB(v[to]);
    v[i]=max(v[i],f(a));
  }


  cout<<v[0]<<endl;
}


Measured memory_bytes: 8564
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::BinaryHeap;

fn main() {
  let n = read::<i32>();
  let mut bh = BinaryHeap::new();
  let mut a = vec![];

  for i in 0..n {
    let a_i = read::<i32>();
    a.push(a_i);
    bh.push(a_i);
  }

  let max = bh.pop().unwrap();
  let max_second = bh.pop().unwrap();

  for i in a {
    if i == max {
      println!("{}", max_second);
    } else {
      println!("{}", max);
    }
  }
}



Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

vvi to;
vi ans;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    int q;
    cin >> n >> q;
    to.resize(n);
    ans.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i, n) printf("%d%c", ans[i], i==n-1?'\n':' ');
}

Measured memory_bytes: 23552
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define For(i,x,y) for(int i = x; i <= y; ++i)
#define FOR For
#define rev_For(i,x,y) for(int i = x; i >= y; --i)
#define REV_FOR rev_For
#define ll long long
#define Size(v) ((int)v.size())
#define _section "\n--------------------\n"
#define fi first
#define se second
#define pb push_back
using namespace std;
// using namespace __gnu_pbds;


int n;

void input() {
	cin >> n;
}

void solve() {

	// corner case: n = 2
	if (n == 2) {
		cout << 1;
		return;
	}

	int m = n - 1;
	int cnt = 2; // n, n - 1
	for (int i = 2; i * i <= m; ++i) {
		if (m % i == 0 && m / i != i) cnt += 2;
		else if (m % i == 0) cnt++;
	}

	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			if (i * i == n) {
				++cnt;
				continue;
			}
			else {
				if ((n / i) % (n / i) == 1) {
					++cnt;
				}
			}

			int cpy = n;
			while (cpy % i == 0) {
				cpy /= i;
			}
			if (cpy == 1 || cpy % i == 1) {
				++cnt;
			}
		}
	}

	cout << cnt;
}

signed main() {
#ifdef _DEBUG
	// freopen("INPUT.inp", "r", stdin);
	//freopen("OUTPUT.out", "w", stdout);
	clock_t start, end;
	start = clock();
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------------------------------------------
//----------------------------------MAIN PROGRAM--------------------------------------
	int t = 1;
	while (t--) {
		input();
		solve();
	}
//--------------------------------------END-------------------------------------------
//------------------------------------------------------------------------------------
#ifdef _DEBUG
	end = clock();
	cerr << "\n----------\nTime Elapsed: " << fixed << double(end - start) / double(CLOCKS_PER_SEC) << setprecision(6) << '\n';
#endif
	return 0;
}

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

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

    int maxL = 1, minR = n;
    for (int i = 0; i < m; i++) {
        int L, R;
        cin >> L >> R;

        maxL = max(maxL, L);
        minR = min(minR, R);
    }

    cout << (minR < maxL ? 0 : (minR - maxL) + 1) << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n,a,b;cin >>n>>a>>b;
    ll ans=0;
    if(a%2==b%2){
        ans=(b-a)/2;
    }
    else {
        ans+=min(n-b+1,a);
        ans+=(b-a)/2;
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin>> n;
    vi a(n);
    map<int, int> stu;
    rep(i,n) {
        int a;
        cin >> a;
        stu[a]  = i+1; 
    }
    for(int i = 1; i <= n; i++) {
        cout << stu[i] << ' ';
    }
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	typedef pair<int, int> P;
	vector<P> BC( M );
	for( int i = 0; i < M; i++ ) {
		cin >> BC[i].second >> BC[i].first;
	}

	sort( A.begin(), A.end() );
	sort( BC.begin(), BC.end(), greater<P>() );
	vector<int> D;
	for( int i = 0; i < M; i++ ) {
		int C = BC[i].first;
		int B = BC[i].second;
		for( int j = 0; j < B; j++ ) {
			if( A[D.size()] > C ) break;
			D.push_back( C );
			if( D.size() >= N ) break;
		}
		if( D.size() >= N ) break;
	}
	long long ans = 0;
	for( int i = 0; i < D.size(); i++ ) {
		ans += D[i];
	}
	for( int i = D.size(); i < N; i++ ) {
		ans += A[i];
	}

	cout << ans << endl;
}


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

int h, w;
char c[100][100];

bool isOK(int y, int x){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int search(int y, int x){
    int ans = 0;
    for(int i = -1;i <= 1;i++){
        for(int j = -1;j <= 1;j++){
            if(!(i == 0 && j == 0)){
                if(isOK(y+i, x+j) && c[y+i][x+j] == '#'){
                    ans++;
                }
            }
        }
    }
    return ans;
}

int main(){
    cin >> h >> w;
    for(int i = 0;i < h;i++)
        cin >> c[i];

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(c[i][j] == '#'){
                cout << '#';
            }else{
                cout << search(i, j);
            }
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(void){
    string A;
    cin>>A;
    
    ll c[26]={0};
    ll N=A.size();
    ll ans=N*(N-1)/2+1;
    
    ll i;
    for(i=0;i<N;i++){
        c[A[i]-'a']++;
    }
    
    for(i=0;i<26;i++){
        ans-=c[i]*(c[i]-1)/2;
    }
    
    cout<<ans<<endl;
 
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define FOR(i, n) for (int i = 1; i < (int)(n + 1); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int gcd_n(vector<int> &numbers) {
  int GCD;
  GCD = numbers[0];
  for (int i = 1; i < numbers.size(); i++) {
    GCD = gcd(GCD, numbers[i]);
  }
  return GCD;
}

int main() {
  int K;
  cin >> K;
  vector<int> num(3);
  ll sum = 0;
  FOR(a, K) {
    FOR(b, K) {
      FOR(c, K) {
        num[0] = a;
        num[1] = b;
        num[2] = c;
        sum += gcd_n(num);
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
using namespace std;
int pd[110][110];
int main(){
    int h,w,n,x=0;
    cin>>h>>w>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            if((x/w)%2==0) pd[x/w][x%w]=i+1;
            else pd[x/w][w-(x%w)-1]=i+1;
            x++;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(j==w-1) printf("%d\n",pd[i][j]);
            else printf("%d ",pd[i][j]);
        }
    }
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k;
	cin >> k;
	vector<bool> data(k+1);

	data[1] = 1;

	rep(i, 2, k ) {
		
		int b = i * i;
		while(b<=k){
			data[b] = 1;

			b *= i;

		}
	}

	rrep(i, k, 0) {
		if(data[i]) {
			cout << i << endl;
			return 0;
			
		}
	}
	
	
		
	
	
	
	
}
	

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())

Mod=10**9+7
M=2*10**5 +1#書き換え

fac=[0]*M
finv=[0]*M
inv=[0]*M

#finvに逆元、facに階乗のmod
def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
def COM(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return (fac[n]*(finv[k]*finv[n-k]%Mod)%Mod)%Mod

COMinit()
if n>k:
    ans=1
    for i in range(1,k+1):
        ans+=(COM(n,i)*COM(n-1,i))%Mod
        ans%=Mod
else:
    ans=1
    for i in range(1,n):
        ans+=(COM(n,i)*COM(n-1,i))%Mod
        ans%=Mod
print(ans)

Measured memory_bytes: 79084
#[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()));
            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, 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")
        };
    }

    #[allow(unused_imports)]
    use std::cmp::{max, min};
    #[allow(unused_imports)]
    use std::collections::{BinaryHeap, HashMap};

    #[allow(dead_code)]
    type Graph = Vec<Vec<usize>>;

    fn main() {
        input! {
            a: i64,
            b: i64,
        }

        println!("{}", b * 2 - a);
    }


Measured memory_bytes: 4352
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h:u128 = read();
    let w:u128 = read();
    if w == 1 || h == 1 {
        println!("1");
        return;
    }
    println!("{}", w * (h / 2) + (w/2 + w % 2) * (h % 2));
}


Measured memory_bytes: 2112
#include <iostream>
#include <cmath>
#define maxint 2147483647;
typedef long long ll;
void dump(int a[],int n)
{
  for (int codeTest = 0; codeTest < n; ++codeTest) {
    if (codeTest!=0)std::cout << " ";
    std::cout << a[codeTest];
  }
  std::cout << '\n';
}

int main() {
  int n,tmp;
  int a[10001];
  for (int i = 0; i <= 10000; ++i){a[i]=0;}
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> tmp;
    ++a[tmp];
  }
  bool b=false;
  for (int c1 = 0; c1 <= 10000; ++c1) {
    for (int c2=0; c2<a[c1];++c2){
      if (b)std::cout << " ";
      std::cout <<c1;
      b=true;
    }
  }
  std::cout << '\n';
  return 0;
}



Measured memory_bytes: 3152
#include<iostream>

using namespace std;

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

	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	int curr = 0; int mx = 0; int i=0;
	while(i<n-1){
		if(a[i]>=a[i+1]){
			curr++;
			mx = max(mx,curr);
		}
		else{
			curr=0;
		}
		i++;
	}
	cout << mx;
	
	return 0;
}

Measured memory_bytes: 3992
N = int(input())
X = list(map(int,input().split()))
a = sorted(X)[N//2-1]
b = sorted(X)[N//2]

if a == b:
  for _ in range(N):
    print(a)
else:
  for i in range(N):
    if X[i] <= a:
      print(b)
    else:
      print(a)

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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, vector<ll> A, vector<ll> B, vector<ll> C) {
  int ans{};

  for (auto i = 0; i != N; i++) {
    ans += B[A[i] - 1];
    if (i && A[i] - A[i - 1] == 1) {
      ans += C[A[i - 1] - 1];
    }
  }
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  vector<ll> C(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i];
  }
  solve(N, move(A), move(B), move(C));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int INF=(1e9)+10;
int N,M,n,m,dx[3010],dy[3010];
int a[1010],b[1010],c[1010],d[1010],e[1010],f[1010];
ll ans;
bool vis[3010][3010],heng[3010][3010],shu[3010][3010];
int Fx(int x) {
	return lower_bound(dx+1,dx+n+1,x)-dx;
}
int Fy(int y) {
	return lower_bound(dy+1,dy+m+1,y)-dy;
}
struct node { int x,y; };
queue<node> q;
void insert(int x,int y) {
	if (vis[x][y]) return;
	if (x==1||x==n||y==1||y==m) { printf("INF\n"); exit(0); }
	q.push((node){x,y});
	vis[x][y]=1;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(N); read(M);
	dx[++n]=0,dy[++m]=0;
	dx[++n]=-INF,dx[++n]=INF;
	dy[++m]=-INF,dy[++m]=INF;
	for (int i=1;i<=N;i++) {
		read(a[i]); read(b[i]); read(c[i]);
		dx[++n]=a[i],dx[++n]=b[i],dy[++m]=c[i];
	}
	for (int i=1;i<=M;i++) {
		read(d[i]); read(e[i]); read(f[i]);
		dx[++n]=d[i],dy[++m]=e[i],dy[++m]=f[i];
	}
	sort(dx+1,dx+n+1);
	sort(dy+1,dy+m+1);
	n=unique(dx+1,dx+n+1)-dx-1;
	m=unique(dy+1,dy+m+1)-dy-1;
//	printf("%d %d\n",n,m);
	for (int i=1;i<=N;i++) {
		a[i]=Fx(a[i]),b[i]=Fx(b[i]),c[i]=Fy(c[i]);
		for (int j=a[i];j<b[i];j++) heng[j][c[i]]=1;
	}
	for (int i=1;i<=M;i++) {
		d[i]=Fx(d[i]),e[i]=Fy(e[i]),f[i]=Fy(f[i]);
		for (int j=e[i]+1;j<=f[i];j++) shu[d[i]][j]=1;
	}
	int x=Fx(0),y=Fy(0);
	insert(x,y);
	while (!q.empty()) {
		x=q.front().x,y=q.front().y; q.pop();
		ans+=(ll)(dx[x+1]-dx[x])*(dy[y]-dy[y-1]);
		if (!heng[x][y]) insert(x,y+1);
		if (!heng[x][y-1]) insert(x,y-1);
		if (!shu[x][y]) insert(x-1,y);
		if (!shu[x+1][y]) insert(x+1,y);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 26808
#include<iostream>
using namespace std;
string s[1001];
int h,w,i;
int main()
{
	cin>>h>>w;
	for (i=1;i<=h;i++)
	  cin>>s[i];
	for (i=1;i<=h;i++)
	  cout<<s[i]<<endl<<s[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
U[102][102],R[102][102],M=1e5;main(w,h,x,y,r){for(;scanf("%d%d",&w,&h)*w;printf("%d\n",(U[w][h+1]+R[w+1][h]+r)%M))for(R[2][1]=U[1][2]=x=1;y=x++<=w;)for(;y++<=h;r+=R[x][y]=(R[x-1][y]+U[x-2][y])%M)r=U[x][y]=(U[x][y-1]+R[x][y-2])%M;}

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

using namespace std;

int n,k,l,i,j,road[200005],rail[200005],ans[200005],cnt[200005];

vector <int> gp[200005];

int find(int s, int* p){
	if(p[s] == s) return s;
	return p[s] = find(p[s], p);
}

int main(){
	scanf("%d%d%d", &n, &k, &l);
	
	for(i = 1; i <= n; i++){
		road[i] = i;
		rail[i] = i;
	}
	
	for(i = 0; i < k; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		
		int u = find(x, road);
		int v = find(y, road);
		
		road[u] = v;
	}	
	
	for(i = 0; i < l; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		
		int u = find(x, rail);
		int v = find(y, rail);
		
		rail[u] = v;
	}
	
	for(i = 1; i <= n; i++){
		int u = find(i, road);
		gp[u].push_back(i);
	}
	
	for(i = 1; i <= n; i++){
		for(j = 0; j < gp[i].size(); j++)
		cnt[find(gp[i][j], rail)]++;
		for(j = 0; j < gp[i].size(); j++){
			ans[gp[i][j]] = cnt[find(gp[i][j], rail)];
		}
		for(j = 0; j < gp[i].size(); j++)
		cnt[find(gp[i][j], rail)]--;
	}
	
	for(i = 1; i <= n; i++){
		if(i == 1)
		printf("%d", ans[i]);
		else
		printf(" %d", ans[i]);
	}
	
	printf("\n");
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define mod 1000000007
#define MOD 998244353
#define db(a) cout << a << endl
#define adb(a) for(auto i:a) cout << i << " "
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

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

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

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(i=2;i<n;i++) dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));

    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main() {
    string str;
    cin >> str;


    string ans = str;
    int j = 0;
    for(int i = 0; i < str.size(); i++) {
        if(str[i] == '0') {
            ans[j] = '0';
            j++;
        }else if(str[i] == '1') {
            ans[j] = '1';
            j++;
        }else {
            if(j == 0){
                continue;
            }
            j--;
        }
    }

    for(int i = 0; i < j; i++){
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
struct mat{
	ll a[3][3];
}p[33],q,o;
ll s[3],t[3];
int x[100009];
const ll P=1e9+7;
mat mul(mat a,mat b){
	mat c=o;
	int i,j,k;
	for(i=0;i<3;++i)for(j=0;j<3;++j)for(k=0;k<3;++k)c.a[i][k]+=a.a[i][j]*b.a[j][k];
	for(i=0;i<3;++i)for(j=0;j<3;++j)c.a[i][j]%=P;
	return c;
}
void mul(mat a){
	int i,j;
	for(i=0;i<3;++i)for(t[i]=j=0;j<3;++j)t[i]+=s[j]*a.a[i][j];
	for(i=0;i<3;++i)s[i]=t[i]%P;
}
void calc(int x){
	for(int i=0;(1<<i)<=x;++i)if(x&(1<<i))mul(p[i]);
}
int main(){
	int n,m,i;
	scanf("%d%d",&n,&m),s[0]=1;
	for(i=1;i<=m;++i)scanf("%d",x+i);
	q.a[1][0]=2,q.a[0][0]=q.a[1][1]=q.a[2][0]=q.a[2][1]=q.a[2][2]=1,p[0]=q,p[0].a[0][0]=2,p[0].a[0][1]=p[0].a[0][2]=1;
	for(i=1;(1<<i)<=n;++i)p[i]=mul(p[i-1],p[i-1]);
	for(i=1;i<=m;++i)calc(x[i]-x[i-1]-1),mul(q);
	calc(n-x[m]),printf("%llu",s[2]);
	return 0;
}

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

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main () {
	int n, x;
	cin >> n >> x;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int c = abs(a[0] - x);
	for (int i = 1; i < n; i++) {
		c = gcd(c, abs(a[i] - x));
	}

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

Measured memory_bytes: 1152
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int M[2][MAXN][19], a[MAXN], pos[MAXN], n;
vector<int> v[2];
priority_queue<pair<int, pii> > st;

int getMin(int t, int u, int v) {
	int k = log2(v - u + 1);
	return min(M[t][u][k], M[t][v-(1<<k)+1][k]);
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		pos[a[i]] = i;
	}
	
	for (int i=0; i<n; i++) {
		v[i % 2].pb(a[i]);
	}
	
	for (int i=0; i<2; i++) {
		for (int j=0; j<sz(v[i]); j++) {
			M[i][j][0] = v[i][j];
		}
		for (int k=1; (1<<k)<=sz(v[i]); k++) {
			for (int j=0; j+(1<<k)-1<sz(v[i]); j++) {
				M[i][j][k] = min(M[i][j][k - 1], M[i][j+(1<<(k-1))][k - 1]);
			}
		}
	}
	
	st.push(mp(-getMin(0, 0, (n-1)/2), mp(0, n - 1)));
	
	while (!st.empty()) {
		pair<int, pii> cur = st.top();
		st.pop();
		cur.FI = -cur.FI;
		
		int L = cur.SE.FI, R = cur.SE.SE;
		
		int now = pos[cur.FI];
		
		int gg = getMin((now % 2) ^ 1, (now + 1) / 2, R / 2);
		
		int nxt = pos[gg];
		
		printf("%d %d ", cur.FI, gg);
		
		if (now + 1 < nxt - 1) {
			gg = getMin((now + 1) % 2, (now + 1) / 2, (nxt - 2) / 2);
			st.push(mp(-gg, mp(now + 1, nxt - 1)));
		}
		if (L < now - 1) {
			gg = getMin(L % 2, L / 2, (now - 2) / 2);
			st.push(mp(-gg, mp(L, now - 1)));
		}
		if (nxt + 1 < R) {
			gg = getMin((nxt + 1) % 2, (nxt + 1) / 2, (R - 1) / 2);
			st.push(mp(-gg, mp(nxt + 1, R)));
		}
	}

	return 0;
}


Measured memory_bytes: 21616
package main

import (
        "fmt"
        "sort"
)

func solution(n, k int, a []int) int {
        seen := make(map[int]int, 0)

        for i := range a {
                seen[a[i]]++
        }

        l := len(seen)
        if l <= k {
                return 0
        }

        tmp := make([]int, 0, l)
        for _, v := range seen {
                tmp = append(tmp, v)
        }
        sort.Ints(tmp)
        out := 0
        for i := 0; i < l-k; i++ {
                out += tmp[i]
        }
        return out
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        a := make([]int, n)
        for i := range a {
                fmt.Scan(&a[i])
        }
        fmt.Println(solution(n, k, a))
}

Measured memory_bytes: 16012