akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;


struct SCC{
	vector<vector<int> > G;
	vector<vector<int> > rG;
	vector<int> vs;
	vector<bool> used;
	vector<int> cmp;
	int sz,newsz;
	SCC(int n):G(n),rG(n),used(n,false),cmp(n){sz = n;}
	
	//辺を張る
	void add_edge(int from,int to){
		G[from].PB(to);
		rG[to].PB(from);
	}
	
	void dfs(int v){
		used[v] = true;
		REP(i,G[v].size()){
			if(!used[G[v][i]])dfs(G[v][i]);
		}
		vs.PB(v);
	}
	
	void rdfs(int v,int k){
		used[v] = false;
		cmp[v] = k;
		REP(i,rG[v].size()){
			if(used[rG[v][i]])rdfs(rG[v][i],k);
		}
	}
	
	//ＳＣＣ実行
	int reMake(){
		vs.clear();
		REP(i,sz)if(!used[i])dfs(i);
		int k = 0;
		for(int i = sz-1;i >= 0;i--){
			if(used[vs[i]]){
				rdfs(vs[i],k++);
			}
		}
		return newsz = k;
	}
	
	int scc_node(int n){
		return cmp[n];
	}
};


int main(){
	int n,m;cin >> n >> m;
	
	SCC scc(n);
	
	REP(i,m){
		int a,b;cin >> a >> b;
		scc.add_edge(a,b);
	}
	
	scc.reMake();
	
	int q;cin >> q;
	
	REP(i,q){
		int a,b;cin >> a >> b;
		if(scc.scc_node(a) == scc.scc_node(b)){
			cout << 1 << endl;
		}
		else{
			cout << 0 << endl;
		}
	}
			
	return 0;
}


Measured memory_bytes: 4428
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<char>> as(n, vector<char>(n)), bs(m, vector<char>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> as[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin >> bs[i][j];
        }
    }
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            bool ok = true;
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(as[i + k][j + l] != bs[k][l]){
                        ok = false;
                        break;
                    }
                }
            }
            if(ok){
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = array[0];
        var Y = array[1];
        
        for(var x = 0;x <= N;x++){
            for(var y = 0;y <= N;y++){
                var z = N - x - y;
                if(z >= 0){
                    if(10000 * x + 5000 * y + 1000 * z == Y){
                        Console.WriteLine($"{x} {y} {z}");
                        return;
                    }
                }
            }
        }
        Console.WriteLine("-1 -1 -1");
        
    }
}


Measured memory_bytes: 11348
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        S.append(s)
    # print(S)

    if N == 1:
        ans = sorted(S[0])
        print("".join(ans))
    else:
        a = []
        st = set(S[0])
        cnt = 10 ** 9
        for c in list(st):
            for s in S:
                cnt = min(cnt, s.count(c))
                # print(c, s, cnt)
            # if cnt > 0:
            for i in range(cnt):
                a.append(c)
            cnt = 10 ** 9
        ans = sorted(a)
        print("".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
//Topological Sort
#include <iostream>
#include <vector>
#include <queue>
#include <list>

using namespace std;

vector<int> topologicalSort(int n, vector<vector<int>> &G) {
    vector<int> indeg(n, 0);
    for(int s=0; s<n; s++)
        for(int t: G[s])
            indeg[t]++;

    queue<int> q;
    for(int i=0; i<n; i++)
        if(indeg[i] == 0) q.push(i);

    vector<int> ans;
    while(!q.empty()) {
        int s = q.front(); q.pop();
        ans.push_back(s);
        for(int t: G[s]) {
            if(--indeg[t] == 0) q.push(t);
        }
    }

    return ans;
}

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

    vector<vector<int>> G(n);
    for(int i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
    }

    vector<int> ans = topologicalSort(n, G);

    for(auto a : ans) cout << a << endl;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//展望台の数
		int m = sc.nextInt();//道の数
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();//それぞれの展望台の高さ。
		}
		int[] b = new int[n];//標高が低かった回数を格納→0のものがいい展望台。
		for (int i = 0; i < m; i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			if (a[x] < a[y]) {
				b[x]++;//低かった方でカウントする
			} else if (a[x] > a[y]) {
				b[y]++;
			} else {
				b[x]++;
				b[y]++;
			}

		}
		int cnt = 0;
		for (int i = 0; i < b.length; i++) {
			if (b[i] == 0) {
				cnt++;
			}
		}

		System.out.println(cnt);
	}

}

