akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))

if len(set(v)) == 1:
    print(n//2)
else:

    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    o = c1.most_common(2)
    e = c2.most_common(2)
    o.append((0,0))
    e.append((0,0))
    if o[0][0] == e[0][0]:
        print(min(n-o[1][1]-e[0][1],n-o[0][1]-e[1][1]))
    else:
        print(n-o[0][1]-e[0][1])

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=1e4+10;
int dp[maxn],a[maxn],b[maxn];
int main()
{
    int h,n;
    cin>>h>>n;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    for(int i=1;i<maxn;i++) dp[i]=1e9;
    for(int i=0;i<n;i++){
        for(int j=a[i];j<maxn;j++){
            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    int ans=1e9;
    for(int i=h;i<maxn;i++){
        ans=min(ans,dp[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
__int128 LIM;
#define F first
#define S second
const int N = 106;
vector<int> g[N];
int md;
vector<int> mu;
int pa[N];
int dm[N];
void far(int u,int p = 0,int d = 0)
{
    if (d == md) {
        mu.push_back(u);
    } else if (d > md) {
        md = d;
        mu = {u};
    }
    pa[u] = p;
    for (int v : g[u]) if (v != p) {
        far(v,u,d+1);
    }
}
void solve(int u,int p = 0,int d = 0)
{
    int deg = 0;
    for (int v : g[u]) if (v != p) {
        solve(v,u,d+1);
        ++deg;
    }
    dm[d] = max(dm[d], deg);
}
pii get_dia()
{
    mu = {};
    md = 0;
    far(1);
    int a = mu[0];
    mu = {};
    md = 0;
    far(a);
    int b = mu[0];
    return pii(a,b);
}
ll solve_even(int mi,int mj,int w)
{
    memset(dm,0,sizeof(dm));
    solve(mi,mj);
    solve(mj,mi);
    ll ans = 2;
    for (int i = 0; i < w/2-1; ++i)
        ans *= dm[i];
    return ans;
}
int main()
{
    ios::sync_with_stdio(0);
    LIM = __int128(1) << 124;
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int a,b;
    tie(a,b) = get_dia();
    int w = md+1;
    ll ans;
    if (w % 2 == 0) {
        int mi = b;
        for (int i = 0; i < w/2-1; ++i)
            mi = pa[mi];
        int mj = pa[mi];
        ans = solve_even(mi,mj,w);
    } else {
        int mi = b;
        for (int i = 0; i < w/2; ++i)
            mi = pa[mi];
        memset(dm,0,sizeof(dm));
        solve(mi);
        ans = 1;
        for (int i = 0; i < w/2; ++i)
            ans *= dm[i];
        for (int u : g[mi])
            ans = min(ans, solve_even(mi,u,w+1));
    }
    cout << (w + 1) / 2 << ' ' << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int s = 0;
    int n = stoi(n_s);

    for(int i = 0; i < n_s.length(); i++) {
        s += n_s[i] - '0';
    }
    cout << (n%s==0?"Yes":"No") << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      
      String s = sc.nextLine();
      
      if(s.charAt(0) != 'A')
         System.out.println("WA");
      else if(Character.isUpperCase(s.charAt(1)) || Character.isUpperCase(s.charAt(s.length()-1)))
         System.out.println("WA");
      else {
         int count = 0;
         for(int i = 2; i < s.length(); i++) {
            if(Character.isUpperCase(s.charAt(i)) && count == 1) {
               System.out.println("WA");
               System.exit(0);
            }
            if(s.charAt(i) == 'C')
               count++;  
         }
         if(count != 1)  
            System.out.println("WA");
         else 
            System.out.println("AC");
      }
   }
}

Measured memory_bytes: 25172
#include <iostream>

using namespace std;

int main(){
    int n, a, b, c, d, change;
    cin >> n;
    a = n / 100;
    b = n - (a * 100);
    c = b / 10;
    d = b - (c * 10);

    if(a == 9){
        a = 1;
    }else{
        a = 9;
    }
    if(c == 9){
        c = 1;
    }else{
        c = 9;
    }
    if(d == 9){
        d = 1;
    }else{
        d = 9;
    }
    change = a * 100 + c * 10 + d * 1;
    cout << change << endl;

}

Measured memory_bytes: 256
using System;
using static System.Console;

namespace abc174
{
    class Program
    {
        static void Main()
        {
            var nd = ReadLine().Split(' ');
            var n = int.Parse(nd[0]);
            var d = long.Parse(nd[1]);
            d *= d;
            var count = 0;
            for (var i = 0; i < n; ++i)
            {
                var xy = ReadLine().Split(' ');
                var x = long.Parse(xy[0]);
                var y = long.Parse(xy[1]);
                if (x * x + y * y <= d)
                {
                    ++count;
                }
            }
            WriteLine(count);
        }
    }
}


Measured memory_bytes: 40680
N,K,C= map(int,input().split())
S = input()
T = [n for n, v in enumerate(S) if v == "o"]

a,b=[T[0]],[T[-1]]

for i in range(len(T)):
  if len(a)!=K:
    if T[i]-a[-1]>C:
      a.append(T[i])
  if len(b)!=K:
    if b[-1]-T[-i-1]>C:
      b.append(T[-i-1])
      
for i in range(K):
  if a[i]==b[-i-1]:
    print(a[i]+1)
  

Measured memory_bytes: 69756
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
	int n; 
	cin >> n; 
	int cord[n];
	int ans[101];
	for(int i = 1; i < 101; i++) {
		ans[i] = 0;
	}
	for(int i = 0; i < n; i++) {
		cin >> cord[i];
	}
	for(int i = 0; i < n; i++) {
		for(int j = 1; j < 101; j++) {
			ans[j] += pow((cord[i] - j), 2);
		}
	}
	int min = 1000000000;
	for(int i = 1; i < 101; i++) {
		if(ans[i] < min) min = ans[i];
	}
	cout << min << "\n";
	return 0;
}

Measured memory_bytes: 256
# 任意の位置 i について、
# S[j] (j < i) が黒の個数 + S[j] (j >= i) が白の個数
# の最小値が求める答え
# dp[i]を i 番目までの白の個数とすると、
# min { i - dp[i] + dp[N] - dp[i] } ( i in 0 .. N)

N = gets.to_i
S = gets.chomp
dp = Array.new(N + 1, 0)
N.times do |i|
  dp[i + 1] = dp[i] + (S[i] == '.' ? 1 : 0)
end
puts (0 .. N).map{|i| dp[N] - 2 * dp[i] + i }.min


Measured memory_bytes: 5368
from collections import Counter
N = int(input())
S = [str(input()) for _ in range(N)]
hoge = Counter(S)
hoge = sorted(hoge.items(), key=lambda x: (-x[1], x[0]))
now = hoge[0][1]
for k, v in hoge:
    if now == v:
        print(k)
    else:
        break


Measured memory_bytes: 60832
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

#define yes cout << "YES\n"
#define no cout << "NO\n"
#define YN(x) cout << ((x) ? "YES\n" : "NO\n")

int n, cnt[2];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        ++cnt[a&1];
    }
    YN(!(cnt[1]&1));
}

Measured memory_bytes: 256
import sys

def integral(n):

    sumnum = 0

    for i in range(1,601 - n):
        if i % n == 0:
            sumnum += i * i * n

    return sumnum

if __name__ == '__main__':

    nums = []

    for n in sys.stdin:
        if n == "\n":
            break
        else :
            nums.append(int(n))

    for n in nums:
        print(integral(n))

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

int main()
{
    long n, a, b;
    cin >> n;
    cin >> a;
    cin >> b;

    if(a == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        long result;
        result = n / (a + b) * a;
        long mod = n % (a + b);
        result += mod > a ? a : mod;

        cout << result << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}


int main()
{

	
	string str;
	cin >> str;

	int queryCount;
	cin >> queryCount;

	int mode;
	int f;
	char c;

	int rev = 1;//1が正方向　2が逆方向

	string head = "";
	string last = "";


	for (int i = 0; i < queryCount; i++) {
		cin >> mode;
		
		if (mode == 2) {
			cin >> f;
			cin >> c;

			if (f == rev) {
				head.push_back(c);
			}
			else {
				last.push_back(c);
			}


		}
		else {

			if (rev == 1)rev = 2;
			else rev = 1;

		}
	}

	if (rev == 1) {

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

		cout << head << str << last << endl;
	}
	else {

		reverse(last.begin(), last.end());
		reverse(str.begin(), str.end());

		cout << last << str << head << endl;

	}


	
	
	


	return 0;

}



Measured memory_bytes: 1088
/*
 * drish1001
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>  
#include <iostream> 
using namespace __gnu_pbds; 
using namespace std;
#define     pb                 push_back
#define     mp                 make_pair
#define     ff                 first
#define     ss                 second
#define    MOD                1000000007
#define     pll                pair<ll,ll>
void        sorta(auto &v)     {sort(v.begin(),v.end());} 
void        sortd(auto &v)     {sort(v.begin(),v.end(), greater<>());} 
void        fast()            {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef        long long        ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> magic; 

//all variables and functions be1ow this ..

int main()
{
	fast();
	ll a, b, c, d;
	cin	>> a >> b >> c >> d;
	ll j = max(a*c, a*d);
	ll k = max(b*c, b*d);
	cout << max(j, k) << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>

int main(void) {

    //入力
    int A = 0;
    int B = 0;
    int M = 0;

    scanf("%d %d %d", &A, &B, &M);

    int *a = NULL;
    a = (int*)malloc(sizeof(int)*A);
    for(int ii = 0; ii < A; ii++) {
        scanf("%d", &a[ii]);
    }
    
    int *b = NULL;
    b = (int*)malloc(sizeof(int)*B);
    for(int ii = 0; ii < B; ii++) {
        scanf("%d", &b[ii]);
    }

    int *x = NULL;
    int *y = NULL;
    int *c = NULL;

    x = (int*)malloc(sizeof(int)*M);
    y = (int*)malloc(sizeof(int)*M);
    c = (int*)malloc(sizeof(int)*M);

    for(int ii = 0; ii < M; ii++) {
        scanf("%d %d %d", &x[ii], &y[ii], &c[ii]);
    }

    //割引の方の最小値
    int waribikiSum = 300000;
    for(int ii = 0; ii < M; ii++) {
        int tmpSum = 0;

        tmpSum = a[ x[ii] - 1 ] + b[ y[ii] - 1 ] - c[ii];

        if( waribikiSum > tmpSum ) {
            waribikiSum = tmpSum;
        }

    }

    int minA = 300000;
    for( int ii = 0; ii < A; ii++ ) {
        if( minA > a[ii] ) {
            minA = a[ii];
        }
    }

    int minB = 300000;
    for( int ii = 0; ii < B; ii++ ) {
        if( minB > b[ii] ) {
            minB = b[ii];
        }
    }

    if( (minA + minB) < waribikiSum ) {
        std::cout << (minA + minB);
    }
    else {
        std::cout << waribikiSum;
    }

    if(c != NULL) {
        free(c);
    }

    if(y != NULL) {
        free(y);
    }

    if(x != NULL) {
        free(x);
    }

    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
const int N=55;
struct each{
	long long v,w,id;
	bool operator < (each k){
		return 1LL*w*k.v>v*k.w;
	}
}a[N];
long long ans,f[M];
int n,m,d,mw,li,now,v[N],nex[N],head[N];
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
void dfs(int x){
	for(int i=head[x];i;i=nex[i]){
		dfs(v[i]),a[x].v+=a[v[i]].v;
		a[x].w+=a[v[i]].w;
	}
}
void insert(long long w,long long v){
	for(int i=mw;i>=w;i--)
		f[i]=min(f[i],f[i-w]+v);
}
void move(each k){
	int x=li;
	for(int i=0;(1<<i)<=x;i++){
		insert(k.w*(1<<i),k.v*(1<<i));
		x-=1<<i;
	}
	if(x)	insert(k.w*x,k.v*x);
}
int main(){
	//freopen("1.out","w",stdout);
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&m,&d);
	scanf("%lld",&a[1].v);
	a[1].w=1,a[1].id=1;
	for(int i=2,x;i<=n;i++){
		scanf("%lld%d",&a[i].v,&x);
		addedges(x,i),a[i].w=1;
	}
	dfs(1),li=min(n,d),mw=n*n*n;
	memset(f,23,sizeof(f)),f[0]=0;
	for(int i=1;i<=n;i++)	move(a[i]);

	sort(a+1,a+n+1);
	while(a[n].id!=1)	--n;
	for(int i=0;i<=mw;i++){
		if(f[i]>m)	continue;
		int v=f[i],w=i;
		for(int j=1;j<n;j++){
			int k=min(1LL*d-li,(m-v)/a[j].v);
			w+=k*a[j].w,v+=k*a[j].v;
		}
		int k=(m-v)/a[n].v;
		ans=max(ans,w+k*a[n].w);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
#define ll long long
#define pii pair<int,int>
int N, K;
int main(){
    cin >> N >> K;
    cout << ((N + 1) / 2 >= K ? "YES" : "NO") << endl;
    return 0;
}

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

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  char ans;
  while(true) {
    c -= b;
    if(c <= 0) {
      ans = 't';
      break;
    }
    a -= d;
    if(a <= 0) {
      ans = 'a';
      break;
    }
  }
  if(ans == 't') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }.sorted()

    val max = aa.last()
    val target = max/2

    val idx = upperBound(aa.toIntArray(), target, 0, n-1)

    if (idx < 0) {
        println("$max ${aa[0]}")
        return
    }

    if (aa[idx] == target) {
        println("$max $target")
        return
    }

    val lDiff = target - aa[idx]
    val uDiff = target - (max - aa[idx+1])

    if (lDiff <= uDiff) {
        println("$max ${aa[idx]}")
    } else {
        println("$max ${aa[idx+1]}")
    }
}

fun upperBound(list: IntArray, key: Int, start: Int, end: Int): Int {
    var minIdx = start-1
    var maxIdx = end+1

    while (maxIdx - minIdx > 1) {
        val mid = minIdx + (maxIdx - minIdx)/2
        if (list[mid] > key) {
            maxIdx = mid
        } else {
            minIdx = mid
        }
    }

    return minIdx
}

Measured memory_bytes: 59196
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int s, w;
	cin >> s >> w;
	cout << (w >= s ? "unsafe" : "safe") << endl;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;
    Vl A(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> A[i];
        --A[i];
    }

    Vl ans(N);
    for (int i = 0; i < N - 1; i++) {
        ++ans[A[i]];
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> a(n);
  
  rep(i, n) cin >> a[i];
  
  vector<int> at(n);
  rep(i, n) {
    at[i] = a[i];
  }
  sort(at.begin(), at.end());
  reverse(at.begin(), at.end());
  
  int a_first = at[0];
  int a_last = at[1];
  int ans = 0;
  
  rep(i, n) {
    if(a_first == a[i]) {
      cout << a_last << endl;
    }
    else cout << a_first << endl;
  }
  return 0;
}

Measured memory_bytes: 4756
def main():
    MOD = 10**9 + 7
    r1, c1, r2, c2 = (int(i) for i in input().split())
    m = r2 + c2 + 3
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    ans += (fac[r2+1+c2+1]*finv[r2+1]*finv[c2+1] - 1) % MOD
    ans -= (fac[r2+1+c1]*finv[r2+1]*finv[c1] - 1) % MOD
    ans -= (fac[r1+c2+1]*finv[r1]*finv[c2+1] - 1) % MOD
    ans += (fac[r1+c1]*finv[r1]*finv[c1] - 1) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"

#define PB push_back
#define MP make_pair
#define F first
#define S second

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

#define MAX(a,b,c) (max(max(a,b),c))
#define MIN(a,b,c) (min(min(a,b),c))

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<int>::iterator vit;

const int N=1e9+7;

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int sq=sqrt(n);
    while(n%sq!=0) sq--;
    cout<<sq+n/sq-2;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define N (300000+1000)
using namespace std;

struct Edge{int to,next;}edge[N<<1];
int head[N],num_edge,Maxdep[N],size[N],sum,n,u,v;
long long ans;
char s[N];

void add(int u,int v)
{
	edge[++num_edge].to=v;
	edge[num_edge].next=head[u];
	head[u]=num_edge;
}

void Dfs1(int x,int fa)
{
	size[x]=(s[x]=='1');
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa)
		{
			Dfs1(edge[i].to,x);
			size[x]+=size[edge[i].to];
			Maxdep[x]=max(Maxdep[x],Maxdep[edge[i].to]+1);
		}
}

void Dfs2(int x,int fa,int maxdis)
{
	int l=(s[x]=='1'?0:(1<<30)), r, max1=maxdis, max2=0;
	if (sum-size[x]) l=min(l,maxdis);
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa)
		{
			if (Maxdep[edge[i].to]+1>max2) max2=Maxdep[edge[i].to]+1;
			if (max2>max1) swap(max1,max2);
			if (size[edge[i].to]) l=min(l,Maxdep[edge[i].to]+1);
		}
	if (max1==max2) r=max2-1;
	else if (max1==max2+1) r=max2;
	else r=max2+1;
	if (l<=r) ans+=r-l+1;
	for (int i=head[x]; i; i=edge[i].next)
		if (edge[i].to!=fa)
		{
			if (Maxdep[edge[i].to]+1!=max1) Dfs2(edge[i].to,x,max1+1);
			else Dfs2(edge[i].to,x,max2+1);
		}
}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<n; ++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	scanf("%s",s+1);
	for (int i=1; i<=n; i++)  sum+=(s[i]=='1');
	Dfs1(1,0); Dfs2(1,0,0);
	printf("%lld\n",ans+1);
}

Measured memory_bytes: 17408
from collections import deque

h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0

for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            continue
        else:
            dist=[[inf for _ in range(w)] for _ in range(h)]
            dist[i][j]=0
            queue=deque([(i,j)])
            while queue:
                si,sj=queue.popleft()
                for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                    if 0<=ni<=h-1 and 0<=nj<=w-1 and S[ni][nj] != "#":
                        if dist[ni][nj] > dist[si][sj] + 1:
                            dist[ni][nj] = dist[si][sj] + 1
                            queue.append((ni, nj))
                max_dist = 0
                for ii in range(h):
                    for jj in range(w):
                        if dist[ii][jj] != inf:
                            max_dist = max(max_dist, dist[ii][jj])
                            ans = max(max_dist,ans)
print(ans)


Measured memory_bytes: 58204
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);

    vector<int> deg(5, 0);
    for (int i = 1; i <= 3; i++) {
        int x, y;
        cin >> x >> y;
        deg[x]++, deg[y]++;
    }

    map<int, int> cnt;
    for (int i = 1; i <= 4; i++) {
        cnt[deg[i]]++;
    }

    if(cnt[1] = 2 and cnt[2] == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> data(N);
  for (int i=0; i < N;i++){
    cin >> data.at(i);
    }//for input
  
  int count = 0;  
  bool p = true;
  
  while (p){
  for (int i = 0; i < N; i++){
    if (data.at(i) % 2 == 0){
      data.at(i) /= 2;
    } //if
    else {
      p = false;
      }//else
   }//for i
    count++;
  }//while
  cout << count - 1 << endl;
}//main

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

int main () {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; i++) {
        cin >> a.at(i);
    }
    for (int i = 0; i < W + 2; i++) {
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < a.size(); i++) {
        cout << "#" << a.at(i) << "#" << endl;
    }
    for (int i = 0; i < W + 2; i++) {
        cout << "#";
    }
    cout << endl;
}

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

using namespace std;

bool prime[1000001],dp[1000001];

void make_prime(){
  for(int i=0;i<1000001;i++) prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=2;i<=1000000;i++){
    if(prime[i]){
      for(int j=i*2;j<1000001;j+=i){
          prime[j]=false;
        }
    }
  }
}

int n,x;
vector<int> price;

int main(){
  make_prime();

  while(1){
    cin>>n>>x;
    if(!n && !x)break;
    while(price.size())price.pop_back();
    for(int i=0;i<1000001;i++){
      dp[i]=false;
    }
    for(int i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      price.push_back(tmp);
      dp[tmp]=true;
    }

    sort(price.begin(),price.end());

    for(int i=0;i<n;i++){
      for(int j=0;j+price[i]<=x;j++){
        if(dp[j]) dp[j+price[i]]=true;
      }
    }

    int ans=0;

    for(int i=x;i>=1;i--){
      if(dp[i] && prime[i]){
        ans=i; break;
      }
    }

    if(ans==0){
      cout<<"NA"<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  int cnt = 0;
  rep(i, N) {
    if ((double)A[i] >= (double)sum/(4.0*M)) cnt++;
   }

   if (cnt >= M) cout << "Yes" << endl;
   else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int a[999]={};
    int N,K;
    cin>>N>>K;
    for(int z=0;z<N;z++){
        cin>>a[z];
    }
    sort(a,a+N);
    N=0;
    for(int z=0;z<K;z++){
        N+=a[z];
    }
    cout<<N<<endl;
}


Measured memory_bytes: 3540
#include <stdio.h>
#include <string.h>
int main(void)
{
	char s[51],a[51];
	scanf("%s",s);
	int i=strlen(s)-8;
	strncpy(a,s,i);
	a[i]='\0';
	printf("%s\n",a);
	return 0;
}

Measured memory_bytes: 128
Q = int(input())

is_prime = [True] * 100010
for i in range(100010):
    if i <= 1:
        is_prime[i] = False
        continue

    if is_prime[i]:
        for j in range(2*i,100010,i):
            is_prime[j] = False

is_2017like_prime = [False] * 100010
for i in range(1,100010,2):
    if is_prime[i] & is_prime[(i+1)//2]:
        is_2017like_prime[i] = True

cumsum = [0]
for a in is_2017like_prime[1:]:
    cumsum.append(cumsum[-1] + a)

for _ in range(Q):
    l, r = map(int,input().split())
    print(cumsum[r]-cumsum[l-1])

Measured memory_bytes: 82076
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (m, d) = (v[0], v[1]);
    let mut ans = 0;
    for i in 22..d + 1 {
        let d1 = i % 10;
        let d2 = i / 10;
        if d1 * d2 <= m && d1 >= 2 && d2 >= 2 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;
const int mod=1e9+7;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e3+100;

ll a[maxn];
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    if(n>=10)
        cout<<k;
    else
        cout<<k+1000-100*n;
    //cout<<tot<<endl;
    return 0;
}
/*

ll qpow(ll x,ll y){
    ll sum=1;
    while(y){
        if(y&1)
            sum=sum*x%mod;
        y/=2;
        x=x*x%mod;
    }
    return sum;
}
ll C(ll n,ll m){
    ll low=min(m,n-m);
    ll H=1,L=1;
    for(int i=n-low+1;i<=n;i++)
        H=H*i%mod;
    for(int i=1;i<=low;i++)
        L=L*i%mod;
    return H*qpow(L,mod-2)%mod;
}
*/



Measured memory_bytes: 256
surface = gets.split.map(&:to_i)
commands = gets.chomp.chars.map(&:to_sym)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key do |k|
  th[k] = throw[k].map(&:pred)
end

dice = [*0..5]
commands.each do |c|
  next_dice = Array.new(6, 0)
  dice.each_with_index do |d, i|
    next_dice[th[c][i]] = d
  end
  dice = next_dice
end
puts surface[dice[0]]




Measured memory_bytes: 6872
H, W = map(int, input().split())

S = ["."*(W+2)]
ans = 'Yes'
for i in range(H):
    s = input()
    S.append('.'+s+'.')

S.append('.'*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '#':
            if S[i][j+1] == '#' or S[i][j-1] == '#' or S[i+1][j] == '#' or S[i-1][j] == '#':
                continue
            else:
                ans = 'No'
                break

print(ans)


Measured memory_bytes: 3064
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int X = sc.nextInt();
      int Y = sc.nextInt();
      int Z = sc.nextInt();
      int buffer;

      buffer = X;
      X = Y;
      Y = buffer;
      buffer = X;
      X = Z;
      Z = buffer;

      System.out.println(X + " " + Y + " " + Z);
      
      
      

   }
 }


Measured memory_bytes: 39356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());
            List<long> v = Console.ReadLine().Split().Select(s => long.Parse(s)).OrderBy(x => x).ToList();
            double max_value = v[0];
            foreach (long item in v)
	        {
                max_value = (max_value + item) / 2;
	        }
            Console.WriteLine(max_value);
            Console.Out.Flush();
        }
    }
}


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

