akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] D;
	static int[][] v;
	static int M;
	static int K;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		M = sc.nextInt();
		K = sc.nextInt();

		D = new int[N];
		int M2Dnum[] = new int[M];
		v = new int[N][K];

		Arrays.fill(D, -1);
		for(int i = 0; i < M; i++) {
			int d = sc.nextInt()-1;
			D[d] = i;
			M2Dnum[i] = d;
		}

		for(int i = 0; i < N; i++) {
			for(int j = 0; j < K; j++) {
				v[i][j] = sc.nextInt()-1;
			}
		}

		//idxに示される状態になるための最小手数
		int[] minDist = new int[1 << M];
		Arrays.fill(minDist, Integer.MAX_VALUE);
		minDist[(1<<M)-1] =0;

		Queue<Integer> q= new ArrayDeque<Integer>();
		q.add((1<<M)-1);

		while(!q.isEmpty()) {
			int now = q.poll();


			//各指示
			for(int j = 0; j <K ; j++) {
				//or演算用
				int nextState = 0;
				//指示ごとに暗い部屋の次の行き先を調べる
				for(int i = 0; i < M; i++) {
					if((now  & (1 << D[M2Dnum[i]])) != 0 && D[v[M2Dnum[i]][j]] != -1) {
						nextState |= (1 <<  D[v[M2Dnum[i]][j]]);
					}
				}
				if(minDist[nextState] > minDist[now]+1) {
				minDist[nextState] = minDist[now]+1;
				q.add(nextState);
				}
			}
		}
		System.out.println(minDist[0]);
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}
}



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

typedef long long ll;
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
int main(){
  ll n;
  cin >> n;
   ll k = pow(n,0.5);
   //cout << k ;
   ll A = 1;
   ll B  = 1;
   for(int i=1;i<=k+1;++i){
	   if(n%i==0){
		 A = i;
		 B = n/i;   
	   }
   }
   
   ll ans = A - 1 + B - 1;
   cout << ans;
}  
















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e18
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e5 + 5;
const ll MOD = 1e9 + 7;
ll dp[500][500];

int main()
{
    fastRead;
    int n;
    cin>>n;
    vector<ll>vec(n+1), sum(n+1);
    for(int i =1 ; i <=n; i++ ) cin>>vec[i], sum[i] = (sum[i-1]+ vec[i]);
    
    for(int i = 1; i <=n ; i++ ) {
        for(int j =1 ; j <=n ; j++ ) dp[i][j] = INF;
    }
    
    for(int i =1 ; i <=n ; i++ ) dp[1][i] = vec[i];
    
    
    for(int i = 2; i <=n ; i++ ) {
        for(int j = 1; j + i - 1 <=n ; j++ ) {
            for(int k = 1; k < i ; k++ ) {
                
                int len1 = k, len2 = i - k;
                int frm1 = j ,frm2 = j + len1;
                
                int to = j + i -1;
                
//                cout<<i<<" -> "<<j<<" "<<i + j-1<<" -- "<<frm1<<" "<<frm1 + len1-1<<" -- "<<frm2<<" "<<len2 + frm2-1;
//                cout<<"\t--"<<dp[len1][frm1]<<" "<<dp[len2][frm2]<<" "<<sum[to] - sum[frm1-1]<<'\n';
                
                dp[i][j] = min(dp[i][j], dp[len1][frm1] + dp[len2][frm2] + sum[to] - sum[frm1-1]);
            }
        }
    }
    cout<<dp[n][1] - sum[n]<<'\n';
    return 0;
}

Measured memory_bytes: 5156
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
        Scanner scanner1 = new Scanner(System.in);
        //System.out.println("数値を入力してください。");
        //Scanner scanner2 = new Scanner(System.in);
        //System.out.println("数値を入力してください。");
        int n = scanner1.nextInt();
        int m[] = new int[n];
        int sum = 0;
        for(int i = 0;i < n;i++){
        	m[i] = scanner1.nextInt();
        	sum = sum + m[i];
        }
        
        int p = 0;
        
        for(int i = 0;i < n;i++){
        	if(sum - m[i] <= m[i]){
        		System.out.println("No");
        		p++;
        		break;
        	}
        }
        if(p == 0){
        	System.out.println("Yes");
        }	
   }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 2005;
#define sz(v) ((int)(v).size())
int n;
vector<int> gph[MAXN];
vector<int> ans;
int p[MAXN], a[MAXN], mark[MAXN], dep[MAXN];