Measured memory_bytes: 59668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  vector<ll> c(n);
  ll k=0;
  for(ll i=0;i<n;i++){
    if(a[i]==a[i+1]){
      c[k++]=a[i];
      i++;
    }
  }
  cout << c[k-2]*c[k-1] << endl;
}


Measured memory_bytes: 4688
n, m = gets.split.map(&:to_i)
conditions = []
m.times do
  conditions << gets.split.map(&:to_i)
end

number = 'X' * n
answer = 0

conditions.each do |c|
  if number[c[0] - 1] != 'X' && number[c[0] - 1] != c[1].to_s
    answer = -1
    break
  end
  number[c[0] - 1] = c[1].to_s
end

answer = -1 if number[0] == '0' && n != 1

unless answer == -1
  number = 
    number.chars.map.with_index(0) do |c, i|
      next c if c != 'X'

      (i == 0 && n != 1) ? 1 : 0
    end
end

puts answer == -1 ? answer : number.join


Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif

int main(){

  double a,b,c;

  scanf("%lf %lf %lf",&a,&b,&c);

  printf("%.9lf\n",a*b*sin(c*M_PI/180)/2);
  printf("%.9lf\n",sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c*M_PI/180))+a+b);
  printf("%.9lf\n",sin(c*M_PI/180)*b);

}


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

#define N 1000000
#define INF 1000000000

typedef struct card{
    char simbol;
    int nmber;
}Card;

int nm;
Card A[N];
Card B[N];
Card L[N / 2 + 2];
Card R[N / 2 + 2];

/*void Babblesort(){
  int j, flag=1;
  Card temp;
  
  while(flag == 1){
    flag = 0;
    for(j = nm-1; j > 0; j--){
      if(A[j].nmber < A[j-1].nmber){
        temp = A[j];
        A[j]= A[j-1];
        A[j-1]= temp;

        flag = 1;
      }
    }
  }
  return ;
}*/

void merge(Card *A,int n, int l, int m, int r){
    int i, j, k;
    int n1 = m - l;
    int n2 = r - m;

    for(i = 0; i < n1; i++)L[i] = A[l + i];
    for(i = 0; i < n2; i++)R[i] = A[m + i];

    L[n1].nmber = R[n2].nmber = INF;
    i = j = 0;
    for(k = l; k < r; k++){
        if(L[i].nmber <= R[j].nmber){
            A[k] = L[i++];
        }
        else {
            A[k] = R[j++];
        }
    }
}

void merges(Card *A, int n, int l, int r){
    int m;
    int i;
    if(l + 1 < r){
        m = (l+r) / 2;
        merges(A, n, l, m);
        merges(A, n, m, r);
        merge(A, n, l, m, r);
    }
}

int partition(int p, int r){
    int i, j, x;
    Card temp;
  x = B[r].nmber;
  i = p - 1;
  for(j = p; j <= r-1; j++){ 
    if(B[j].nmber <= x){
      i++;
        temp = B[i];
        B[i] = B[j];
        B[j] = temp;
    }
  }
    temp = B[i+1];
    B[i+1] = B[r];
    B[r] = temp;
    
  
  return i+1;
}

void quickSort(int p, int r){
    int q;
    if(p < r){
        q = partition(p, r);
        quickSort(p, q-1);
        quickSort(q+1, r);
    }
    return;
}

int compare(Card *A, Card *B){
    int i;
    for(i = 0; i < nm; i++){
        if(A[i].simbol != B[i].simbol || A[i].nmber != B[i].nmber) return 0;
    }
    return 1;
}

int main(){
    int i, j, n;

    scanf("%d", &nm);

    for(i = 0; i < nm; i++){
        scanf("%s %d", &A[i].simbol, &A[i].nmber);
        B[i].nmber = A[i].nmber;
        B[i].simbol = A[i].simbol;
    }

    quickSort(0, nm-1);
    merges(A, nm, 0, nm);
    

    if(compare(A, B) == 1) printf("Stable\n");
    else printf("Not stable\n");

    for(i = 0; i < nm; i++){
        printf("%c ", B[i].simbol);
        printf("%d\n", B[i].nmber);
    }

    return  0;
}


Measured memory_bytes: 4212
using System;

