akhauriyash/Code-Regression huggingface dataset:
process.stdin.resume();
var x = '';
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (input) {
    x += input;
});

process.stdin.on('end', function () {
    var xArray = x.split('\n');
    var output = [];
    for(var i = 0; i < xArray.length; i++) {
        if(0 != xArray[i]) {
            output.push('Case ' + (i + 1) + ': ' + xArray[i]);
        }
    }
    console.log(output.join('\n'));
});

Measured memory_bytes: 19448
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char stribuf[2200010];
uint32_t stribufl;

#define getchar_unlocked() stribuf[stribufl++]
uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }
void rsort_str(void *base, const int count, const int size);

char str[200000][11];

int main(void){
	read(0, stribuf, sizeof(stribuf));
	uint32_t n=nextpint();
	for(uint32_t i=0; i<n; i++){
		char *s=str[i];
		char c=getchar_unlocked();
		while(c!=' '&&c!='\n'){ *s++=c; c=getchar_unlocked(); }
		*s='\0';
	}
	rsort_str(str, n, 11);
	uint32_t ans=1;
	for(uint32_t i=1; i<n; i++){
		if(strcmp(str[i], str[i-1])) ans++;
	}
	printint(ans);
}

void rsort_str(void *base, const int count, const int size){
	char (*a)[size]=base;
	char (*b)[size]=malloc(count*size);
	int c[0x100];
	for(int j=9; j>=0; j--){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[a[i][j]]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ memcpy(&b[--c[a[i][j]]], a[i], size); }{void *t=a; a=b; b=t;}
	}
	free(b);
}


Measured memory_bytes: 7552
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pii;

template<typename T>
using pq_gt = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using pq_lt = priority_queue<T, vector<T>, less<T>>;

#define se second
#define fi first
#define pb push_back

int a[55],b[55];
ll ans;
ll dp[55][55],dp1[55][55];

int check(int idx) {
	for(int i = 0; i < 55; ++i) {
		dp1[idx][i] = dp[idx][i];
		//cout<<dp1[idx][i]<<" ";
	}
	//cout<<endl;	
	for(int i = 50; i>=1; i--) {
		for(int j = 0; j<=50; ++j) {
			if(dp1[idx][j]!=1e18) {
				dp1[idx][j%i] = min(dp1[idx][j%i], dp1[idx][j]+(1LL<<i));
			}
		}
	}
	//cout<<dp1[idx][b[idx]]<<endl;
	if(dp1[idx][b[idx]]==1e18) {
		return -1;
	}
	//cout<<dp1[idx][b[idx]]<<endl;
	for(int i = 50; i>=1; i--) {
		if((1LL<<i) & dp1[idx][b[idx]]) {
			return i;
		}
	}
	return 0;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    for(int i = 0; i < N; ++i) {
    	cin>>a[i];
    }
    for(int i = 0; i < N; ++i) {
    	cin>>b[i];
    }
    for(int i = 0; i <=52; ++i) {
    	for(int j = 0; j<=52; ++j) {
    		dp[i][j] = 1e18;
    	}
    }
    for(int i = 0; i < N; ++i) {
    	dp[i][a[i]] = 0;
    }
    while(true) {
    	int x = 0;
    	for(int i = 0; i < N; ++i) {
    		int p = check(i);
    		if(p==-1) {
    			cout<<-1<<endl;
    			return 0;
    		}
    		x = max(x, p);
    	}
    	//cout<<x<<endl;
    	if(x==0) {
    		cout<<ans<<endl;
    		return 0;
    	}
    	ans += (1LL<<x);
    	for(int i = 0; i < N; ++i) {
    		for(int j = 0; j <= 50; ++j) {
    			if(dp[i][j]!=1e18) {
    				dp[i][j%x] = min(dp[i][j%x], dp[i][j]);
    			}
    		}
    	}
    }
}

Measured memory_bytes: 256
n = int(input())
l = [[0, 0] for _ in range(n)]

for i in range(n):
  x, y = map(float, input().split())
  l[i][0] = x
  l[i][1] = y
#print(l)

import itertools
import math
seq = range(0, n)
seqs = list(itertools.permutations(seq))
ans = 0
for c in seqs:
  t = 0
  for i in range(len(c)-1):
    z1 = c[i]
    z2 = c[i+1]
    t += math.sqrt((l[z1][0] - l[z2][0])**2+(l[z1][1] - l[z2][1])**2)
  ans += t

print(ans/len(seqs))

Measured memory_bytes: 45808
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll A[100010], dp[100010][2] = {};
const ll inf = -1e18;