int main(){
  int k ,x;
  cin >> k >> x;
  if(500*k<x)cout << "No" <<endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;

int main(){
    int n, k; cin >> n >> k;
    vector<P> pos;
    vector<int> xarr, yarr;
    rep(i,n){
        int x, y; cin >> x >> y;
        pos.push_back(P(x,y));
        xarr.push_back(x);
        yarr.push_back(y);
    }
    sort(ALL(xarr));
    sort(ALL(yarr));
    ll ans =  1LL * (xarr[n-1] - xarr[0]) * (yarr[n-1] - yarr[0]);
    for(int xi = 0; xi < n; xi++){
        for(int xj = xi+1; xj < n; xj++){
            for(int yi = 0; yi < n; yi++){
                for(int yj = yi+1; yj < n; yj++){
                    int cnt = 0;
                    ll lx = xarr[xi], rx = xarr[xj];
                    ll by = yarr[yi], uy = yarr[yj];
                    rep(i,n){
                        if(lx <= pos[i].first && pos[i].first <= rx && by <= pos[i].second && pos[i].second <= uy) cnt++;
                    }
                    if(cnt >= k) ans = min(ans, 1LL * (rx-lx)*(uy-by));
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = list(input().split())
for i in range(n):
    s[i] = int(s[i])

s.sort()


m = n//2 -1
#print(s)
ans = 0
if s[m+1] == s[m]:
    ans = 0
else:
    ans = s[m+1]-s[m]

print(ans)
#print(m)


Measured memory_bytes: 11356
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	a := getNextInt64(scanner)
	b := getNextInt64(scanner)
	c := getNextInt64(scanner)
	if a%2&b%2&c%2 == 0 {
		fmt.Println(0)
		return
	}
	ans := a * b
	if ans > b*c {
		ans = b * c
	}
	if ans > a*c {
		ans = a * c
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    string S;
    cin >> S;
    vector<ll> V(S.size()+1);
    S = S + "1";
    ll count = 1;
    REP(i,S.size()){
        if(i != 0){if(S[i-1] == S[i]){
            count++;
        }else{
            if(S[i-1] == '<'){
                for(ll m = count;m > -1;m--){
                V[i-count + m] = max(m,V[i-count + m]);
                }
            }else{
                for(ll m = 0;m < count +1;m++){
                V[i-m] = max(m,V[i- m]);
                }
            }
            count = 1;
        }
    }
    }
    ll sum = 0;
    REP(i,S.size())sum += V[i];
    cout <<sum<< "\n";
}

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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int m, d;
	cin >> m  >> d;
	int ans = 0;
	for(int i=1; i<=m; i++) {
		for(int j=20; j<=d; j++) {
			if(j%10 >= 2 && (j%10)*(j/10) == i)
				ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  string S, T; cin >> S >> T;
  int ans = 0;
  rep(i, S.size()) {
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 3912
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

long long pow(long long a, long long p){
	if(p == 0) return 1;
	long long res = pow(a, p/2);
	res *= res;
	if(p%2 == 1) res *= a;
	return res;
}

int main(){
	long long N, A;
	while(cin >> N >> A){
		long long res = N;
		long long s = sqrt(N)+1;
		long long seg = 2;
		while(s > 1){
			while(pow(s, seg) > N) --s;
			long long cur = pow(s, seg);
			long long sum = s * seg;
			while(cur < N){
				cur /= s;
				cur *= s+1;
				++sum;
			}
			res = min(res, sum+A*(seg-1));
			++seg;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d))
// priority_queue<int,vector<int>,greater<int>>
int solve(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = INF;
  vector<int>sum(n + 1);
  rep(i,n){
    if(s[i] == '#')sum[i + 1] = sum[i] + 1;
    else sum[i + 1] = sum[i];
  }
  rep(i,n + 1)ans = min(ans,sum[i] + n - i - (sum[n] - sum[i]));
  cout << ans << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

int A, B;

int main(){
  cin >> A >> B;
  if (B % A == 0) cout << A + B << endl;
  else cout << B - A << endl;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long a, b; scan(a, b);
      if( a + b >= 10 ) puts("error");
      else printf("%ld\n", a + b);
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
int main(){
    int n;
    cin >> n;
    map<int, int> M;
    rep(i, n-1){
        int A;
        cin >> A;
        A--;
        M[A]++;
    }
    rep(i, n){
        cout << M[i] << endl;
    }
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	int l[n];
	for(int i=0;i<n;i++){
		cin>>l[i];
}
int ans=0;
sort(l,l+n);
for(int i=0;i<n;i++){
	for(int j=i+1;j<n;j++){
		for(int k=j+1;k<n;k++){
			if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k])
			continue;
			if(l[i]+l[j]>l[k])
			ans++;
}
}
}
cout<<ans;
}


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

int main() {
	int f = 0,c = 0;
	int A, B;
	char S[10];
	cin >> A >> B;
	cin >> S;
	int i=0;
	for (i = 0; i <= A + B; i++) {
			if (S[A] != '-') {
				f++;
			}
			if (typeid(S[i])==typeid(i)) {
				f++;
			}
			if (S[i] == '-') {
				c++;
			}
	}
	if (c == 1) {
		if (f == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
}

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

const int MAX_N = int(1e6);
int N, a[MAX_N+10];
int res, m[MAX_N+10];

int main()
{
    std::cin>>N;
    for (int i = 0; i < N; ++i)
        scanf("%d", a+i);

    res = 0;
    for (int i = 0; i < N; ++i)
    {
        int l = 0, r = res+1;
        while (r-l>1)
        {
            int mid = l+r>>1;
            if (a[m[mid]] < a[i])
                l = mid;
            else
                r = mid;
        }

        if (res < l+1)
        {
            res = l+1;
            m[l+1] = i;
        }

        if (a[m[l+1]] > a[i])
            m[l+1] = i;

        //std::cout<<i<<") ";
        //for (int j = 1; j <= res; ++j) std::cout<<m[j]<<" ";
        //std::cout<<"res = "<<res<<"\n";
    }

    std::cout<<res<<"\n";
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
const int N = 25005;
const int K = 405;
const int mod = 1000000007;
inline int qp(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod;
		b >>= 1;
	}
	return res;
}
int n, k, m, b[N], vis[K], f[N][K], g[N][K], F[N], G[N];
int main() {
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
	int miaow = 0;
	int ans = 1ll * qp(k, n - m) * (n - m + 1) % mod;
	for (int i = 1; i <= m - k + 1; i++) {
		for (int j = 1; j <= k; j++) vis[j] = 0;
		int bad = 0;
		for (int j = i; j <= i + k - 1; j++) {
			if (vis[b[j]]) {
				bad = 1;
				break;
			}
			vis[b[j]] = 1;
		}
		if (!bad) {
			miaow = 1;
			break;
		}
	}
	if (miaow) {
		printf("%d\n", ans);
		return 0;
	}
	int fl = 0;
	for (int i = 1; i <= k; i++) vis[i] = 0;
	for (int i = 1; i <= m; i++) {
		if (vis[b[i]]) {
			fl = i - 1;
			break;
		}
		vis[b[i]] = 1;
	}
	if (!fl) {
		f[1][1] = k;
		g[1][1] = (m == 1) * k;
		for (int i = 2; i <= n; i++) {
			int psf = 0, psg = 0;
			for (int j = k - 1; j >= 1; j--) {
				psf = (psf + f[i - 1][j]) % mod;
				psg = (psg + g[i - 1][j]) % mod;
				f[i][j] = (psf + 1ll * f[i - 1][j - 1] * (k - j + 1)) % mod;
				g[i][j] = (psg + 1ll * g[i - 1][j - 1] * (k - j + 1)) % mod;
				if (j >= m) g[i][j] = (g[i][j] + f[i][j]) % mod;
			}
		}
		int sum = 0;
		for (int j = 1; j < k; j++) sum = (sum + g[n][j]) % mod;
		int prd = 1;
		for (int j = k; j >= k - m + 1; j--) prd = 1ll * prd * j % mod;
		prd = qp(prd, mod - 2);
		sum = 1ll * sum * prd % mod;
		ans = (ans - sum + mod) % mod;
		printf("%d\n", ans);
		return 0;
	}
	int fr = 0;
	for (int i = 1; i <= k; i++) vis[i] = 0;
	for (int i = m; i >= 1; i--) {
		if (vis[b[i]]) {
			fr = m - i;
			break;
		}
		vis[b[i]] = 1;
	}
	f[0][fl] = 1;
	g[0][fr] = 1;
	F[0] = G[0] = 1;
	for (int i = 1; i <= n - m; i++) {
		int psf = 0, psg = 0;
		for (int j = k - 1; j >= 1; j--) {
			psf = (psf + f[i - 1][j]) % mod;
			psg = (psg + g[i - 1][j]) % mod;
			f[i][j] = (psf + 1ll * f[i - 1][j - 1] * (k - j + 1)) % mod;
			g[i][j] = (psg + 1ll * g[i - 1][j - 1] * (k - j + 1)) % mod;
			F[i] = (F[i] + f[i][j]) % mod;
			G[i] = (G[i] + g[i][j]) % mod;
		}
	}
	int sum = 0;
	for (int i = 0; i <= n - m; i++) sum = (sum + 1ll * F[i] * G[n - m - i]) % mod;
	ans = (ans - sum + mod) % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 82960
package main

import(
    "fmt"
)

func main() {
    var n int
    var a[222222] int
    var count[222222] int
    fmt.Scan(&n) 

    for i := 0; i < n - 1; i++{
        fmt.Scan(&a[i])
        count[a[i]] += 1        
    }
    for i := 1; i <= n ; i++{
        fmt.Println(count[i])
    }
}
    

Measured memory_bytes: 8212
<?php
  fscanf(STDIN, "%d %d", $x, $n);

  if ($n == 0) {
    echo $x;
    return;
  }

  $nums = explode(' ', str_replace("\n", '', fgets(STDIN)));
  $ans;

  $i = 0;
  while (1) {
    if (array_search($x - $i, $nums) === false) {
      $ans = $x - $i;
      break;
    } else if (array_search($x + $i, $nums) === false) {
      $ans = $x + $i;
      break;
    } else {
      $i++;
    }
  }

  echo $ans;

Measured memory_bytes: 16180
n = int(input())
t, a = list(map(int, input().split()))

h = list(map(int, input().split()))
#print(h)

tmp_dif = [abs(a- (t - h[i]*0.006)) for i in range(len(h))]
#print(tmp_dif)

print(tmp_dif.index(min(tmp_dif))+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        cout << (n * (n - 1)) / 2 << '\n';
    }
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  
  if(a-1+2*k > b){
    for (int i=a;i<=b;i++) cout << i << endl;
  }
  else{
    for(int i=a;i<a+k;i++) cout << i << endl;
    for(int i=b-k+1;i<=b;i++) cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Problem Code: abc176_e

#include <bits/stdc++.h>

using namespace std;

long long D(long long H, long long W, long long M, vector<long long>& h, vector<long long>& w) {
	long long max_bombs, r, c;
	set<long long> seen;
	vector<long long> row(H), col(W);
	
	for (long long i = 0; i < M; i++) {
		row[h[i]]++;
		col[w[i]]++;
	}
	
	r = distance(row.begin(), max_element(row.begin(), row.end()));
	max_bombs = row[r];
	for (long long i = 0; i < M; i++)
		if (h[i] == r)
			seen.insert(w[i]);
	
	for (c = 0; c < W; c++) {
		long long bombs = row[r] + col[c] - seen.count(c);
		max_bombs = max(bombs, max_bombs);
	}
	
	seen.clear();
	c = distance(col.begin(), max_element(col.begin(), col.end()));
	max_bombs = max(max_bombs, col[c]);
	for (long long i = 0; i < M; i++)
		if (w[i] == c)
			seen.insert(h[i]);
	
	for (r = 0; r < H; r++) {
		long long bombs = row[r] + col[c] - seen.count(r);
		max_bombs = max(bombs, max_bombs);
	}
	
	return max_bombs;
}

int main() {
	long long H, W, M;
	cin >> H >> W >> M;
	vector<long long> h(M), w(M);
	for (long long i = 0; i < M; i++) {
		cin >> h[i] >> w[i];
		--h[i], --w[i];
	}
	cout << D(H, W, M, h, w);
	return 0;
}

Measured memory_bytes: 26728
n, m, l = list(map(int, input().split()))

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

answer = []
for i in range(n):
    calcSum = []
    for j in range(l):
        calc = []
        for k in range(m):
            calc.append(a[i][k] * b[k][j])
        calcSum.append(sum(calc))

    answer.append(calcSum)

[print(*answer[i]) for i in range(len(answer))]


Measured memory_bytes: 7000
L=[[1,31],[2,28],[3,31],[4,30],[5,31],[6,30],[7,31],[8,31],[9,30],[10,31],[11,30],[12,31]]

M1,D1=map(int,input().split())
M2,D2=map(int,input().split())

print([0,1][[M1,D1] in L])

Measured memory_bytes: 3064