namespace B
{
  class Program
  {
    public static int[] inStamp;
    public static int[] outStamp;
    public static int stamp = 0;
    static void Main(string[] args)
    {
      int node = int.Parse(Console.ReadLine());
      inStamp = new int[node];
      outStamp = new int[node];
      int[,] array = new int[node, node];
      for (int i = 0; i < node; i++)
      {
        String[] input = Console.ReadLine().Split(' ');
        for (int j = 1; j <= int.Parse(input[1]); j++)
        {
          array[int.Parse(input[0]) - 1, int.Parse(input[j + 1]) - 1] = 1;
        }
      }
      DFS(0, array);
      for (int i = 0; i < inStamp.Length; i++)
      {
        if (inStamp[i] == 0)
        {
          DFS(i, array);
        }
      }
      for (int i = 0; i < node; i++)
      {
        Console.WriteLine(i + 1 + " " + inStamp[i] + " " + outStamp[i]);
      }
    }
    public static void DFS(int p, int[,] Graph)
    {
      inStamp[p] = ++stamp;
      for (int i = 0; i < Graph.GetLength(0); i++)
      {
        if (Graph[p, i] == 1)
        {
          if (inStamp[i] == 0) DFS(i, Graph);
        }
      }
      outStamp[p] = ++stamp;
    }
  }
}



Measured memory_bytes: 18000
// atcoder/abc167/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n, m, x;
  while (cin >> n >> m >> x) {
    int c[n];
    vec<int> a[n];
    for (int i = 0; i < n; ++i) {
      a[i].resize(m);
      cin >> c[i] >> a[i];
    }

    const lli inf = 1LL << 60;
    lli mn = inf;

    for (int bit = 0; bit < (1 << n); ++bit) {
      lli y = 0;
      lli sum[m];
      fill(sum, sum + m, 0);
      for (int i = 0; i < n; ++i) {
        if (bit & (1 << i)) {
          y += c[i];
          for (int j = 0; j < m; ++j) {
            sum[j] += a[i][j];
          }
        }
      }
      bool f = true;
      for (int i = 0; i < m; ++i) {
        f = f && (x <= sum[i]);
      }
      if (f) setmin(mn, y);
    }

    cout << (mn == inf ? -1 : mn) << endl;
  }

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long ll;
#define MOD 1000000007

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF = 1LL << 60;



//大文字小文字気をつけろ

int main(){
  int h,w;
  bool a=0;
  cin >> h >> w;
  char s[100][100];
  FOR(i,h){
    FOR(j,w){
      cin >> s[i+1][j+1];
    }
  }
  FOR(i,h){
    s[i][0]='.';
    s[i][h+1]='.';
  }
  FOR(i,w){
    s[0][i]='.';
    s[w+1][i]='.';
  }

  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(s[i][j]=='#' && s[i+1][j]!='#' && s[i-1][j]!='#' && s[i][j+1]!='#' && s[i][j-1]!='#'){
        a=1;
      }
    }
  }
  if(a){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}


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

int main()
{
	double a;
	while(cin >> a){
		double sum = a;
		for(int i=2;i<=10;i++){
			if(i%2==0){
				a *= 2.0;
				sum += a;
			}else{
				a /= 3.0;
				sum += a;
			}
		}
		printf("%.6lf\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1236
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.Arrays;
import java.util.HashSet;

public class Main {

    public static void main(String[] args) throws IOException {
        try (InputReader reader = new InputReader(System.in)) {
            solve(reader);
        }
    }

    private static void solve(InputReader reader) throws IOException {
        int n = reader.readInt();
        int[] as = reader.readIntsSplitByDelimiter(" ");
        int ans = 0;
        for (int i = 1; i < n; i++) {
            if (as[i] == as[i - 1]) {
                as[i] = 0;
                ans++;
            }
        }
        System.out.println(ans);
    }
}

class Util {
    static int gcd(int m, int n) {
        int min = Math.min(m, n);
        int max = Math.max(m, n);
        while (min != 0) {
            int tmp = min;
            min = max % tmp;
            max = tmp;
        }

        return max;
    }

    static int lcm(int m, int n) {
        return m / gcd(m, n) * n;
    }
}

class InputReader implements Closeable, AutoCloseable {
    private final BufferedReader br;

    InputReader(InputStream inputStream) {
        this.br = new BufferedReader(new InputStreamReader(inputStream));
    }

    String readLine() throws IOException {
        return this.br.readLine();
    }

    int readInt() throws IOException {
        return Integer.parseInt(this.readLine());
    }

    long readLong() throws IOException {
        return Long.parseLong(this.readLine());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(this.readLine());
    }

    String[] readStringsSplitByDelimiter(String delimiter) throws IOException {
        return this.readLine().split(delimiter);
    }

    int[] readIntsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        int[] ints = new int[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            ints[i] = Integer.parseInt(strings[i]);
        }

        return ints;
    }

    long[] readLongsSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        long[] longs = new long[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            longs[i] = Long.parseLong(strings[i]);
        }

        return longs;
    }

    double[] readDoublesSplitByDelimiter(String delimiter) throws IOException {
        String[] strings = this.readStringsSplitByDelimiter(delimiter);

        int stringsLength = strings.length;
        double[] doubles = new double[stringsLength];
        for (int i = 0; i < stringsLength; i++) {
            doubles[i] = Double.parseDouble(strings[i]);
        }

        return doubles;
    }

    @Override
    public void close() throws IOException {
        this.br.close();
    }
}


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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int V = max(X, Y);

    int i, j, v;
    int minv = 1000000000;
    // cout << minv << endl;
    for (int k = 0; k <= V; k++)
    {
        i = max(X - k, 0);
        j = max(Y - k, 0);
        v = A * i + B * j + C * 2 * k;
        // cout << i << " " << j << " " << 2 * k << endl;
        // cout << v << endl;
        minv = min(minv, v);
    }
    cout << minv << endl;
}