int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        dp[i][0] = inf;
        dp[i][1] = inf;
    }
    for (int i=2;i<=N;i++){
        if (i==2){
            dp[i][0] = A[i-1]+A[i];
            dp[i][1] = -A[i-1]-A[i];
        }else{
            dp[i][0] = max(dp[i-1][0], dp[i-1][1])+A[i];
            dp[i][1] = max(dp[i-1][0]-2*A[i-1]-A[i], dp[i-1][1]+2*A[i-1]-A[i]);
        }
    }
    cout << max(dp[N][0], dp[N][1]) << endl;
}

Measured memory_bytes: 2560
def IsPalindrome(s):
    reversed = s[::-1]
    for i, j in zip(s, reversed):
        if i != j:
            return False
    return True

def weakOrStrong(s):
    if not IsPalindrome(s):
        return False
    n = len(s)
    if not IsPalindrome(s[:int((n - 1) / 2)]):
        return False
    if not IsPalindrome(s[int((n + 1) / 2):]):
        return False
    return True

def solve(s):
    return 'Yes' if weakOrStrong(s) else 'No'

def main():
    s = input()
    print(solve(s))

if __name__ == '__main__':
    main()


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b == c+d)cout << "Balanced";
  else if(a+b > c+d)cout << "Left";
  else cout << "Right";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n; cout<<(180*n - 360);

    return 0;
}

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,j,n) for(int i=j; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const ll mod=1000000007;

int main()
{
    optimizeIO();
    int nT; nT=1;
	while(nT--)
	{
		string s1,s2; cin>>s1>>s2;
		int cnt=0;
		rep(i,0,3) if(s1[i]==s2[i]) cnt++;
		cout<<cnt;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool Binary_Search(int *A, int length, int key);

int main() {
	
	int n, q;
	int *S, *T;
	int count = 0;
	
	cin >> n;
	S = new int [n];
	
	for(int i=0;i<n;i++)
		cin >> S[i];
		
	cin >> q;
	T = new int [q];
	
	for(int i=0;i<q;i++)
		cin >> T[i];
		
	for(int i=0;i<q;i++)
		if( Binary_Search(S, n, T[i]) )
			count++;

	cout << count << "\n";
	
	delete [] S;
	delete [] T;
	
	return 0;
}

bool Binary_Search(int *A, int length, int key) {
	
	int low = 0;
	int up = length - 1;
	int mid;
	
	while(low <= up) {
		
		mid = low + (up-low)/2;
        
        if(key == A[mid]) {
            return true;
            break;
        }
            
        else if(key > A[mid])
        	low = mid + 1;
            
        else
            up = mid - 1;
		
	}
	return false;
}


Measured memory_bytes: 3228
#include <stdio.h>
int main (void){
    int am,pm,i,nin,gaku;
    char cl[16];
    for(i=0;i<9;i++){
        scanf("%s%d%d",cl,&am,&pm);
        nin=am+pm;
        gaku=am*200+pm*300;
        printf("%s %d %d\n",cl,nin,gaku);
    }
return 0;
}

Measured memory_bytes: 1024
a, b, c = map(int, input().split(" "))


k = 0
ans = [a, b, c]
p = max(a, b, c)

for i in range(len(ans)):
    ans[i] = p - ans[i]

count = 0


while count != 3:
    count = 0

    for j in range(len(ans)):
        if ans[j] == 0:
            count = count + 1
    
    
    if count == 1:
        for i in range(len(ans)):
            if ans[i] != 0:
                ans[i] = ans[i] - 1

        k = k + 1
    
    elif count == 2:
        for i in range(len(ans)):
            if ans[i] > 0:
                ans[i] = ans[i] - 2
                
            elif ans[i] < 0:
                ans[i] = ans[i] + 1
                
        k = k + 1
    else:
        break
    
print(k)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  ll N,M;
  cin >> N >> M;
  if(M/2 <= N)cout << M/2 << endl;
  else cout << N + (M - N*2)/4 << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
    int  N=0, A=0, B=0;
    cin >> N >> A >> B;
    cout << min(A, B)  << " " << (N-(A+B)>0 ? 0 : abs(N-(A+B))) << endl;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

def main():
    N = int(input())
    grid = []
    for _ in range(N):
        tmp = list(map(int, readline().split()))
        grid.append(tmp)
    
    removes = set([])
    for k in range(N):
        for i in range(N):
            for j in range(N):
                gridij = grid[i][j]
                gridik = grid[i][k]
                gridkj = grid[k][j]
                if gridij > gridik + gridkj:
                    print(-1)
                    return
                elif i != j and j != k and k != i and gridij == gridik + gridkj:
                    removes.add((i, j))
                else:
                    pass
    
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += grid[i][j] * ((i, j) not in removes)
    print(ans)

if __name__ == "__main__":
    main()


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

int solve(string S) {
    vector<string> zenbu;
    for (int i = 0; i < S.length() - 1; i++) {
        string a;
        string b;
        for (int j = 0; j <= i; j++) {
            a.push_back(S[j]);
        }
        for (int j = i+1; j < S.length(); j++) {
            b.push_back(S[j]);
        }
        string revA;
        for (int j = a.length() - 1; j >= 0; j--) {
            revA.push_back(a[j]);
        }
        string revB;
        for (int j = b.length() - 1; j >= 0; j--) {
            revB.push_back(b[j]);
        }
        zenbu.push_back(a+b);
        zenbu.push_back(a+revB);
        zenbu.push_back(b+a);
        zenbu.push_back(b+revA);
        zenbu.push_back(revA+b);
        zenbu.push_back(revA+revB);
        zenbu.push_back(revB+a);
        zenbu.push_back(revB+revA);
    }
    sort(zenbu.begin(), zenbu.end());
    int ret = 1;
    for (int i = 1; i < zenbu.size(); i++) {
        if (zenbu[i] != zenbu[i-1]) ret++;
    }
    return ret;
}

int main(){
    int N; cin >> N;
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        ans.push_back(solve(s));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
}


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

int ifprime(int i) {
    int j;

    /* 判定フラグ */
    int flag;
    flag = 0;
    for (j = 2; j < i; ++j) {
        if (i % j == 0) {
            flag = 1;
            break;
        }
    }
    /* 判定結果を出力 */
    if (flag == 0)return 1;
    else return 0;
}

int main() {
    int num[1000001]={0};
    for (int i = 3; i <100001; i+=2) {
        if(ifprime(i) && ifprime((i+1)/2))num[i]=1+num[i-2];
        else num[i]=num[i-2];
    }
    //cout<<num[7]<<num[9]<<num[11]<<num[13]<<endl;
    int q;
    cin>>q;
    for (int j = 0; j < q; ++j) {
        int l,r;
        cin>>l>>r;
        if(l==1)l=3;
        cout<<num[r]-num[l-2]<<endl;
    }
    return 0;
}

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

int divisor(int input) {
	int count = 0;
	for (int i = 1; i <= input; i++) {
		if (input % i == 0) {
			count++;
		}
	}
	return count;
}

int main() {
	int n;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i += 2) {
		if (divisor(i) == 8) {
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3568
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


x_max, y_max, N = il()
x_min, y_min = 0, 0
s = 0
for i in range(N):
    x, y, a = il()
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    elif a == 3:
        y_min = max(y_min, y)
    else:
        y_max = min(y_max, y)
if x_min > x_max or y_min > y_max:
    print(0)
else:
    print((x_max - x_min) * (y_max - y_min))


Measured memory_bytes: 3064
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //数値入力する
            string input = Console.ReadLine();

            //r*rを出力
            if(input == "SUN")
                Console.WriteLine("7");
            else if(input == "MON")
                Console.WriteLine("6");
            else if(input == "TUE")
                Console.WriteLine("5");
            else if(input == "WED")
                Console.WriteLine("4");
            else if(input == "THU")
                Console.WriteLine("3");
            else if(input == "FRI")
                Console.WriteLine("2");
            else if(input == "SAT")
                Console.WriteLine("1");
                
        }
}

Measured memory_bytes: 11092
// C - GeT AC
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,Q; string S; cin>>N>>Q>>S;

	vector<int> P(N+1);
	for(int i=1; i<N; ++i)
		P[i+1] = S[i-1]=='A' && S[i]=='C'? P[i]+1: P[i];

	for(int i=0; i<Q; ++i){
		int l,r; cin>>l>>r;
		cout<< P[r] - P[l] <<endl;
	}

}

Measured memory_bytes: 1408
'use strict';
 
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;
});
 
