akhauriyash/Code-Regression huggingface dataset:
class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N = int(input())
INF = 10**18
P = list(map(int, input().split()))
I = [-1] * (N + 1)
tree = UnionFind(N + 2)

for i, p in enumerate(P, start=1):
    I[p] = i

ans = 0
used = [False] * (N + 2)
for p in range(1, N):
    i = I[p]

    # p 未満の範囲 [i - left, i + right]
    left = tree.sizeOfSameRoot(i - 1) if used[i - 1] else 0
    right = tree.sizeOfSameRoot(i + 1) if used[i + 1] else 0

    cnt = 0
    leftMx = i - (left + 1)
    if leftMx >= 1 and not used[leftMx]:
        L = tree.sizeOfSameRoot(leftMx - 1) if (leftMx - 1) >= 0 and used[leftMx - 1] else 0
        cnt += (L + 1) * (right + 1)
    rightMx = i + (right + 1)
    if rightMx <= N and not used[rightMx]:
        R = tree.sizeOfSameRoot(rightMx + 1) if (rightMx + 1) <= N and used[rightMx + 1] else 0
        cnt += (left + 1) * (R + 1)
    ans += cnt * p

    used[i] = True
    if used[i - 1]:
        tree.union(i, i - 1)
    if used[i + 1]:
        tree.union(i, i + 1)
print(ans)


Measured memory_bytes: 17764
#include<stdio.h>