Measured memory_bytes: 256
//Be Name Khoda
//no comment...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 7;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
bool cycle = false;
ll l[MAXN], r[MAXN], d[MAXN], visited[MAXN], finished[MAXN], dist[MAXN];
vector<pair<ll, ll> > G[MAXN], in[MAXN];
vector<ll> tot;
void dfs(int u)
{
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v.first])
			dfs(v.first);
		else
		if(!finished[v.first])
		{
			cycle = true;
		}
	finished[u] = 1;
}
void dfs2(int u)
{
	tot.push_back(u);
	visited[u] = 1;
	for (auto v : G[u])
		if(!visited[v.first])
		{
			dist[v.first] = dist[u] + v.second;
			dfs2(v.first);
		}
	for (auto v : in[u])
		if(!visited[v.first])
		{
			dist[v.first] = dist[u] - v.second;
			dfs2(v.first);
		}	
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> l[i] >> r[i] >> d[i];
		G[l[i]].push_back({r[i], d[i]});
		in[r[i]].push_back({l[i], d[i]});
	}
	//check if cycle;
	for (int i = 1; i <= n; i++)
		if(!visited[i])
		{
			dfs(i);
		}
	if(cycle)
		return cout << "No", 0;
	memset(visited, 0, sizeof visited);
	for (int i = 1; i <= n; i++)
		if(!visited[i] && in[i].size() == 0)
		{
			tot.clear();
			dfs2(i);
			ll mn = 0;
			for (auto u : tot)
				mn = min((ll)mn, dist[u]);
			for (auto u : tot)
				dist[u] += -mn;
		}
	for (int i = 1; i <= n; i++)
		if(dist[i] > infint)
			return cout << "No", 0;
	
	for (int i = 0; i < m; i++)
		if(dist[r[i]] - dist[l[i]] != d[i])
			return cout << "No", 0;
	cout << "Yes";
}

Measured memory_bytes: 33268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int, ll> m;
    rep(i,n){
        m[a[i]]++;
    }
    ll ans = 0;
    for(auto mi = m.begin(); mi != m.end(); mi++){
        if (mi->second > mi->first){
            ans += mi->second - mi->first;
        }
        else if (mi->second < mi->first){
            ans += mi->second;
        }
    }
    cout << ans << endl;
}

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

typedef long long LL;
const int N = 100005;

int n, a[N], rk[N], pos;
LL ans[N];

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, pos = n;
	for (int i = 0; i < n; ++i) std::cin >> a[i];
	for (int i = 0; i <= n; ++i) rk[i] = i;
	std::sort(rk, rk + n + 1, [] (int x, int y) {return a[x] > a[y];});
	for (int l = 0, r = 0; l < n; l = r) {
		while (a[rk[l]] == a[rk[r]]) pos = std::min(pos, rk[r++]);
		ans[pos] += (LL) (a[rk[l]] - a[rk[r]]) * r;
	}
	for (int i = 0; i < n; ++i) std::cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 2688
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    right, left = 0, 0
    ans = n
    for i in s:
        right += 1 if i=="E" else 0

    for i, char in enumerate(s):
        right -= 1 if char=="E" else 0
        cnt = left + right
        ans = min(ans,cnt)
        left += 1 if char=="W" else 0

    print(ans)
main()


Measured memory_bytes: 93136
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string hoge=s;
    reverse(hoge.begin(),hoge.end());
    
    int count=0;
    for(int i=0;i<hoge.size();i++){
        if(s[i]!=hoge[i]) count++;
    }
    
    cout<<count/2<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define ff first
#define pb push_back
#define ss second
#define maxn 100005
using namespace std;

ll A[maxn], res = 1LL, cal[maxn];