void QUERY(int x){
	assert(x >= 0);

	ans.push_back(x);
	vector<int> pth;
	for(int j=x; j!=-1; j=p[j]) pth.push_back(j);
	reverse(pth.begin(), pth.end());
	int bmark = mark[0], bval = a[0];
	for(int j=0; j<sz(pth) - 1; j++){
		mark[pth[j]] = mark[pth[j+1]];
		a[pth[j]] = a[pth[j+1]];
	}
	mark[pth.back()] = bmark;
	a[pth.back()] = bval;
	return;
	printf("After query %d\n", x);
	for(int i=0; i<n; i++) printf("%d ", a[i]);
	puts("");
	for(int i=0; i<n; i++) printf("%d ", mark[i]);
	puts("");
}

pi dfs(int x){
	pi ret(-1e9, -1);
	if(!mark[x]) ret = max(ret, pi(dep[x], x));
	for(auto &i : gph[x]) ret = max(ret, dfs(i));
	return ret;
}

int chk[MAXN];
int main(){
	cin >> n;
	for(int i=1; i<n; i++){
		cin >> p[i];
		dep[i] = dep[p[i]] + 1;
		gph[p[i]].push_back(i);
	}
	p[0] = -1;
	for(int i=0; i<n; i++) cin >> a[i];
	int matched = 0;
	while(matched < n){
		memset(mark, 0, sizeof(mark));
		int lcnt = 0;
		int in_chain[MAXN] = {};
		vector<vector<int>> chains;
		vector<vector<int>> occupied_leaves;
		for(int i=n-1; i>=0; i--){
			if(!chk[i] && gph[i].size() == 0){
				vector<int> v;
				for(int j=i; j >= 0 && gph[j].size() <= 1; j=p[j]){
					v.push_back(j);
					in_chain[j] = chains.size() + 1;
					chk[j] = 1;
					lcnt++;
				}
				chains.push_back(v);
				occupied_leaves.emplace_back();
			}
		}
		matched += lcnt;
		while(lcnt > 0){
			if(in_chain[a[0]]){
				lcnt--;
				int c = in_chain[a[0]];
				int pos = chains[c - 1][0];
				int cnt = 0;
				for(auto &j : occupied_leaves[c-1]){
					if(dep[j] > dep[a[0]]){
						pos = p[pos];
						cnt++;
					}
				}
				mark[0] = 2;
				occupied_leaves[c-1].insert(occupied_leaves[c-1].begin() + cnt, a[0]);
				QUERY(pos);
			}
			else{
				int pos = dfs(0).second;
				mark[0] = 1;
				QUERY(pos);
			}
		}
		for(auto &i : chains){
			for(auto &j : i){
				if(j){
					gph[p[j]].erase(find(gph[p[j]].begin(), gph[p[j]].end(), j));
				}
			}
		}
	}
	for(int i=0; i<n; i++) assert(a[i] == i);
	cout << ans.size() << endl;
	for(auto &i : ans) cout << i << endl;
}


Measured memory_bytes: 640
/********************/
                    /*user -> tushar284*/
                    /******************/
#include<bits/stdc++.h>
                                                    /*********/            
using namespace std;                             /*   __   __   */
#define  f              first                    /*   @ ) ( @   */
#define  s              second                   /*     / \     */            
#define  mp             make_pair                /*  __  -  __  */
#define  loop(i,s,e)    for(int i=s;i<e;i++)     /*    ..^..    */
#define  rev(i,s,e)     for(int i=s;i>=e;i--)     /*     |     */
#define  mod            1000000007                  /*   |   */
#define  pb             push_back                      /***/
#define  start	        int main()                     
#define  fast           ios_base::sync_with_stdio(false);cin.tie(0);
#define  test           fast int t; cin>>t;while(t--)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;