int main(void)
{
	char n[21], i = 0 ;
	scanf( "%s", n);
	while( n[++i] != '\0' ) ;
	for( i -= 1 ; i >= 0 ; i-- )
		putchar(n[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}
template <class T> T permutation(ll n, ll k) { T f(1); for (ll i=0; i<k; ++i, --n) f *= n; return f; }
template <class T> T factorial(ll n) { return permutation<T>(n,n); }
template <class T> T binomial(ll n, ll k) { return permutation<T>(n,k) /= factorial<T>(k); }

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll a) { n *= a; clamp(); return *this; }
    modint& operator /= (modint const& a) { *this *= a.inv(); return *this; }
    modint& operator += (modint const& a) { n += a.n; if (n >= Mod) n -= Mod; return *this; }
    modint& operator -= (modint const& a) { n -= a.n; if (n < 0) n += Mod; return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint inv() const { return this->pow(Mod-2); }
    ll get() { return n; }
    modint pow(ll p) const {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        return modint(a);
    }
};

const ll Mod = (ll)1e9+7;
using mint = modint<Mod>;

mint f(ll n) {
    static map<ll,mint> memo;
    if (memo.count(n))
        return memo[n];
    ll pat = n - 6 +2;
    if (pat < 1)
        return 1;
    mint m;
    for (ll i=0; i < pat; ++i) {
        m += f(n-3-i);
    }
    memo[n] = m;
    return m;
}
int main() {
    fastio;
    ll ans=0;
    ll s;
    cin >> s;
    ll n = s;
    if (s < 3)
        ans = 0;
    else
        ans = f(n).get();
    cout << ans << endl;
}


Measured memory_bytes: 3776
#include<iostream>
#include<algorithm>
#include <vector>

using namespace std;

int main() {
	int n,t,ans = 1001;
	cin >> n >> t;

	vector<pair<int, int>> c(n);

	for (int i = 0; i < n; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		c[i] = make_pair(tmp1, tmp2); //first = c,second = t
	}

	for (int i = 0; i < n; i++) {
		if (c[i].second <= t) {
			ans = min(ans, c[i].first);
		}
	}

	

	if (ans == 1001) cout << "TLE";
	else cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int k,s;
    cin>>k>>s;

    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=i;j<=k;j++){
            for(int l=j;l<=k;l++){
                if(i+j+l!=s) continue;
                else if(i==j&&i==l) ans++;
                else if(i==j||j==l||l==i) ans+=3;
                else ans+=6;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  inp.shift()
  const P = [0,0,0,0,0,0,1,1,1,2];
  const Q = [1,1,1,2,2,3,2,2,3,3];
  const R = [2,3,4,3,4,4,3,4,4,4];
  let S = new Array(5).fill(0)

  inp.forEach(str => {
    const index = 'MARCH'.indexOf(str[0])
    if (~index) S[index]++
  })
  let ans = 0
  for (let i = 0; i < 10; i++) {
    ans += S[P[i]] * S[Q[i]] * S[R[i]]
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 17100
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,w; cin>>h>>w;
  char s[w+2][h+2]={' '};
  for(int y=1; y<h+1; y++){
    for(int x=1; x<w+1; x++){
      cin>>s[x][y];
    }
  }
  for(int y=1; y<h+1; y++){
    for(int x=1; x<w+1; x++){
      if(s[x][y]=='#') {
        cout<<'#'; continue;
      }
      int cnt=0;
      if(s[x-1][y-1]=='#') cnt++;
      if(s[x][y-1]=='#') cnt++;
      if(s[x+1][y-1]=='#') cnt++;
      if(s[x-1][y]=='#') cnt++;
      if(s[x+1][y]=='#') cnt++;
      if(s[x-1][y+1]=='#') cnt++;
      if(s[x][y+1]=='#') cnt++;
      if(s[x+1][y+1]=='#') cnt++;
      cout<<cnt;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a;
  double b;
  cin>>a>>b;
  string s=to_string(b);
  string bb;
  bb+=s.at(0);
  bb+=s.at(2);
  bb+=s.at(3);
  int c=stoi(bb);
  long long ans=a*c;
  ans=ans/100;
  cout<<ans<<endl;
}


Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	string S, T;
	cin >> S >> T;

	char sl[27];
	char tl[27];
	for(int i=0; i<27; i++) {
		sl[i] = 0; // init
		tl[i] = 0; // init
	}
	
	// 各文字の出現位置を保存する
	for(int i=0; i<S.size(); i++) {
		int sIdx = S[i] - 'a'; // 0 to 25
		int tIdx = T[i] - 'a'; // 0 to 25
		
		char s = S[i];
		char t = T[i];
		
		if(sl[sIdx] == 0) sl[sIdx] = t;
		else if(sl[sIdx] != t) {
			cout << "No";
			return 0;
		}
		if(tl[tIdx] == 0) tl[tIdx] = s;
		else if(tl[tIdx] != s) {
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";
	return 0;
}


Measured memory_bytes: 776
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

    int sum =0;
    map<int, int> PT;
    for(int i = 1; i <= N; i++){
        int T;
        cin >> T;
        sum+= T;
        PT[i] = T;
    }
    int M;
    cin >> M;
    vector<pair<int ,int>> PX(M);
    for(int i = 0; i < M; i++){
        cin >> PX[i].fi >> PX[i].se;
    }
    for(auto px : PX){
        cout << sum - (PT[px.fi] - px.se) << endl;
    }
}


Measured memory_bytes: 3536
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List
dice = list(map(int, input().split()))
D = [dice]
for i in range(0, 3):
    D.append(north(D[i]))
D.append(south(west(D[0])))
D.append(south(east(D[0])))
for i in range(6):
    for j in range(3):
        if j == 0:
            D.append(east(D[i + j]))
        else:
            D.append(east(D[5 + 3 * i + j]))

dice2 = list(map(int, input().split()))
k = 0
for i in range(len(D)):
    if dice2 == D[i]:
        print('Yes')
        k = 1
        break
if k == 0:
    print('No')


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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 1000000007

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c;
    vector<vector<int>> a;
    rep(i, n){
        int cost;
        cin >> cost;
        c.push_back(cost);
        vector<int> tmp;
        rep(j, m){
            int A;
            cin >> A;
            tmp.push_back(A);
        }
        a.push_back(tmp);
    }
    int check = 1 << n;
    int minim = INT32_MAX;

    rep(i, check){
        vector<int> und(m, 0);
        int cost=0;
        rep(j, n){
            if(i&(1<<j)){
                cost += c[j];
                rep(k, m){
                    und[k] += a[j][k];
                }
            }
        }
        bool flag=true;
        rep(j, m){
            if(und[j]<x){
                flag = false;
                break;
            }
        }
        if(flag){
            minim = min(cost, minim);
        }
    }

    if(minim!=INT32_MAX)cout << minim << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main(){

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

    map<int, int> count;
    for(int i = 0; i < N; i++){
        count[a[i] - 1]++;
        count[a[i]]++;
        count[a[i] + 1]++;
    }

    int ans = 0;
    for(auto itr = count.begin(); itr != count.end(); itr++) ans = max(ans, itr->second);

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

Measured memory_bytes: 5120
/*
 * D.cpp
 *
 *  Created on: 2012-8-25
 *      Author: Administrator
 */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

long long ans;
long long prime[1000000] = { 2, 3, 5, 7 };
int pn = 4;
void getprime() {
	for (int i = 8; i <= 1000000; i++) {
		bool flag = true;
		for (int j = 0; prime[j] * prime[j] <= i; j++) {
			if (i % prime[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			prime[pn++] = i;
//		cout<<i<<endl;
		}
	}
}
long long frac[100];
long long fracn[100];
int n;
int main() {
	getprime();
	long long l;
//	cout<<pn<<endl;
//	while (cin >> l && l) {
	while (~scanf("%lld", &l) && l) {
		memset(frac, 0, sizeof(frac));
		memset(fracn, 0, sizeof(fracn));
		n = 0;
		for (int i = 0; prime[i] <= l && i < pn; i++) {
			if (l % prime[i] == 0) {
				frac[n] = prime[i];
				while (l % prime[i] == 0) {
					l /= prime[i];
					fracn[n]++;
				}
				n++;
			}
		}
		if (l != 1) {
			frac[n] = l;
			fracn[n] = 1;
			n++;
		}
		ans = 1;
		for (int i = 0; i != n; i++) {
			ans *= fracn[i] * 2 + 1;
		}
//		cout<<ans/2+1<<endl;
		printf("%lld\n", ans / 2 + 1);
	}
}

Measured memory_bytes: 1804
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
 

int main(){
 string S;
  
  cin>>S;
 
	for (int i =0; i < S.size(); i+=2) {
  		cout<<S.at(i);
	}
  

  
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    string s;
    cin >>s;

    if (s=="SUN")
    {
        cout << "7"<<"\n";
    }


    else  if (s=="MON")
    {
        cout << "6"<<"\n";
    }

    else if (s=="TUE")
    {
        cout << "5"<<"\n";
    }

    else if (s=="WED")
    {
        cout << "4"<<"\n";
    }

    else if (s=="THU")
    {
        cout << "3"<<"\n";
    }

    else if (s=="FRI")
    {
        cout << "2"<<"\n";
    }

    else  if (s=="SAT")
    {
        cout << "1"<<"\n";
    }

}


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

using namespace std;

int main()
{
  int h, w;

  while(true)
  {
    cin	>> h >> w;
    if(!h && !w)
      break;
    for(int i = 0; i < h; i++)
    {
      for(int j = 0; j < w; j++)
      {
	if(i ==	0 || i == h - 1 || j == 0 || j == w - 1)
          cout << "#";
	else
          cout << ".";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6 + 1;
ll bigMod (ll x, ll n, ll m) {
  if (n == 0LL) return 1LL % m;
  ll u = bigMod(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
int main () {
  ll k;
  scanf("%lld", &k);
  k *= 9;
  ll ans = -1LL;
  for (ll i = 1LL; i <= N; ++i) {
    ll p = ((7 * (bigMod(10, i, k) % k)) % k - 7 % k) % k;
    if (p == 0LL) {
      ans = i;
      break;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 3772
import math

N = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = 1
b = 1
for i in range(N):
    a += (p[i] - 1) * math.factorial(N - i - 1)
    for j in range(i + 1, N):
        if p[j] > p[i]:
            p[j] -= 1

for i in range(N):
    b += (q[i] - 1) * math.factorial(N - i - 1)
    for j in range(i + 1, N):
        if q[j] > q[i]:
            q[j] -= 1

print(abs(a - b))


Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S=sc.nextInt();
        if(S/100>12||S/100==0){
            if(S%100<=12&&S%100>0){
                System.out.println("YYMM");
            }
            else{
                System.out.println("NA");
            }
        }
        else{
            if(S%100<=12&&S%100>0){
                System.out.println("AMBIGUOUS");
            }
            else{
                System.out.println("MMYY");
            }
        }
    }
}

Measured memory_bytes: 21844
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s=readln.chomp.to!(char[]);

  writeln(s[0..($-8)]);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

int main(){
  int x,k;
  int i;

  scanf("%d %d", &k, &x);

  for(i = x - k + 1;i < k + x - 1;i++){
    if(i >= -1000000 && 1000000 >= i) printf("%d ",i);
  }

  if(i >= -1000000 && 1000000 >= i) printf("%d\n", i);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int choco = X;
		while (sc.hasNextInt()) {
			int A = sc.nextInt();
			choco += (D % A == 0) ? D / A : (D / A) + 1;
		}
		System.out.println(choco);
	}
}

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

int main()
{
	string s;
	bool f = 0;

	cin >> s;

	if (s == "keyence")
		f = 1;
	else if (s.size() > 7){
		for (int i = 0; i < 7; i++) {
			string t = s.substr(0, i) + s.substr(i + s.size() - 7, s.size());
			if (t == "keyence") {
				f = 1;
				break;
			}
		}
	}

	if(f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll H,W;
    cin >> H >> W;
    char a[H][W];
    ll h[H];
    rep(i,H) h[i] = 0;
    ll w[W];
    rep(i,W) w[i] = 0;
    rep(i,H){
        rep(j,W){
            cin >> a[i][j];
            if(a[i][j]=='.'){
                h[i]++;
                w[j]++;
            }
        }
    }
    rep(i,H){
        if(h[i]<W){
            rep(j,W){
                if(w[j]<H) cout << a[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}


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

int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n==0) break;
		int max=0,min=1000,sum=0;
		for(int i=0;i<n;i++){
			int a;
			cin >> a;
			sum+=a;
			if(max<a) max=a;
			if(min>a) min = a;
		}
		int result = (sum-max-min) / (n-2);
		cout << result << endl;
	}
	
	return 0;
}

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

int main()
{
    int n, mini;
    int64_t sum=0;
    cin >> n;
    int a[n];
    
    rep(i, n)
    {
        cin >> a[i];
    }

    mini = a[0];
    rep2(i, 1, n)
    {
        if(mini > a[i])
        {
            sum += mini - a[i];
        }
        else
            mini = a[i];
    }

    cout << sum << endl;


}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main(){

long long a,b,c,d;
cin>>a>>b>>c>>d;
long long ans;
long long temp1=a*c;
ans=temp1;
long long temp2=b*d;
long long temp3=a*d;
long long temp4=b*c;
if(a<=0&&b>=0){
  long long temp=0;
  ans=max(ans,temp);
}
if(c<=0&&d>=0){
  long long temp=0;
  ans=max(ans,temp);
}
ans=max(temp2,ans);
ans=max(temp3,ans);
ans=max(temp4,ans);
cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

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

int main(){
  int i, n;
  scanf("%d",&n);
  int a[n],d[n];
  a[0] = 0;
  for(i=1;i<n;i++) scanf("%d",&a[i]);
  rep(i,n) d[i] = 0;
  rep(i,n) d[a[i]]++;
  for(i=1;i<n;i++) {
    printf("%d\n",d[i]);
  }
  puts("0");
}
   

Measured memory_bytes: 3296
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define ll long long int
#define vr vector
#define pb push_back
#define pf push_front
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define loop(i,n) for(i=0;i<n;i++)
#define inp !cin.eof()
#define sec itr->second
#define fir itr->first

ll power(ll x,ll y,ll p)
{
    ll res = 1;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x)%p;


        y = y>>1;
        x = ((x%p)*(x%p))%p;
    }
    return res%p;
}



int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     // iterating a loop until input is providing====!cin.eof()

   // ll t;cin>>t;
        //while(t--)
        {

         ll n,m,i,x,y,p=0,z,j,k,flag=1,mi=mod,ans=0,sum=0,cnt=0;

         cin>>n>>m>>k;
         p=n/m;
         if(n%m!=0)
            p++;
         cout<<p*k;









         }
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll X,A;
    cin >> X >> A;

    cout << (X<A?0:10) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
// 素因数分解 O(√n)以下
// (素因数,個数)
template<typename T>
vector<pair<T, ll> > prime_factorization(T n) {
    vector<pair<T, ll> > res;
    for (T i = 2; i*i <= n; i++) {
        ll cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) res.push_back(make_pair(i,cnt));
    }
    if (n > 1) res.push_back(make_pair(n,1));
    return res;
}

int main() {
  ll n,k,m,x=0, y=0 , z = 0, h,w, ans=0,sum = 1, Max = -1, Min = 3e9+1;
  string u;
  bool ok=true;
  cin >> n;
  
  auto a = prime_factorization(n);

  for(int i=0; i<a.size();i++){
    ll m = 1;
    while(a[i].second >= m){
      a[i].second -= m;
      ans++;
      m++;
    }
  }
  pri(ans);
  return 0;
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
 
int main(){
 
  int N;
  int ans=1;
  cin >> N;
  long H[N];
  for(int i=0; i<N; i++) cin >> H[i];
 
  for(int i=0; i<N-1; i++){
    if(H[i+1]>H[i]) H[i+1]--;
  }
 
  for(int i=1; i<N; i++){
    if(H[i]<H[i-1]) ans = 0;
  }
 
if(ans)cout<<"Yes";
  else cout<<"No";
  return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tc;
	cin >> tc;
	while(tc--){
		int n;
		cin >> n;
		vector<long long> a(n);
		for(int i=0;i<n;i++) cin >> a[i];
		string str;
		cin >> str;
		
		if(str.back()=='1'){
			cout << 1 << "\n";
			continue;
		}
		
		vector<long long> base;
		for(int i=n-1;i>=0;i--){
			long long v=a[i];
			for(long long b:base){
				v=min(v,v^b);
			}
			if(str[i]=='0' && v>0){
				for(int j=0;j<(int)base.size();j++){
					base[j]=min(base[j],base[j]^v);
				}
				base.push_back(v);
				sort(base.begin(),base.end());
				reverse(base.begin(),base.end());
			}
			a[i]=v;
		}
		
		bool bo=false;
		for(int i=0;i<n;i++){
			if(str[i]=='1' && a[i]!=0) bo=true;
		}
		
		if(bo) cout << 1 << "\n";
		else cout << 0 << "\n";
	}
	return 0;
}

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

constexpr ll INF = ll(1e+18) + 1;

ll dist(ll a, ll b, ll c, ll d) {
    return abs(a-c) + abs(b-d);
}

int main() {
    int R, G, B, N;
    int ans = 0;

    cin >> R >> G >> B >> N;

    rep(i, N/R + 1) {
        rep (j, (N-i*R)/G + 1) {
            if ((N - (i*R+j*G))%B == 0) {ans++;}
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3596
d,g = map(int,input().split())
pc = [list(map(int,input().split())) for _ in range(d)]
res = 10**10
for bit in range(1 << d):
    score = 0
    prob = 0
    used = [False] * d
    for i in range(d):
        if bit & 1:
            used[i] = True
            score += pc[i][1]
            score += (i + 1) * 100 * pc[i][0]
            prob += pc[i][0]
        bit >>= 1
    dd = []
    for i in range(d-1,-1,-1):
        if not used[i]:
            dd.append([(i+1) * 100, pc[i][0]])
    pivot = 0
    flag = True
    while score < g:
        if pivot == len(dd):
            flag = False
            break
        if dd[pivot][1] == 0:
            pivot += 1
            continue
        else:
            score += dd[pivot][0]
            prob += 1
            dd[pivot][1] -= 1
    if not flag:
        continue
    res = min(res, prob)
print(res)


Measured memory_bytes: 3064
from math import cos, radians
A, B, H, M = map(int, input().split())  # 時針Acm, 分針Bcm, H時M分
hour_hand = H*30 + M*0.5
minit_hand = M*6
c = (A**2 + B**2 - 2*A*B*cos(radians(hour_hand-minit_hand)))**(1/2)
print(c)


Measured memory_bytes: 9472
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> v(n+1);
    rep(i,n+1) cin >> v[i];
    vector<ll> node(n+1, INF);
    node[0] = 1 - v[0];
    reps(i,n){
        // node[i] = min(INF, node[i-1] * 2 - v[i]);
        chmin(node[i], node[i-1] * 2 - v[i]);
        chmax(node[i], -INF);
    }
    debug(node);
    if(node[n] < 0){
        cout << -1 << endl;
        return 0;
    }
    vector<ll> rev(n+1);
    rev[n] = 0;
    rrep(i,n){
        rev[i] = min(node[i], (rev[i+1] + v[i+1]));
    }
    debug(rev);

    ll ans = 0;
    rep(i,n+1){
        ans += v[i] + rev[i];
    }
    // bool ok = true;
    // rep(i,n)ok &= rev[i] > 0;

    // cout << (ok ? ans : -1) << endl;
    cout << ans << endl;
}

Measured memory_bytes: 5548
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, res; cin >> N;
    int A[N], B[N], C[N-1];
    res = 0;
    for (int i = 0; i < N; i++){ cin >> A[i]; }
    for (int i = 0; i < N; i++){ cin >> B[i]; }
    for (int i = 0; i < N - 1; i++){ cin >> C[i]; }
    int cur, pre;
    cur = pre = -1; 
    for (int j = 0; j < N; j++)
    {
        cur = A[j]-1;
        res += B[cur];
        if (cur == pre + 1)
        {
            res += C[pre];
        }
        pre = cur;
    }
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) sort(x.begin(),x.end())
#define RALL(x) sort(x.rbegin(),x.end())
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}
ll inv_mod(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
//関数とか

//宣言とか
int n, k;
int ans;
/*signed*/int main(void) {
    cin >> n >> k;
    vector<int> vec(n);
    vector<int> suuji(200100);
    rep(i, n) {
        cin >> vec[i];
        ++suuji[vec[i]];
    }
    sort(suuji.rbegin(),suuji.rend());
    rep(i, k) {
        ans += suuji[i];
    }
    cout << max(0, n - ans) << endl;
    return 0;
}

Measured memory_bytes: 4816
#include <stdio.h>
int main(){
  long long int x,ans,d,r;
  scanf("%lld",&x);
  if(x<=6)ans=1;
  else {
    d=x/11;
    r=x%11;
    ans=d*2;
    if(r>6)ans+=2;
    else if(1<=r && r<=6) ans++;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int n;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    int ans = 0;
    REP(i,n){
        if(a[a[i]-1] == i+1){
            ans++;
        }
    }
    ans /= 2;
    cout << ans << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
 
    for (int i = 1; i <= n; ++i) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }
        if (x % 10 == 3) {
            cout << " " << i;
            continue;
        }
        x /= 10;
        for (;;) {
            if (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            } else {
                break;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int):
    print(K*((K-1)**(N-1)))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  double N;
  cin>>N;
  vector<double> v(N);
  for(int i=0; i<N; i++){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  for(int i=0; i<N-1; i++){
    v.at(i+1)=(v.at(i)+v.at(i+1))/2;
  }
  printf("%.10f\n",v.at(N-1));
  return 0;
}

Measured memory_bytes: 3796
//Deep Godhani
//DAIICT

#include<bits/stdc++.h>
using namespace std;

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

#include <bits/stdc++.h>
using namespace std;

ld fact(int n)
{
  ld ans = 1;
  for(int i=1;i<=n;i++)
  {
    ans = ans*i;
  }
  return ans;
}

ld ncr(int n,int r)
{
  return (ld) fact(n)/(fact(r)*fact(n-r));
}

void primeFactors(int n)
{
    while (n % 2 == 0)
    {
        cout << 2;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            cout << i;
            n = n/i;
        }
    }
    if (n > 2)
        cout << n;
}

void solve()
{
    ll n;
    cin >> n;
    ll h[n];
    for(int i=0;i<n;i++)
    {
      cin >> h[i];
    }

    vector<ll> dp(n,0);

    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);

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

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

int main()
{
    FAST;
    ll t=1;
    //cin >> t;
    while(t--)
    {
      //cout << "************" << endl;
      solve();
      //cout << "************"  << endl;
    }
		return 0;
}


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

int main(){
  long n;
  long t;
  cin>>n;
  long ans = 0;
  if(n == 1){
    ans=0;
  }
  else{
    for(long i = 1;i*i<=n;i++){
      if(n%i == 0){
        t = (n/i)-1;
        if(n%t == n/t){
          ans += t;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e8
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V 100005
int V, h, w;
int table[400][400];
bool nashi[20][20];

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


void warshall_floyd(){
  REP(i, V) REP(j, V) REP(k, V) table[j][k] = min(table[j][k], table[j][i] + table[i][k]);
}

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


int main() {
    cin >> h >> w;

    REP(i, h) {
        string s;
        cin >> s;
        REP(j, w) {
            if(s[j] == '.') {
                nashi[i][j] = true;
            } else {
                nashi[i][j] = false;
            }
        }
    }

    REP(i, h*w) REP(j, h*w) {
        table[i][j] = INF;
        if(i == j) {
            table[i][j] = 0;
        }
    }

    REP(i, h) REP(j, w) {
        REP(k, 4) {
            int x = i+dx[k], y = j+dy[k];
            if(isIn(x, y) && nashi[x][y] && nashi[i][j]) {
                table[i*w+j][x*w+y] = 1;
                //cout << i << " " << j << " " << x << " " << y << endl;
            }
        }
    }

    REP(i, h*w) REP(j, h*w) REP(k, h*w) table[j][k] = min(table[j][k], table[j][i] + table[i][k]);


    int ans = 0;

    REP(i, h*w) REP(j, h*w) {
        if(table[i][j]!= INF) {
            //cout << table[i][j] << endl;
            ans = max(ans, table[i][j]);
        }
    }

    cout << ans << endl;

}
 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, t;
	int dif = 0;
	cin >> s >> t;
	for (int i = 0 ; i < s.size() ; i++) {
		if (s[i] != t[i])
			dif++;
	}
	cout << dif << "\n";

	return 0;
}


Measured memory_bytes: 3888
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int list[] = new int[n];
    
    for(int i = 0; i < n; i++)
      list[i] = sc.nextInt();
    Arrays.sort(list);
    
    int count = 0;
    int a,b,c;
    a: for(int ai = 0; ai < n-2; ai++){
      b: for(int bi = ai+1; bi < n-1; bi++){
        c: for(int ci = bi+1; ci < n; ci++){
    		a = list[ai];
     		b = list[bi];
      		c = list[ci];
    		if(a >= (b+c)){
				break a;
            }
          	if(b >= (c+a))
              continue a;
          	if(c >= (a+b)) 
              continue b;
          	count++; 	
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26128
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
lli power(lli x, lli y, lli p)   
{  
    lli res = 1;     // Initialize result  ! 
    x = x % p; // Update x if it is more than or  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 

int main()
{
	lli n;
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])cout<<"Yes";
	else cout<<"No";
	
	
	
	
    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++);

int main() {
	int N, K;
	int temp = 0;
	cin >> N >> K;
	
	vector<int> xn(N);
	for (int i = 0; i < N; i++) {
		cin >> xn.at(i);
	}
	for (int i = 0; i < N; i++) {
		int pos = xn.at(i);
		int atype = pos*2;
		int btype = abs(K - pos)*2;
		temp += min(atype, btype);
	}
	cout << temp << endl;
}


Measured memory_bytes: 3592
import Control.Monad
import Data.List

main = do
    n <- readLn
    ss <- replicateM n getLine
    let ab = sum $ map  (length . (filter ("AB" `isPrefixOf`)) . tails) ss
        a = length $ filter (\x -> last x == 'A' && head x /= 'B') ss
        b = length $ filter (\x -> last x /= 'A' && head x == 'B') ss
        ba = length $ filter (\x -> last x == 'A' && head x == 'B') ss
        ans | ba == 0 = ab + min a b
            | a == 0 && b == 0 = ab + ba - 1
            | otherwise = ab + ba + min a b
    print ans

Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,k;
	cin >> n >> k;
	int x[n];
	REP(i,n) cin >> x[i];
	int ans = 0;
	REP(i,n){
		if(x[i] < k - x[i]) ans += 2 * x[i];
		else ans += 2 * (k - x[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256