process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});
 
function readline() {
    return inputString[currentLine++];
}
 
// main funtion .. code start ..... ///
function main() {
 
    var T = parseInt(readline());
    var str = readline();
    
    var res1 = str.slice(0, Math.floor(T/2));
    var res2 = str.slice(T/2);
    
    if(str.length === 1 ) console.log('No');
    else console.log(res1 === res2 ? 'Yes': 'No');
 
}

Measured memory_bytes: 21320
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define MOD 1000000007LL

map<llong, llong> M;

template<typename T> void factorization(T p) {
    llong i = 2;
    while (i * i <= p) {
        if (p % i == 0) {
            ++M[i];
            p /= i;
        } else {
            ++i;
        }
    }

    if (p != 1) ++M[p];
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    for (llong i = 2; i <= n; ++i) {
        factorization(i);
    }

    llong ans = 1;
    for (auto itr = M.begin(); itr != M.end(); ++itr) {
        ans = ((ans % MOD) * (itr->second + 1) % MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
S = list(input())[::-1]
Now = [0 for _ in range(13)]
Next = [0 for _ in range(13)]

if S[0] != "?":
    Next[int(S[0])] = 1
else:
    Next = [1,1,1,1,1,1,1,1,1,1,0,0,0]
Now = Next
modq = 1
for i in range(len(S)-1):
    i = i + 1
    Next = [0 for _ in range(13)]
    if S[i] != "?":
        mod = (int(S[i])*10*modq)%13
        for j in range(len(Now)):
            Next[(mod+j)%13] = (Next[(mod+j)%13] + Now[j])%(10**9+7)
        modq = (10*modq)%13
    else:
        modq = (10*modq)%13
        mod = 0
        for j in range(10):
            for k in range(len(Now)):
                Next[(mod+k)%13] = (Next[(mod+k)%13] + Now[k])%(10**9+7)
            mod = (mod + modq)%13
    Now = Next
print(Now[5])

Measured memory_bytes: 50288
using System;
using static System.Console;
using System.Collections.Generic;
using System.Collections;

namespace Grobal
{
	class Program
	{
		static void Main(string[] args)
		{
			string c = ReadLine();
			switch(c)
			{
				case "a":
				case "i":
				case "u":
				case "e":
				case "o":
					WriteLine("vowel");
					break;
				default:
					WriteLine("consonant");
					break;
			}
		}
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const ll MOD = 1e9 + 7;

int main() {
    ll N, sum = 0;
    cin >> N;
    vl A(N);
    rep(i,N) {
        cin >> A[i];
        sum += A[i];
    }
    ll ans = 0;
    rep(i,N) {
        ll tmp = (sum - A[i]) % MOD;
        (ans += (A[i]*tmp) % MOD) %= MOD;
        sum -= A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4820
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <queue>
using namespace std;

// first-child second-sibling
map< int, pair< int, int > > nodes;
// first-parent second-depth
map< int, pair< int, int > > parentsAndDepths;
vector< int > heights;
vector< bool > isChild;
int root;

void populateHeights(void) {
  for (int i = 0; i < parentsAndDepths.size(); i++) {
    if (nodes[i].first == -1) {
      heights[i] = 0;
      int prev = i;
      int parent = parentsAndDepths[i].first;
      while (parent != -1) {
	if (heights[parent] < (heights[prev]+1))
	  heights[parent] = heights[prev]+1;
	prev = parent;
	parent = parentsAndDepths[prev].first;
      }
    }
  }
  return;
}

string nodeType(int id) {
  if (id == root)
    return "root";
  else if (nodes[id].first == -1)
    return "leaf";
  else
    return "internal node";
}

int degree(int id) {
  if (nodes[id].first == -1)
    return 0;
  else if (nodes[nodes[id].first].second == -1)
    return 1;
  else
    return 2;
}

void populateDepths(void) {
  queue< int > fringe;
  fringe.push(root);
  parentsAndDepths[root].second = 0;
  while (!fringe.empty()) {
    int current = fringe.front();
    fringe.pop();
    int toAdd = nodes[current].first;
    if (toAdd != -1) {
      parentsAndDepths[toAdd].second = parentsAndDepths[current].second+1;
      fringe.push(toAdd);
      int toAddSibling = nodes[toAdd].second;
      if (toAddSibling != -1) {
	parentsAndDepths[toAddSibling].second = parentsAndDepths[toAdd].second;
	fringe.push(toAddSibling);
      }
    }
  }
  return;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  isChild = vector< bool > (n, false);
  heights = vector< int > (n, -1);
  for (int i = 0; i < n; i++) {
    nodes[i] = pair< int, int > (-1,-1);
    parentsAndDepths[i] = pair< int, int > (-1, -1);
  }
  for (int i = 0; i < n; i++) {
    int id, left, right;
    cin >> id >> left >> right;
    if (left != -1) {
      isChild[left] = true;
      nodes[left].second = right;
      nodes[id].first = left;
      parentsAndDepths[left].first = id;
    }
    if (right != -1) {
      isChild[right] = true;
      nodes[right].second = left;
      nodes[id].first = right;
      parentsAndDepths[right].first = id;
    }
  }
  for (int i = 0; i < n; i++)
    if (!isChild[i]) {
      root = i;
      break;
    }
  populateDepths();
  populateHeights();
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": ";
    cout << "parent = " << parentsAndDepths[i].first << ", ";
    cout << "sibling = " << nodes[i].second << ", ";
    cout << "degree = " << degree(i) << ", ";
    cout << "depth = " << parentsAndDepths[i].second << ", ";
    cout << "height = " << heights[i] << ", ";
    cout << nodeType(i);
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3212
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int num = 0; num < 1000; ++num) {
    string num_s = to_string(num);
    if (num_s.size() != n) continue;
    bool ok = true;
    for (int i = 0; i < m; ++i) {
      if (num_s[s[i]] - '0' != c[i]) ok = false;
    }
    if (ok) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

using namespace std;


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    int aSum = a + 10*b + c;
    int bSum = 10 * a + b + c;
    int cSum = a + b + 10 * c;
    cout << max(aSum,max(bSum,cSum));
    return 0;
};

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  string s; cin >> s;
  for (char &ch: s) if (ch == ',') ch = ' ';
  cout << s << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[105];
int sum[105],ans,mx[105];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1); ans=len-1;
	for(int i=1;i<=26;i++){
		int tot=0;
		for(int j=1;j<=len;j++) if(s[j]-'a'+1==i) sum[++tot]=j,mx[tot]=max(sum[tot]-sum[tot-1]-1,mx[tot-1]);
		for(int j=1;j<=tot;j++) ans=min(ans,max(mx[tot],len-sum[tot]));
	}
	printf("%d\n",ans);
}

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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define max 1000000000000000000
typedef uint64_t ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == 0){
            cout<<"0";
            return 0;
        }
    }
    ll ans=1;
    for(ll i=0;i<n;i++){
        if(a[i] <= max/ans ){
            ans *= a[i];
        }
        else{
            cout<<"-1";
            return 0;
        }

    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> res(n,0);
	vector<int> p;
	REP(i, n) {
		if (s[i] == 'R' && s[i + 1] == 'L') {
			p.push_back(i);
		}
	}
	REP(i, p.size()) {
 		int cr = 0,cl = 0;
		for (int j = p[i]-1;j>=0; --j) {
			if (s[j] == 'R') {
				cr++;
			}
			else {
				break;
			}
		}
		for (int j = p[i] + 2; j < n; ++j) {
			if (s[j] == 'L') {
				cl++;
			}
			else {
				break;
			}
		}
		res[p[i]] += cr/2+(cl+1)/2+1;
		res[p[i]+1] += (cr+1)/2+cl/2+1;
	}
	put(res);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
int MOD=1000000007;
using namespace std;
long long b[100005]={0};
long long PowerMod(long long a, long long b, long long c)
{
    long long ans = 1;
    a = a % c;
    while(b>0) {
        if(b % 2 == 1)
        ans = (ans * a) % c;
        b = b/2;
        a = (a * a) % c;
    }
    return ans;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		b[x]++;
	}
	if(n%2==0)
	{
		for(int i=1;i<=n-1;i=i+2)
		{
			if(b[i]!=2)
			{
				cout<<"0"<<endl;
				return 0;
			}
		}
	}
	else
	{
		for(int i=2;i<=n-1;i+=2)
		{
			if(b[i]!=2)
			{
				cout<<"0"<<endl;
				return 0;
			}
		}
		if(b[0]!=1)
		{
			cout<<"0"<<endl;
			return 0;
		}
	}
	cout<<PowerMod(2,n/2,MOD)<<endl;
	return 0;
} 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int N, ans,a;
multiset<int> S;
int main(){
    cin>>N;
    for (int i=1; i<=N; i++) {
        scanf("%d", &a);
        S.insert(a);
    }
    while (!S.empty()){
        int t = *(--S.end()), k;
        S.erase(--S.end());
        for (k=1; k<=t; k<<=1);
        if (S.find(k-t) != S.end()){
            ans++;
            S.erase(S.find(k-t));
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

vector<string> F;
vector<int> sft;

void f(string s) {
    if (s.size() == 10) return;
    F.push_back(s);
    f(s + "3");
    f(s + "5");
    f(s + "7");
    return;
}

void judge(string s) {
    bool j = false;
    rep(i, s.size()) if (s[i] == '3') j = true;
    if (!j) return;
    j = false;
    rep(i, s.size()) if (s[i] == '5') j = true;
    if (!j) return;
    j = false;
    rep(i, s.size()) if (s[i] == '7') j = true;
    if (!j) return;
    
    int S = stoi(s);
    sft.push_back(S);
    return;
}

int main() {
    int N;
    cin >> N;
    
    f("3");
    f("5");
    f("7");
    for (auto x : F) judge(x);
    sort(sft.begin(), sft.end());
    int cnt = 0;
    for (int x : sft) if (x <= N) ++cnt;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 2428
#include <cstdio>

int main() {
  char S[131072];
  scanf("%s", S);

  char alph[26]={};
  for (int i=0; S[i]; ++i)
    ++alph[S[i]-'a'];

  for (int i=0; i<26; ++i)
    if (alph[i] == 0)
      return !printf("%c\n", i+'a');

  printf("None\n");
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>

using namespace std;

struct State {
    int step;
    int x;
    int y;

    State() {
        step = 0;
        x = 0;
        y = 0;
    }

    State(int step, int x, int y): step(step), x(x), y(y) {}
};

const int MAX_N = 1000;
const int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, { -1, 0}};
char board[MAX_N][MAX_N];
int W, H, N;
State pos[10];

void init();
void input();
void solve();
int bfs(State from, State to);
void findPossition();

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    init();
    input();
    solve();
    return 0;
}

void init() {
}

void input() {
    scanf("%d %d %d", &H, &W, &N);

    for(int i = 0; i < H; i++) {
        scanf("%s", board[i]);
    }
}


void solve() {
    int moves = 0;
    findPossition();

    for(int i = 0; i < N; i++) {
        moves += bfs(pos[i], pos[i + 1]);
    }

    printf("%d\n", moves);
}

int bfs(State from, State to) {
    queue<State> que;
    bool visit[H][W];
    State cur = from;

    for(int i = 0; i < H; i++) {
        memset(visit[i], false, sizeof(visit[i]));
    }

    que.push(cur);

    while(!que.empty()) {
        cur = que.front();
        que.pop();

        if(visit[cur.x][cur.y]) {
            continue;
        }
        
        visit[cur.x][cur.y] = true;

        if(cur.x == to.x && cur.y == to.y) {
            break;
        }

        for(int i = 0; i < 4; i++) {
            int x = cur.x + dir[i][0];
            int y = cur.y + dir[i][1];

            if(x < 0 || x >= H || y < 0 || y >= W || visit[x][y] || 'X' == board[x][y]) {
                continue;
            }

            que.push(State(cur.step + 1, x, y));
        }
    }

    return cur.step;
}

void findPossition() {
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            int c = board[i][j];

            if('S' == c) {
                pos[0] = State(0, i, j);
            }

            if(isdigit(c)) {
                pos[c - '0'] = State(0, i, j);
            }
        }
    }
}

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

#define int ll
#define pb push_back
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main()
{
    IOS;
    int sx,sy,tx,ty,dx,dy;
    cin>>sx>>sy>>tx>>ty;
    dx = tx - sx;
    dy = ty - sy;
    FOR(i,0,dy) cout<<"U";
    FOR(i,0,dx) cout<<"R";
    FOR(i,0,dy) cout<<"D";
    FOR(i,0,dx) cout<<"L";
    cout<<"L";
    FOR(i,0,dy) cout<<"U";
    cout<<"U";
    cout<<"R";
    FOR(i,0,dx) cout<<"R";
    cout<<"D";
    cout<<"R";
    FOR(i,0,dy) cout<<"D";
    cout<<"D";
    cout<<"L";
    FOR(i,0,dx) cout<<"L";
    cout<<"U";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String s = scan.next();
        String t = scan.next();
        String u = scan.next();
        
        if(s.charAt(s.length()-1) == t.charAt(0) && t.charAt(t.length()-1) == u.charAt(0))
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_set>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    ll r=0,g=0,b=0;
    
    for(int i = 0; i < n; i++){
        if(s[i] == 'R')
        r++;
        else if(s[i] == 'G')
        g++;
        else
        b++;
    }
   
    ll total = r*g*b;
    ll cnt = 0;
    
    for(int i = 0; i<n;i++){
        for(int j =i;j<n;j++){
                 
                 if(s[i] == 'R' && s[j] == 'G' && s[j*2-i] == 'B')
                 cnt++;
                 else if(s[i] == 'B' && s[j] == 'R' && s[j*2-i] == 'G' )
                 cnt++;
                 else if(s[i] == 'R' && s[j] == 'B' && s[j*2-i] == 'G')
                 cnt++;
                 else if(s[i] == 'G' && s[j] == 'R' && s[j*2-i] == 'B')
                 cnt++;
                 else if(s[i] == 'G' && s[j] == 'B' && s[j*2-i] == 'R')
                 cnt++;
                 else if(s[i] == 'B' && s[j] == 'G' && s[j*2-i] == 'R')
                 cnt++;
            
        }
    }
    
    cout << total - cnt;
    
}









Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i < n + 1; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V a(n + 1);
    int count = 0;
    REP1(i, n)
    {
        cin >> a[i];
        if (i % 2 != 0 && a[i] % 2 != 0)
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int n,m,nsum,msum,s;
  scanf("%d""%d",&n,&m);
  if(n < 2)
  nsum = 0;
  else if(n > 1)
  nsum = n*(n-1)/2;

  if(m < 2)
  msum = 0;
  else if(m > 1)
  msum = m*(m-1)/2;

  s = nsum + msum;

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

  return 0;
}


Measured memory_bytes: 1732
package main

import "fmt"

func c(ss []string, y, x int) bool {
	if x < 0 || y < 0 || y >= len(ss) || x >= len(ss[y]) {
		return false
	}
	return ss[y][x] == '#'
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	ss := make([]string, h)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	for y := range ss {
		for x := range ss[y] {
			if ss[y][x] == '#' && !c(ss, y-1, x) && !c(ss, y+1, x) && !c(ss, y, x-1) && !c(ss, y, x+1) {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()

using namespace std;

int main(void){
    int a,b;

    cin >> a >> b;

    if((a*b)%2 == 0) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	string T;
	cin >> T;
	int length = T.length();
	for(int i = 0; i < length; i++){
		if(T[i] == '?'){
			T[i] = 'D';
		}
	}
	cout << T << endl;
	return 0;
}

Measured memory_bytes: 3748
import java.util.*;
class Main
{
    static int MOD = 1000000007;
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();

        int[] cntA = new int[n+1];
        int[] cntB = new int[n+1];
        int[] cntC = new int[n+1];
        int[] cntQ = new int[n+1];
        cntA[0] = cntB[0] = cntC[0] = cntQ[0] = 0;
        for(int i = 1; i < n+1; i++){
            char c = s.charAt(i-1);
            cntA[i] = cntA[i-1];
            cntB[i] = cntB[i-1];
            cntC[i] = cntC[i-1]; 
            cntQ[i] = cntQ[i-1];           
            switch(c){
                case 'A':
                    cntA[i]++;
                    break;
                case 'B':
                    cntB[i]++;
                    break;
                case 'C':
                    cntC[i]++;
                    break;
                default:
                    cntQ[i]++;
                    break;

            }
        }
        long ans = 0;
        long left;
        long right;
        for(int i = 0; i < n; i++){
            left = right = 0;
            if(s.charAt(i) == 'B' || s.charAt(i) == '?'){
                left += cntA[i+1] * pow3(cntQ[i]) % MOD;
                left += cntQ[i] * pow3(cntQ[i] - 1) % MOD;
                left %= MOD;
                right += (cntC[n] - cntC[i+1]) * pow3(cntQ[n] - cntQ[i+1]) % MOD;
                right += (cntQ[n] - cntQ[i+1]) * pow3(cntQ[n] - cntQ[i+1] - 1) % MOD;
                right %= MOD;
                ans += left * right % MOD;
                ans %= MOD;
            }
        }
        System.out.println(ans);
    }
    static long pow3(int n){
        if(n < 0) return 0;
        if(n == 0) return 1;
        if(n % 2 == 0){
            long d = pow3(n / 2);
            return d * d % MOD;
        }
        return 3 * pow3(n-1) % MOD;
    }
}

Measured memory_bytes: 26780
import java.util.*;

public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] s = new int[15];
    int[] h = new int[15];
    int[] c = new int[15];
    int[] d = new int[15];
    String egara;
    int figure;
   for(int i=0;i<15;i++){
       s[i]=0;
       h[i]=0;
       c[i]=0;
       d[i]=0;
   }
   for(int i=0;i<n;i++){
       egara=sc.next();
       figure=sc.nextInt();
       if(egara.equals("S")) s[figure]=1;
       else if(egara.equals("H")) h[figure]=1;
       else if(egara.equals("C")) c[figure]=1;
       else if(egara.equals("D")) d[figure]=1;
   }
   for(int i=1;i<14;i++){
       if(s[i]==0) System.out.println("S "+i);
   }
   for(int i=1;i<14;i++){
    if(h[i]==0) System.out.println("H "+i);
}
for(int i=1;i<14;i++){
    if(c[i]==0) System.out.println("C "+i);
}
for(int i=1;i<14;i++){
    if(d[i]==0) System.out.println("D "+i);
}
}
}


Measured memory_bytes: 26340
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt(), N = sc.nextInt(), minDiff = X, pNot[] = new int[102], ans = 0;
		for (int i = 0; i <= 101; i++)
			pNot[i] = 1;
		for (int i = 0; i < N; i++)
			pNot[sc.nextInt()] = 0;
		for (int i = 0; i <= 101; i++)
			if (pNot[i] == 1)
				if (minDiff > Math.abs(X - i)) {
					minDiff = Math.abs(X - i);
					ans = i;
				}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35676
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import fractions
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

#2で何回割れるかを数える関数
def t_per2(k):
    return format(k,'b')[::-1].find('1')

def main():
    n,m = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    k2 = t_per2(a[0])
    l = a[0]//2
    for ai in a[1::]:
        if not k2 == t_per2(ai):
            print(0)
            exit()
        l = l*(ai//2)//(fractions.gcd(l,ai//2))
        if l > m:
            print(0)
            exit()
    print((m+l)//(2*l))
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 82412
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = Integer.parseInt(sc.nextLine())
        if (n < 1 || n > 100) {
            throw Exception("Illegal input.")
        }
        val a = sc.nextLine()
                .split(" ")
                .map { Integer.parseInt(it) }
                .toIntArray()
        val sortedAAndCount: Pair<IntArray, Int> = selectionSort(a)
        println(sortedAAndCount.first.joinToString(" "))
        println(sortedAAndCount.second)
    } catch (e: Exception) {
        println(e)
    }
}
fun selectionSort(a: IntArray): Pair<IntArray, Int> {
    var c = 0
    for (i in 0 until a.size) {
        var minI = i
        for (j in i until a.size) {
            if (a[j] < a[minI]) {
                minI = j
            }
        }
        if (i == minI) continue
        val tmp = a[i]
        a[i] = a[minI]
        a[minI] = tmp
        c++
    }
    return a to c
}



Measured memory_bytes: 33376
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let (N, i): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = N - i + 1;

    println!("{}", ans);
}


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

/* 平面幾何の基本要素 */
 
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS )
 
class Point { // 点を表すクラス
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  
  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

typedef Point Vector; // ベクトルを表す構造体

struct Segment { // 線分を表す構造体
  Point p1,p2;
};

typedef Segment Line; // 直線を表す構造体

class Circle { // 円を表すクラス
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0): c(c),r(r) {}
};
typedef vector < Point > Polygon; // 多角形

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}
 
double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
 
int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
 
  if( cross(a,b) > EPS ) return COUNTER_CLOCKWISE;
  if( cross(a,b) < -EPS ) return CLOCKWISE;
  if( dot(a,b) < -EPS ) return ONLINE_BACK;
  if( a.norm() < b.norm() ) return ONLINE_FRONT;
 
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return ( ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 && 
	   ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s2.p1,s1.p2,s2.p2);
}