start
{   
    int k,a,b;
    cin>>k>>a>>b;
    bool ok = false;
    loop(i,a,b+1)if(i%k==0)ok=true;
    if(ok)cout<<"OK";
    else cout<<"NG";
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int lis(vector<int> const& a,int n){
    int res=0;
    int inf=1000000007;
    vector<int> dp(n+1,0);
    rep(i,n){
        dp[a[i]]=dp[a[i]-1]+1;
    }
    rep1(i,n){
        if(res<dp[i])res=dp[i];
    }
    return res;
}
signed main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int leng=lis(a,n);
    int res=n-leng;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
 
inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
 
int n,m;
 
signed main()
{
	n=read();
	for ( int i=1;i<=n;i++ )
	{
		if(i%3==0||i%5==0) continue;
		m+=i;
	}
	printf("%lld\n",m);
	return 0;
}

Measured memory_bytes: 3760
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s;
ll k;
ll calc(string str){
	char ch = str[0];
	int cnt = 1, ret = 0;
	for(int i=1;i<str.size();i++){
		if(ch == str[i]) cnt++;
		else{
			ret += (cnt)/2;
			cnt = 1;
			ch = str[i];
		}
	}
	ret += (cnt)/2;
	return ret;
}
int main(){
	cin >> s >> k;
	for(int i=1;i<s.size();i++) if(s[0] != s[i]) goto nxt;
	k = k*(ll)(s.size());
	cout << k/2 << endl; return 0; nxt:;
	string a = s;
	ll beg = calc(a);
	a += s;
	ll nxt = calc(a);
	
	cout << beg + (nxt-beg) * (k-1) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	
	int n,x,i,j,l,count=0;
	
	for(;;){
		
		scanf("%d %d",&n,&x);
		
		if(n==0&&x==0){
			break;
		}
		
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				for(l=j+1;l<=n;l++){
					if(i+j+l==x && i!=j && i!=l && j!=l){
						count++;
					}
				}
			}
		}
		
		printf("%d\n",count);
		
		count=0;
	}
	
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if (a == b && a != c) cout<<"Yes"<<endl;
    else if(a == c && a != b) cout<<"Yes"<<endl;
    else if(b == c && a != b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
query = int(input())
for i in range(query):
    q = input().split()
    if q[0] == 'print':
        print(s[int(q[1]):int(q[2])+1])
    elif q[0] == 'reverse':
        s = s[0:int(q[1])] + s[int(q[1]):int(q[2])+1][::-1] + s[int(q[2])+1:]
    else:
        s = s[0:int(q[1])] + q[3] + s[int(q[2])+1:]


Measured memory_bytes: 5612
n=int(input())
a=[int(i) for i in input().split()] 

check4=0
check2=0
for i in a:
    if i%4==0:
        check4+=1
        continue
    if i%2==0:
        check2+=1
if n==check2:
    ans='Yes'
elif check2<=1:
    if n//2<=check4:
        ans='Yes'
    else:
        ans='No'
else:
    n=n-check2
    if -(-n//2)<=check4:
        ans='Yes'
    else:
        ans='No'
print(ans)

Measured memory_bytes: 14252
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <algorithm>
using namespace std;


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

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

    //
    auto cmp = [](int x, int y) { return x > y; };
    sort(A, A + N, cmp);
//    for (int i = 0; i < N; i++) {
//        cout << A[i] << endl;
//    }

    //
    int alice = 0, bob = 0;
    for (int i = 0; i < N; i+=2) {
        alice += A[i];
    }
    for (int i = 1; i < N; i+=2) {
        bob += A[i];
    }

    //
    cout << alice - bob << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
	int a ,b ;
	char  op;
	while(1){
		cin >> a >> op >> b ;
		if (op == '?' )break;
		else if (op == '+')
			cout << a+b << endl;
		else if (op == '-')
			cout << a-b << endl;
		else if (op == '*')
			cout << a*b << endl;
		else if (op == '/')
			cout << a/b << endl;
	}
}

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

int main()
{
    long long a;
    double b;
    cin >> a >> b;
    long long ib = b * 100 + 0.5;
    a *= ib;
    a /= 100;
    cout << (long long)a << endl;
    return 0;
}

Measured memory_bytes: 3636
a, b, k = map(int, input().split())

if a <= k:
  if b -(k - a) <=0:
    print('0 0')
  else:
    s = 0
    t = b - (k - a)
    print('{} {}'.format(s, t))
else:
  s = a - k
  t = b
  print('{} {}'.format(s, t))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    vecl A(N);
    veci res(N);
    REP(i,N) {
        cin >> A[i];
        res[A[i]]++;
    }
    ll ans = 1;
    const int MOD = 1000000007;
    if(N%2 != 0) {
        if(res[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
        REP(i,N) if(i != 0 && i%2 == 0 && res[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
        REP(i,N) if(i%2 == 0) {
            ans *= res[i];
            ans %= MOD;
        }
    } else {
        REP(i,N) if(i%2 != 0 && res[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
        REP(i,N) if(i%2 != 0) {
            ans *= res[i];
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s, t;
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> a >> b;
	cout << max(a - b, 0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <cmath>

using namespace std;
long long x, k, d;
long long min_abs;

int main() {
    cin >> x >> k >> d;
    if (x < 0) x *= -1;

    long long min_k = round((double) x / d);
    if (k <= min_k) {
        min_abs = x - (d * k);
    } else {
        min_abs = x - (d * min_k);
        k -= min_k;
        if ((k & 1) == 1) {
            if (min_abs < 0) {
                min_abs += d;
            } else {
                min_abs -= d;
            }
        }
    }

    cout << abs(min_abs) << "\n";
    return 0;
}


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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    lint N;
    ulint A[200001];
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    A[N]=0;

    lint l=0,r=0;
    lint xo=A[l];
    lint su=A[l];
    lint cnt=0;
    while(r<N){
        while(r<N && xo==su){
            cnt+=r-l+1;
            r++;
            xo^=A[r];
            su+=A[r];
        }
//        cerr << l << " " << r << endl;
//        cnt+=(r-l)*(r-l-1)/2+(r-l);
        while(xo!=su){
            xo^=A[l];
            su-=A[l];
            l++;
        }
    }

    cout << cnt << endl;
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int d = A - B;
  
  if (A % 2 != B % 2) {
  	cout << "IMPOSSIBLE" << endl;
  }
  
  else {
  	cout << (A + B) / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll X;
    cin>>X;
    rep(i, 2000) rep(j, 2000){
        if(i*i*i*i*i-j*j*j*j*j==X){
            cout<<i<<sp<<j<<endl;
            return 0;
        }
        if(i*i*i*i*i+j*j*j*j*j==X){
            cout<<i<<sp<<-j<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;


int main() {
	int n, m; CI n >> m;
	int tmp[50] = {};
	for (int i = 0; i < n; i++) {
		int k; CI k;
		for (int j = 0; j < k; j++) {
			int a; CI a; a--;
			tmp[a]++;
		}
	}
	int ans = 0;
	REP(i, m) {
		if (tmp[i] == n) { ans++; }
	}
	CO ans EN;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 7 && b == 5 && c == 5 ||
        a == 5 && b == 7 && c == 5 || 
        a == 5 && b == 5 && c == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  for(int i = 0;i<a.size()+b.size();i++){
    if(i%2 == 0)
      cout << a.at(i/2);
    else 
      cout << b.at(i/2);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

int main() {
	string S;
	cin >> S;
	if (S[1] == 'B')S[1] = 'R';
	else S[1] = 'B';
	cout << S << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main()
{
	int n,a,b;
	string s;
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	return 0;
}


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

int main()
{
  ll N; cin >> N;
  vector<long double> p(N);
  for (int i=0; i<N; i++){
    cin >> p[i];
  }

  vector<vector<long double>> dp(N+1, vector<long double>(N+1, 0));
  dp[0][0] = 1;
  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      dp[i+1][j+1] += dp[i][j]*p[i];
      dp[i+1][j] += dp[i][j]*(1-p[i]);
    }
  }
  long double ans = 0;
  for (int i=(N+1)/2; i<=N; i++) {
    ans += dp[N][i];
  }
  printf("%.9Lf\n", ans);

  return 0;
}


Measured memory_bytes: 141056
while True:
    H,W=map(int,input().split())
    if H==0 and W==0: 
        break
    for i in range(H): 
        if i==0 or i==H-1:
            print('#'*W)
        else: 
            print('#','.'*(W-2),'#',sep='')
    print('')   


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define PB push_back
#define MP make_pair
#define MOD 1000000000
#define FOR(i,a,b) for(int i=(a);(i)<(b);(i)++)

typedef unsigned int UI;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<char, int> PCI;
int n , l;
int a[100000];
int curCenterLen;
int L = 0 , R = n - 1;
vector<int> untie;
vector<int> centerPos;
int go(int l , int r)
{
	//cout << l << " " << r << endl;
	printf("Possible\n");
	for(int i = 1; i < l; i++)
	{
		printf("%d\n" , i);
	}
	for(int i = n - 1; i >= r; i--)
		printf("%d\n" , i);
	printf("%d\n" , l);
	exit(0);
}
int main()
{
	scanf("%d %d" , &n , &l);

	for(int i = 0; i < n; i++)
	{
		scanf("%d" , &a[i]);
		if(a[i] == curCenterLen)
		{
			centerPos.pb(i + 1);
			continue;
		}
		if(a[i] > curCenterLen)
		{
			curCenterLen = a[i];
			centerPos.clear();
			centerPos.push_back(i + 1);
		}
	}
	bool can = true;
	for(int i = 0; i < n - 1; i++)
	{
		int curPos = i;
		if(a[curPos] + a[curPos + 1] >= l)
		{
			go(curPos + 1 , curPos + 2);
		}
	}
	cout << "Impossible";
	return 0;
}





Measured memory_bytes: 1784
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;

const ll inf = 100000000000000LL;

int a[101];
bool flag[101];

int cc = 0;

ll dfs(int n, int k){
  ll ret = inf;

  if(n+1 == k) return 0;
    
  if(!flag[k] && a[k] < 0){
    bool memo[100] = {};
    ll sum = 0;
    int counter = 0;
    
    for(int i=1;i*k<=n;i++){
      if(!flag[i*k]){
	memo[i*k] = true;
	flag[i*k] = true;
	sum += a[i*k];
	counter++;
      }
    }
    
    if(counter != 1 || a[k] < 0){
      ret = min(ret, dfs(n, k+1) + sum);
    }

    for(int i=1;i*k<=n;i++){
      if(memo[i*k]){
	memo[i*k] = false;
	flag[i*k] = false;
      }
    }
    
    if(counter == 1 && a[k] < 0)
	return ret;
  }
    
  ret = min(ret, dfs(n, k+1));

  //printf("%d\n",cc++);
  
  return ret;
}

int main() {
  int n;
  ll sum = 0;
  
  scanf("%d",&n);

  for(int i=1;i<=n;i++){
    scanf("%d",a+i);
    sum += a[i];
  }
  
  printf("%lld\n", sum - dfs(n,1));

  return 0;
}


Measured memory_bytes: 256
# @author 

import sys

class DTeleporter:
    def solve(self, tc=0):
        n, k = [int(_) for _ in input().split()]
        a = [int(_) - 1 for _ in input().split()]
        done = dict()
        cur = 0
        steps = 0
        while cur not in done and steps < k:
            done[cur] = steps
            cur = a[cur]
            steps += 1
        
        if steps == k:
            print(cur + 1)
            return

        d = steps - done[cur]
        steps = steps + ((k - steps) // d) * d

        while steps < k:
            cur = a[cur]
            steps += 1

        print(cur + 1)


solver = DTeleporter()
input = sys.stdin.readline

solver.solve()


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

char S[ 60 ][ 60 ];
int iCnt[ 30 ];
int iMin[ 30 ];

int main()
{
int i;
int j;
int n;
int iMax;
char C;

	cin >> n;

	for( i = 0; i < n; i++ ) cin >> S[ i ];

	j = 0;
	while( ( C = S[ 0 ][ j ] ) != '\0' )
	{
		iMin[ C - 'a' ]++;
		j++;
	}

	for( i = 1; i < n; i++ )
	{
		memset( iCnt, 0, 26 * 4 );

		j = 0;
		while( ( C = S[ i ][ j ] ) != '\0' )
		{
			iCnt[ C - 'a' ]++;
			j++;
		}

		for( j = 0; j < 26; j++ )
			iMin[ j ] = min( iMin[ j ], iCnt[ j ] );
	}

	for( i = 0; i < 26; i++ )
		cout << string( iMin[ i ], 'a' + i );

	cout << endl;

	return 0;
}






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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, k, s;
  cin >> n >> k >> s;
  vector<ll> v(n);
  for (int i = 0; i < k; i++) v[i] = s;
  ll next = (s + 1) % 1000000001;
  if (next == 0) next++;
  for (int i = k; i < n; i++) v[i] = next;
  cout << v[0];
  for (int i = 1; i < n; i++) cout << " " << v[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 2176
n = int(input())
t, a = map(int, input().split())
h = [int(i) for i in input().split()]
d = 9999999999999
num = -1
for i, hei in enumerate(h):
    e = abs(a - (t - hei*0.006))
    if e < d:
        d = e
        num = i + 1
print(num)


Measured memory_bytes: 3060
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for(int i=0;i<n;i++) {
    cin >> x[i];
    y[i] = x[i];
  }

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

  for(int i=0;i<n;i++) {
    if(x[i] >= y[n/2]) {
      cout << y[n/2-1] << endl;
    } else {
      cout << y[n/2] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5376
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

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

const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: [usize; n],
        t: [usize; m],
    }

    let mut dp = vec![vec![0; m + 1]; n + 1];
    for i in 0..n + 1 {
        dp[i][0] = 1;
    }

    for i in 0..m + 1 {
        dp[0][i] = 1;
    }

    for i in 1..n + 1 {
        for j in 1..m + 1 {
            if s[i - 1] == t[j - 1] {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            } else {
                dp[i][j] = M + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
            }
            dp[i][j] %= M;
        }
    }
    println!("{}", dp[n][m]);
}


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

int main() {
  char c11, c12, c13, c21, c22, c23;
  cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23;

  if(c11 == c23 && c12 == c22 && c13 == c21) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<time.h>
using namespace std;
const int N = 3e5 + 10;
using ll = long long;
const int INF = 2e9 + 10;
using pii = pair<int, int>;
using vi = vector<int>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define mp make_pair 
#define pb push_back
#define clr(x, v) memset(x, v, sizeof (x))
#define all(x) x.begin(), x.end()
#define fi first
#define se second
int n, k;
int L;
int main() {
    cin >> L;
    int sum = 0;
    vector<pair<int, int>> vec;
    for (int i = 18; i >= 0; i--) {
        while (L >= sum + (1 << i)) {
            vec.push_back({19 - i, sum});
            sum += (1 << i);
        }
    }
    cout << 20 << " " << 36 + vec.size() << endl;
    for (int i = 1; i < 19; i++) {
        cout << i + 1 << " " << i + 2 << " " << 0 << endl;
        cout << i + 1 << " " << i + 2 << " " << (1 << (18 - i)) << endl;
    }
    for (auto e : vec) {
        cout << 1 << " " << e.first + 1 << " " << e.second << endl;
    }
    return 0;
}



Measured memory_bytes: 256
///******* In the name of Allah *******///

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

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

void Ok()
{
    long long int a[30013],b[10013],c,d,e,f,g,h,t,s,i,j,k,l1,l2,m,n,r,sum = 0,ans_1,ans_2,ans_3,cnt = 0,Max,Min,flag,div,temp;
    double aa,bb,cc,dd,ee,tot;
    char aaa[3013],bbb[1013],ccc[1013],num;
    cin>>aaa;
    l1 = strlen(aaa);
    for(i=0;i<l1;i++)
    {
        cout<<"x";
    }

}

int main()
{
    Ok();

    return 0;
}


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	ll ans =0;
	rep(i,n){
		ll l,r;
		cin >>l >>r;
		ans += r+1-l;
	}
	cout << ans <<"\n";
	return 0;
}

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

int main(){
  int N, Q; cin >> N >> Q;
  vector<int> s1(N,N-1),s2(N,N-1);
  int h=N-1,w=N-1;
  long long black=((long long)N-2)*(N-2);
  for(int i=0; i<Q; i++){
    int prob,x; cin >> prob >> x;
    x--;
    
    if(prob==1){
      if(x<w){
        //新しく栓をする
        //栓は最大1回
        for(int j=x; j<w; j++){
          s1[j]=h;
        }
        w=x;
      }
      black-=(s1[x]-1);
    }else{
      if(x<h){
        for(int j=x; j<h; j++){
          s2[j]=w;
        }
        h=x;
      }
      black-=(s2[x]-1);
    }
  }
  cout << black << endl;
}

Measured memory_bytes: 4748
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        n: i32,
    }
    println!("{}", n/3);
}


Measured memory_bytes: 4352
n,k,q = gets.split.map(&:to_i)
a = Array.new(n,0)
q.times do
    a[gets.to_i-1] += 1
end
ans = ""
a.each {|i| 
    if k - q + i > 0
        ans << "Yes\n"
    else
        ans << "No\n"
    end
}

puts ans

Measured memory_bytes: 4220
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
int Factorial(ll n)
{
	for (ll i = n - 1; i > 1; i--)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll Combination(const ll n, const ll r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool IsPrime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll DigitSum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll d, n;

	if (d == 0)
	{
		if (n == 100)
			return OUT(101);
		else
			return OUT(n);
	} else if (d == 1)
	{
		if (n == 100)
			return OUT(10100);
		else
			return OUT(100 * n);
	} else if (d == 2)
	{
		if (n == 100)
			return OUT(1010000);
		else
			return OUT(10000 * n);
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
using namespace std;

int main() {

	string res = "Yes";

	int a, b, c;
	cin >> a >> b >> c;

	if (a != b || b != c || c != a) res = "No";

	cout << res << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment

const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);

namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
}
double dot(P a, P b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(P a, P b){ return   a.real() * b.imag() - a.imag() * b.real(); }

// ????????¨???????????¢
double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));  //??´?????¨???????????¢
}

int N,M,X,Y;
P pos[5555];
typedef pair<double,int> PA;
bool used[5555];
double ky[5555];
priority_queue<PA,vector<PA>,greater<PA> > q;


void insert_seg(const L& seg){
  for(int i=0;i<=N;i++){
    if( used[i] ) continue;
    double x = getDistanceSP( seg, pos[i] );
    if( ky[i] < x ) continue;
    ky[i] = x;
    q.push( PA(x,i) );
  }
}

int main(){
  cin >> N >> M >> X>> Y;
  fill(ky,ky+N+1,1e300);
  used[0] = true;
  pos[0] = P(X,Y);
  P kp = P(X,Y);
  PA k=PA(1e300,0);
  for(int i=1;i<=N;i++){
    int x,y; cin >> x >> y;
    pos[i] = P(x,y);
    k = min( k , PA( abs(pos[i]-kp), i ) );
  }
  vector<L> seg;
  used[k.second] = true;
  seg.push_back( L(pos[k.second],kp) );
  insert_seg( L(pos[k.second],kp) );

  int cnt = 1;
  while( !q.empty() && cnt < M ) {
    PA p = q.top(); q.pop();
    if( used[p.second] ) continue;
    cnt++;
    PA kx = PA(1e300,0);
    P kp = pos[p.second];
    for(int i=0;i<=N;i++){
      if( used[i] ) {
	//	cout << kx.first << " - " << abs(kp-pos[i]) << " i " << i << endl;
	kx = min( kx, PA( abs(kp-pos[i]), i ) );
	///	cout << kx.first << " " << kx.second << endl;
	
      }
    }
    used[p.second] = true;
    insert_seg( L(kp, pos[kx.second]) );
    seg.push_back( L(kp,pos[kx.second]) );
  }

  double res = 0.0;
  //cout << seg.size()<< " "<< cnt  << endl;
  for(int i=0;i<seg.size();i++){
    //cout << seg[i].first << " - " << seg[i].second << endl;
    res += abs(seg[i].first - seg[i].second);
  }
  printf("%.10lf\n",res);
  
}

Measured memory_bytes: 35952
# aising2019C - Alternating Path
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(x: int, y: int) -> None:
    global blk, wht
    seen[x][y] = 1
    cur = S[x][y]
    if cur == "#":
        blk += 1
    else:
        wht += 1
    for dx, dy in dxy:
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != cur and not seen[nx][ny]:
            dfs(nx, ny)


def main():
    # separate S to connected components
    global H, W, S, seen, dxy, blk, wht
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    seen = [[0] * W for _ in range(H)]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    ans = 0
    for i in range(H):
        for j in range(W):
            if not seen[i][j]:
                blk, wht = 0, 0
                dfs(i, j)
                ans += blk * wht
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 149428
#include <iostream> // cout, endl, cin
#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
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#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 a, b;
    cin >> a >> b;
    if (a > b)
    {
        string ans = "";
        rep(i, a)
        {

            ans.push_back(char(b + 48));
        }
        cout << ans << endl;
    }
    else
    {
        string ans = "";
        rep(i, b)
        {
            ans.push_back(char(a + 48));
        }
        cout << ans << endl;
    }
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
 
Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

bool dp[100501];

int main() {
    Int x;
    cin >> x;
    dp[0] = true;
    for (Int i = 100; i <= 105; i++) {
        for (Int j = 0; j <= x; j++) {
            dp[i + j] = dp[i + j] or dp[j];
        }
    }
    dump(dp[x] ? 1 : 0);
    return 0;
}

Measured memory_bytes: 384
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

// conversion
inline int
toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

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

//math
template <class T>
inline T sqr(T x) { return x * x; }

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

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

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

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

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1);
    A[0] = 0;
    A[1] = 0;
    vector<int> ans(N + 1);
    for (int i = 2; i <= N; ++i)
    {
        cin >> A[i];
        ans[A[i]]++;
    }
    for (int i = 1; i <= N; ++i)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4840