ll mul(ll x, ll y){
    ll res = (x%mod * y%mod)%mod;
    return res;
}


int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> A[i];
    }
    int taken = 3;
    for(int i=1;i<=n;i++){
        if(!A[i]){
            res = mul(res, taken);
            taken --;
        }
        else{
            res = mul(res, cal[A[i]-1] - cal[A[i]]);
        }
        cal[A[i]] ++;

    }
    cout << res << endl;




    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int N = 1e5+5;
int a[N];

void fileIO()
{
        #ifndef ONLINE_JUDGE
        freopen("int.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
}
int main()
{
	IOS;
    //fileIO();
    int n,l;
    cin >> n >> l;
    int temp = 0;
    for(int i = 0; i < n; i++)
    {
        temp += l+i;
    }
    if(l >= 0)
    {
        cout << temp - l;
    }
    else if(l < 0 and l+n-1 >= 0)
    {
        cout << temp;
    }
    else
    {
        cout << temp-n-l+1;
    }
	return 0;
}


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

#define FasterIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(), v.end()
const int MOD = 1e9+7;

int main(){
    FasterIO;

    int n, k;
    string s;

    while(cin>>n>>s>>k){
        for(int i=0; i<n; i++){
            if(s[i]!=s[k-1])
                s[i] = '*';
        }

        cout<<s<<endl;
    }

    return 0;
}



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

int main() {
  long a;
  long b;
  long tmp;
  long x;
  cin >> a >> b;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  } 

  int r;
  r = a % b;

  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  cout << x/b << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int h,w,i,j;
	char a[105][105];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)
		for(j=0;j<w;j++)
			scanf(" %c",&a[i][j]);
		for(i=-1;i<h+1;i++){
			printf("#");
			for(j=0;j<w;j++){
				if(i==-1 || i==h)
					printf("#");
				else
					printf("%c",a[i][j]);
			}
			printf("#\n");
		}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    ll n;
    cin >> n;
    vector<ll> v;
    for (ll i = 1; i <= n; i++) {
        if (i % 3 == 0 && i % 5 == 0)
            v.push_back(0);
        else if (i % 3 == 0)
            v.push_back(0);
        else if (i % 5 == 0)
            v.push_back(0);
        else
            v.push_back(i);
    }
    ll sum = 0;
    for (ll i = 0; i < v.size(); i++) {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 11592
#include <stdio.h>

int main(){
    int A,B,C;
    int i,cnt = 0;
    scanf("%d %d %d",&A,&B,&C);
    for(i=1;i<=C;i++){
        if(A*i<=B) cnt=i;
        else break;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;


int main(){
    
    int n;
    int a[maxn];
    cin >> n;
    for(int i=0;i<n;i++)cin >> a[i];
    int M1=0, M2=0;
    for(int i=0;i<n;i++){
        if(a[i]>=M1){
            M2=M1;
            M1=a[i];
        }else if(a[i]>=M2){
            M2=a[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]==M1){
            cout << M2<<endl;
        }else{
            cout << M1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4372
#include <iostream>
using namespace std;
//ITP2の9番台はPythonで実装したら負けだという気がしたのでc++で書きます。

int main(void){
  int n,m;
  cin>>n;
  long A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cin>>m;
  long B[m];
  for(int i=0;i<m;i++){
    cin>>B[i];
  }
  int i=0;
  int j=0;
  while(i<n and j<m){
    if(A[i]<B[j]){
      cout<<A[i]<<endl;
      i++;
    }
    else if(A[i]>B[j]){
      cout<<B[j]<<endl;
      j++;
    }
    else{
      i++;
      j++;
    }
  }
  for(int k=i;k<n;k++){
    cout<<A[k]<<endl;
  }
  for(int k=j;k<m;k++){
    cout<<B[k]<<endl;
  }
  return 0;
}



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

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

    ll h, w;
    cin >> h >> w;
    //1行ごとに string で持つと楽
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    //最初の1行
    REP(i, w + 2){
        cout << '#';
    }
    cout << endl;

    //真ん中のとこ
    REP(i, h){
        cout << '#' << s[i] << '#' << endl;
    }
    //最後の1行
    REP(i, w + 2){
        cout << '#';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int rd(){
    int a=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))a=(a<<1)+(a<<3)+(ch^48),ch=getchar();
    return a;
}
ll rdll(){
    ll a=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))a=(a<<1)+(a<<3)+(ch^48),ch=getchar();
    return a;
}

const int N=100005;

int k,a,b;

int main(){
	k=rd(),a=rd(),b=rd()-a;
	if(b<3||k<a-1)printf("%d",k+1);
	else{
	    ll v=(k-a+1)>>1;//printf("DBG:%lld\n",v);
	    printf("%lld",v*b+k-v-v+1);
	}
	return 0;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define loop(i, s, n) for(int i = s; i < n; i++)
#define min(x, y) (x) > (y) ? (y) : (x)
#define max(x, y) (x) < (y) ? (y) : (x)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
 
int main()
{
  ll n;
  cin >> n;

  v(ll) arr(n);
  loop(i, 0, n)
    cin >> arr[i];

  ll max = 0, max_2 = 0;

  loop(i, 0, n)
  {
      if(arr[i] >= max)
      {
          max_2 = max;
          max = arr[i];
      }
      else if(arr[i] > max_2 && arr[i] <= max)
      {
          max_2 = arr[i];
      }
  }

  loop(i, 0, n)
  {
      if(arr[i] == max)
        cout << max_2 << "\n";
      else
        cout << max << "\n";
  }
  return 0;
}

Measured memory_bytes: 3200
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int = 0, 0, 0

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	M, _ := strconv.Atoi(read())

	pq := &PriorityQueue{}
	heap.Init(pq)

	for i := 0; i < N; i++ {
		a, _ := strconv.Atoi(read())
		heap.Push(pq, a)
	}
	for i := 0; i < M; i++ {
		heap.Push(pq, heap.Pop(pq).(int)/2)
	}
	l := pq.Len()
	for i := 0; i < l; i++ {
		sum += heap.Pop(pq).(int)
	}
	fmt.Println(sum)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

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

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] > h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 7552
#include<iostream>
using namespace std;
int n,i,k,val,V[2005][2005],j;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(i=1; i*(i-1)<=2*n; i++)
        k=i;
    if(k*(k-1)!=2*n)
    {
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
    cout<<k<<"\n";
    val=1;
    for(i=1; i<=k; i++)
    {
        cout<<k-1<<" ";
        for(j=1; j<=V[i][0]; j++)
            cout<<V[i][j]<<" ";
        for(j=i+1; j<=k; j++)
        {
            cout<<val<<" ";
            V[j][++V[j][0]]=val;
            val++;
        }
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4608
#include <set>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n; string s;
int main() {
	cin >> n;
	set<string> v;
	for (int i = 0; i < n; i++) {
		cin >> s;
		v.insert(s);
	}
	if (v.size() == 3) cout << "Three" << endl;
	else cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 768
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
};

struct edge {
    int u, v;
    int64_t cost;
    edge(int u=0, int v=0, int64_t cost=0):u(u), v(v), cost(cost) {} 
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

vector<P> pp;

// 辺の数でresize & 入力
vector<edge> es;
//最小全域木, Vは頂点数
int64_t kruskal(int V) {
    int E = es.size();
    sort(es.begin(), es.end(), comp);
    UnionFind uft(V);
    rep(i, pp.size()){
        uft.unite(pp[i].first, pp[i].second);
    }
    int64_t res = 0;
    for(int i = 0; i < E; ++i) {
        edge e = es[i];
        if(!uft.same(e.u, e.v)) {
            uft.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vvi a(n, vi(n));
    rep(i, n) {
        rep(j, n) {
            cin >> a[i][j];
            if(i != j) {
                es.emplace_back(i, j, a[i][j]);
            }
        }
    }

    ll ans = 0;
    rep(i, n) {
        rep(j, i) {
            bool x = true;
            rep(k, n) {
                if(abs(a[i][k] + a[k][j]) < a[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if(i != k and j != k and a[i][k] + a[k][j] == a[i][j]) x = false;
            }
            if(x) {
                pp.emplace_back(i, j);
                ans += a[i][j];
            }
        }
    }


    cout << kruskal(n)+ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int K;
  cin >> K;
  
  char x = S.at(K - 1);
  
  for(char &c : S){
    if(c != x)
      c = '*';
  }
  
  cout << S << endl;
}


Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = [int(_) for _ in input().split()]

que = []
for i in range(n):
    heapq.heappush(que, -a[i])

for i in range(m):
    t = -heapq.heappop(que)
    t /= 2
    heapq.heappush(que,-t)

res = 0
for i in range(n):
    res += int(-que[i])

print(res)

Measured memory_bytes: 14180
import math
N = int(input())
X = list(map(int,input().split()))

sum = 0
for x in X:
    sum = sum + x

ele = sum/N
ele1 = math.ceil(ele)
ele2 = ele1-1

#print(ele1)
#print(ele2)


ans1 = 0
ans2 = 0
for x in X:
    ans1 = ans1 + (x-ele1)**2
    ans2 = ans2 + (x-ele2)**2

print(min(ans1,ans2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[100];
	bool color[8];
	for (int i = 0; i < 8; i++) color[i] = 0;
	cin >> n;
	int free = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] < 400) color[0] = 1;
		elif(a[i] < 800) color[1] = 1;
		elif(a[i] < 1200) color[2] = 1;
		elif(a[i] < 1600) color[3] = 1;
		elif(a[i] < 2000) color[4] = 1;
		elif(a[i] < 2400) color[5] = 1;
		elif(a[i] < 2800) color[6] = 1;
		elif(a[i] < 3200) color[7] = 1;
		else free++;
	}
	int cnt = 0;
	for (int i = 0; i < 8; i++) {
		if(color[i]) cnt++;
	}
	if(cnt == 0) cout << 1 << ' ';
	else cout << cnt << ' ';
	cout << cnt+free << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,I##_N=N;I<I##_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;

struct node_t {
  i8t value;
  i8t mark = 0;
  std::vector<i8t> adj;

  std::vector<i8t> lis_save;
  i8t ans;

  i8t lis_update_pos=-1;
  i8t lis_update_old=-1;
};

std::pair<i8t, i8t> LIS_append(std::vector<i8t>& vec,i8t add){
  auto it = std::lower_bound(vec.begin(), vec.end(), add);
  i8t pos = it - vec.begin(), val;
  if (it == vec.end()) {
    val = -1;
    vec.push_back(add);
  } else {
    val = *it;
    *it = add;
  }
  return { pos, val };
}

void tree_make_directed_by_root(std::vector<node_t>& vtx, i8t root){
  std::vector<i8t> stk;
  std::vector<i8t> ind;
  i8t p,i;
  vtx[p=root].mark=1;
  i=0;
  while(1){
    node_t& node=vtx[p];
    if (i<node.adj.size()) {
      i8t& p2=node.adj[i];
      if(vtx[p2].mark){
        p2=-1;
        i++;
      }else{
        stk.push_back(p);
        ind.push_back(i+1);
        vtx[p=p2].mark=1;
        i=0;
      }
    }else{
      // remove parents
      node.adj.erase(
        std::remove(node.adj.begin(),node.adj.end(),-1),
        node.adj.end());

      if (stk.size()){
        p=stk.back();
        i=ind.back();
        stk.pop_back();
        ind.pop_back();
      }else{
        break;
      }
    }
  }
}

int main() {
  R(N);
  std::vector<node_t> vtx;
  F(I,N){
    R(a);
    node_t v {a};
    vtx.push_back(v);
  }
  F(I,N-1){
    R(u1)R(v1);
    u1--;
    v1--;
    vtx[u1].adj.push_back(v1);
    vtx[v1].adj.push_back(u1);
  }

  tree_make_directed_by_root(vtx, 0);

  std::vector<i8t> lis;
  std::vector<i8t> stk;
  std::vector<i8t> ind;
  i8t p=0,i=0;
  auto [pos, val] = LIS_append(lis,vtx[p].value);
  vtx[p].ans=lis.size();
  vtx[p].lis_update_pos=pos;
  vtx[p].lis_update_old=val;

  while (1){
    if (i<vtx[p].adj.size()){
      stk.push_back(p);
      ind.push_back(i+1);
      p=vtx[p].adj[i];
      i=0;
      auto [pos, val] = LIS_append(lis,vtx[p].value);
      vtx[p].ans=lis.size();
      vtx[p].lis_update_pos = pos;
      vtx[p].lis_update_old = val;
    }else{
      if(stk.size()){
        // backtrack
        if (vtx[p].lis_update_old<0)
          lis.pop_back();
        else
          lis[vtx[p].lis_update_pos] = vtx[p].lis_update_old;

        p=stk.back();
        i=ind.back();
        stk.pop_back();
        ind.pop_back();
      }else
        break;
    }
  }

  for(auto const& node:vtx){
    P(node.ans);
  }
  return 0;
}


Measured memory_bytes: 33120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		for (int i=0;i<s.length();i++) {
			int a = s.charAt(i)-'A';
			a=(a+N)%26;
			System.out.print((char)(a+'A'));
		}
	}
}


Measured memory_bytes: 40020
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] V = new int[N];
        int[] C = new int[N];
        for(int i = 0; i < N; i++){
            V[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++){
            C[i] = sc.nextInt();
        }
        
        int total = 0;
        for(int i = 0; i < N; i++){
            if( V[i] - C[i] > 0) total += (V[i] - C[i]);
        }
        
        System.out.println(total);
    }
}


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

int a[101];
bool c[8];

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

    int sum1 = 0;
    int sum2 = 0;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        int num = a[i] / 400;
        if(num >= 8){
            ++sum2;
        }
        else if(!c[num]){
            c[num] = true;
            ++sum1;
            ++sum2;
        }
    }
    if(sum1 == 0){
        sum1 = 1;
    }
    cout << sum1 << " " << sum2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long int a,b,c;
  cin>>a>>b>>c;
  long long int res;
  res = (c-a-b)*(c-a-b)-4*a*b;

  if(res>0&&c-a-b>0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, Y = input().split()

if X == Y:
	print("=")
elif X > Y:
	print(">")
else:
	print("<")


Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,ans=0;
  pair<int,int> a[10000];
  while(1){
    ans=0;
    cin>>n>>m;
    if(n==0 && m==0) break;
   
    for(int i=0;i<n;i++){
      cin>>a[i].second>>a[i].first;
    }
    sort(a,a+n);
    for(int i=n-1;i>=0;i--){
      if(a[i].second<m) m-=a[i].second;
      else if(m>0){
	ans+=(a[i].second-m)*a[i].first;
	m=0;
      }
      else ans+=(a[i].first)*a[i].second;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3148
# -*- coding: utf-8 -*-
*s, = map(int,input())

# 初期値は大きい値
ans = len(s)

# iは最初に使う色（0 or 1）
for i in range(2):
    # 変える必要があるタイル数
    cnt = 0

    for j in range(len(s)):
        if (j % 2 == 0) ^ (s[j] == i):
            cnt = cnt +1
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(void)
{
    int N;
    cin >> N;

    for(int i = 0; i <= N/4; i++)
        for(int j = 0; j <= N/7; j++)
            if(i * 4 + j * 7 == N)
            {
                cout << "Yes" << endl;
                return 0;
            }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
using namespace std; typedef long long ll; const int INF=1e9; typedef pair<int,int> P;

int main() {
  string s; cin>>s;
  int n=s.size();
  if (n<26) {
    bool u[26]; fill(u,u+n,false);
    for(int i=0;i<n;i++) u[s[i]-'a']=true;
    for(int i=0;i<26;i++) {
      if (!u[i]) {
        cout<<s<<(char)('a'+i)<<endl;
        break;
      }
    }
  } else {
    int a[n], b[n];
    for(int i=0;i<n;i++) a[i]=s[i]-'a', b[i]=a[i];
    if (next_permutation(a,a+n)) {
      for(int i=0;i<n;i++) {
        cout<<(char)('a'+a[i]); if (a[i] != b[i]) break;
      } cout<<endl;
    } else {
      cout<<-1<<endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int n,m;
vector<int>a(20);

bool dfs(int sum,int count){
	if(count==n)return false;
	if(sum+a[count]==m)return true;
	return(dfs(sum+a[count],count+1)||dfs(sum,count+1));
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>a[i];
	int q;
	cin>>q;
	rep(i,q){
		cin>>m;
		cout<<(dfs(0,0)?"yes":"no")<<endl;
	}
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int a[N], p[N], mp[N];
const int M = 1e9 + 7;

int find(int x) {
	if(p[x] != x) {
		p[x] = find(p[x]);
	}
	return p[x];
}

int main() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		p[i] = i;
	}
	for(int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		p[find(a)] = find(b);
	}
	int res = 0;
	for(int i = 1; i <= n; i++) {
		mp[find(i)]++;
	}
	for(int i = 1; i <= n; i++) {
//		cout << "mp[i] = " << mp[i] << endl;
		res = max(res, mp[i]);
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n, m, s[11], c[11];

    cin >> n >> m;

    if (!m)
    {
        if (n == 1)
            cout << 0;
        if (n == 2)
            cout << 10;
        if (n == 3)
            cout << 100;

        cout << "\n";

        return 0;
    }

    for (int i = 0; i < m; i++)
    {
        cin >> s[i] >> c[i];
        s[i]--;
    }

    int ans = -1;

    for (int i = 0; i < 1000; i++)
    {
        vector <int> digits;

        if (i == 0)
            digits.push_back(0);

        int k = i;

        while (k)
        {
            digits.push_back(k % 10);
            k /= 10;
        }

        reverse(digits.begin(), digits.end());

        bool possible = true;

        for (int j = 0; j < m; j++)
        {
            if (digits.size() != n || s[j] >= digits.size() || digits[s[j]] != c[j])
                possible = false;
        }

        if (possible)
        {
            ans = i;
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256