int contains(Polygon g,Point p){
  int n = g.size();
  bool x = false;
  for(int i=0;i<n;i++){
    Point a = g[i] - p, b = g[(i+1)%n] - p;
    if(abs(cross(a,b)) < EPS && dot(a,b) < EPS) return 1;
    if(a.y > b.y) swap(a,b);
    if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
  }
  return (x ? 2 : 0);
}

/*
double distance( Point p1,Point p2){
  return sqrt( (p1.y - p2.y) * (p1.y - p2.y) + (p1.x - p2.x) * (p1.x - p2.x));
}
*/

double distance( double y1, double x1, double y2, double x2){
  return sqrt( (y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));
}

int main(){
  Point p1,p2,p3,p4;
  double ra,rb;
  int n;
  cin >> n;
  while(n--){
    cin >> p1.x >> p1.y >> ra >> p2.x >> p2.y >> rb;
    double d = distance(p1.y,p1.x,p2.y,p2.x);
    int ret = 1;
    if(d > ra + rb) ret = 0;
    if(d + ra < rb) ret = -2;
    if(d + rb < ra) ret = 2;
    cout << ret << endl;
  }
}

Measured memory_bytes: 1232
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

vector <vector <int>> gr;
vector <int> col;

int dfs(int v, int cur) {
    col[v] = cur;
    int ans = 1;
    for (int u : gr[v])
        if (!col[u])
            ans += dfs(u, cur);
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    gr.resize(n);
    forn (i, 0, m) {
        int v, u;
        cin >> v >> u, --v, --u;
        gr[v].pb(u), gr[u].pb(v);
    }
    vector <vector <int>> blocks(n);
    forn (i, 0, k) {
        int v, u;
        cin >> v >> u, --v, --u;
        blocks[v].pb(u), blocks[u].pb(v);
    }

    vector <int> cnt = {0};
    int cur = 0;
    col.resize(n);
    forn (i, 0, n)
        if (!col[i])
            cnt.pb(dfs(i, ++cur));

    //cout << cnt << "\n";

    forn (i, 0, n) {
        unordered_set <int> friends;
        for (int j : gr[i])
            if (col[j] == col[i])
                friends.insert(j);
        int ans = cnt[col[i]] - gr[i].size() - 1;
        //cout << ans << " ";
        for (int j : blocks[i])
            if (col[j] == col[i] && friends.find(j) == friends.end())
                ans--;
        cout << ans << " ";
    }
    return 0;
}


Measured memory_bytes: 16016
dd = {}
n, m = map(int, input().split())
for _ in range(m):
    a, b = map(int, input().split())
    dd[a] = dd.get(a,0) + 1
    dd[b] = dd.get(b,0) + 1
for i in range(1, n+1):
    print(dd.get(i, 0))

Measured memory_bytes: 3060
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = [input() for _ in range(n)]
    b = [input() for _ in range(m)]
    for i in range(n-m+1):
        for j in range(n-m+1):
            flag = False
            for k in range(m):
                for l in range(m):
                    if a[i+k][j+l] != b[k][l]:
                        flag = True
                        break
                if flag:
                    break
            if not flag:
                break
        if not flag:
            break
    if not flag:
        print('Yes')
    else:
        print('No')
                
    

            

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9156