akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin,(x).end()
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define fastCin ios::sync_with_stdio(false)
typedef vector<int> vi;
typedef vector<char> vc;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const db pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e6+10;
const int inf=1e9;
const int d[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll quickpow(ll x,ll k) //x^k
{
	ll ans=1;
	while (k)
	{
		if (k&1) ans=ans*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ans;
}
int h,w,k;
int x,y,x2,y2;
vc ch[maxn];
vi dis[maxn];
queue<pii> q;

void bfs()
{
	dis[x][y]=0;
	q.push(mp(x,y));
	while (!q.empty())
	{
		int X=q.front().first,Y=q.front().second;
//		cout<<X<<' '<<Y<<' '<<dis[X][Y]<<endl;
		q.pop();
		rep(i,0,3)
		{
			int nx=X,ny=Y,nd=dis[X][Y]+1;
			rep (j,1,k)
			{
				nx+=d[i][0],ny+=d[i][1];
				if (nx<=0 || ny<0 || nx>h || ny>=w || ch[nx][ny]=='@' || dis[nx][ny]<nd) break;
				if (dis[nx][ny]>nd)
				{
					dis[nx][ny]=nd;
					q.push(mp(nx,ny));
				}
			}
		}
	}
}

int main()
{
	fastCin;
	cin>>h>>w>>k;
	cin>>x>>y>>x2>>y2;
	y--;y2--;
	rep(i,1,h)
		rep(j,1,w)
		{
			char c;
			cin>>c;
			ch[i].pb(c);
			dis[i].pb(inf);
		}
	bfs();
	if (dis[x2][y2]==inf) cout<<"-1\n";else cout<<dis[x2][y2]<<"\n";
	return 0;
}


Measured memory_bytes: 57860
import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  def solve: Unit = {
    val sc = new Scanner(System.in)
    val H, W = Integer.parseInt(sc.next)
    val A: Seq[String] = (1 to H).map(h => sc.next)

    val queue: mutable.Queue[(Int, Int)] = new mutable.Queue()
    queue.enqueue((0, 0))
    while (queue.length > 0) {
      val cur = queue.dequeue()
      if (cur._1 > 0 && A(cur._1 - 1)(cur._2) == '#' && cur._2 > 0 && (A(cur._1)(cur._2 - 1) == '#')) {
        println("Impossible")
        return
      }

      if (cur._1 + 1 < H && A(cur._1 + 1)(cur._2) == '#') {
        queue.enqueue((cur._1 + 1, cur._2))
      }
      if (cur._2 + 1 < W && A(cur._1)(cur._2 + 1) == '#') {
        queue.enqueue((cur._1, cur._2 + 1))
      }
      if (queue.length == 2) {
        println("Impossible")
        return
      }
      if (cur._1 == H - 1 && cur._2 == W - 1){
        println("Possible")
        return
      }
    }
    println("Impossible")
  }

  solve
}


Measured memory_bytes: 27840
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int s,w;
void input()
{
    cin>>s>>w;
}

void solve()
{
    if(w>=s) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
A,B = map(int,input().split())
if A != 1 and B != 1:
  if A > B:
    print("Alice")
  elif A == B:
    print("Draw")
  else:
    print("Bob")
    
else:
  if A > B:
    print("Bob")
  elif A == B:
    print("Draw")
  else:
    print("Alice")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
/*
ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}*/

string s;

int main(){
	cin>>s;
	for(auto c:s) cout<<(c=='?'?'D':c);
	cout<<endl;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mod 998244353
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a%mod*a%mod)%mod;
	}
	return ans;
}//prefixsums
void frooty()
{
	l a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
	{
		cout<<k<<"\n";
	}
	else if(k<=a+b)
	{
		cout<<a<<"\n";
	}
	else
	{
		cout<<a-(k-(a+b))<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
//	cin>>q;
	while(q--)
	{
		frooty();
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * Library
 * --------------------------------------------------------
 */
template<class Monoid>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation to merge `data`
     * @param updater operation to update `data`
     */
    SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
                function<Monoid(Monoid, Monoid)> updater)
            : e(e), operation(operation), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<Monoid>(2 * n - 1, e);
        for (int i = n - 2; i >= 0; i--) {
            data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
        }
    }

    /**
     * iの値をxに更新 ( 0-indexed )
     */
    void update(int i, Monoid x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    Monoid query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス( 0-indexed )
     */
    Monoid operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<Monoid> data;
    Monoid e;
    function<Monoid(Monoid, Monoid)> operation;
    function<Monoid(Monoid, Monoid)> updater;

    Monoid query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};


void Main() {
    ll N;
    cin >> N;
    vector<ll> P(N);
    rep(i, N) cin >> P[i];
    vector<ll> A(N);
    SegmentTree<ll> segmentTree(N + 1, 0, [](ll a, ll b) { return max(a, b); }, [](ll a, ll b) { return max(a, b); });
    rep(i, N) {
        ll a = P[i];
        segmentTree.update(a, segmentTree.query(a - 1, a) + 1);
    }
    ll k = segmentTree.query(0, N + 1);
    cout << N - k << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7552
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()

scc = min(n, m // 2)
n, m = 0, m - 2 * scc
scc2 = m // 4

print(scc + scc2)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    if(a[0] > a[1]){
        int tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    
    if(a[1] > a[2]){
        int tmp = a[1];
        a[1] = a[2];
        a[2] = tmp;
    }
    
    if(a[0] > a[1]){
        int tmp = a[0];
        a[0] = a[1];
        a[1] = tmp;
    }
    
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    vector<int> g(n + 1, 0);
    rep(i, m)
    {
        int l, r; cin >> l >> r; --l;
        g[l]++;
        g[r]--;
    }

    rep(i, n) g[i + 1] += g[i];
    int ans = 0;
    rep(i, n) if (g[i] == m) ans++;
    cout << ans << endl;
}

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

int main(){
  long long int N;
  long long int A[5];
  cin >> N;
  long long int min=1000000000000005;
  for(int i=0;i<5;i++) {
    cin >> A[i];
    if(min>A[i]) min=A[i];
  }
  cout << std::setprecision(16) << 4+ceil((long double)(N)/(long double)min);
}


Measured memory_bytes: 256
N = gets.to_i
C = gets.chars.map{|s| s=="R"?0:1}

l=0
r=N-1

ans = 0
while l<r
    if C[l] == 0 then 
        l+=1 
        next 
    end
    if C[r] == 1 then 
        r-=1 
        next 
    end

    ans += 1
    l += 1
    r -= 1
end

p ans

Measured memory_bytes: 31952
from collections import deque
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
ki=[[] for f in range(N)]
for i in range(M):
 A,B= map(int,input().split())
 ki[A-1].append(B-1)
 ki[B-1].append(A-1)
stack = deque([0])
check = [0]*N #チェック済みリスト
check[0] = 1
ans=[0]*(N-1)
while stack != deque([]) :
 a=stack.popleft()
 for i in range(len(ki[a])):
  if check[ki[a][i]]==0:
   stack.append(ki[a][i])
   check[ki[a][i]]=1
   ans[ki[a][i]-1]=a+1
print("Yes")
for i in range(N-1):
 print(ans[i])


Measured memory_bytes: 37520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
int main()
{
    int n,d,ans;
    cin>>n>>d;
    ans=n/(d*2+1);
    if(n%(d*2+1)!=0) ans++;
    cout<<ans;
}

Measured memory_bytes: 3592
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    };
    let s_chars: Vec<char> = s.chars().collect();
    let t_chars: Vec<char> = t.chars().collect();
    let s_len = s_chars.len();
    let t_len = t_chars.len();
    // let mut dp = vec![vec![0; t_chars.len() + 1]; s_chars.len() + 1];
    let mut ans = -10000000;
    for i in 0..s_len - t_len + 1 {
        let mut temp = 0;
        for j in 0..t_len {
            if s_chars[i + j] == t_chars[j] {
                temp += 1;
            }
        }
        ans = ans.max(temp);
    }
    println!("{}", t_len as i64 - ans);

    // for i in 0..t_len {
    //     for j in i..s_len - t_len + 1 + i {
    //         dp[j + 1][i + 1] = dp[j][i] + if t_chars[i] == s_chars[j] { 1 } else { 0 };
    //     }
    // }
    // println!("{}", t_len as i64 - *dp[s_len].iter().max().unwrap());
}


Measured memory_bytes: 2168
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 3e2 + 5, M = 50 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;
int n, sushi[4];
ld memo[N][N][N];
ld solve(int i, int j, int k)
{
    if(!i && !j && !k)
        return 0;
    ld &ret = memo[i][j][k];
    if(ret != -1.0)
        return ret;
    ret = 1.0;
    if(i)
        ret += 1.0 * i / n * solve(i - 1, j, k);
    if(j)
        ret += 1.0 * j / n * solve(i + 1, j - 1, k);
    if(k)
        ret += 1.0 * k / n * solve(i, j + 1, k - 1);
    ret *= (1.0 * n / (i + j + k));
    return ret;
}
int main()
{
    MuhammedAly
    for(int i = 0 ; i < N ; i++)
        for(int j = 0 ; j < N ; j++)
            for(int k = 0 ; k < N ; k++)
                memo[i][j][k] = -1.0;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        int x;
        cin >> x;
        sushi[x]++;
    }
    cout << fixed << setprecision(9) << solve(sushi[1], sushi[2], sushi[3]);
    return 0;
}

Measured memory_bytes: 443648
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int n, m;
  while(cin >> n,n) {
    cin >> m;
    string s; cin >> s;
    vector<int> io;
    int cnt = 0;
    bool I = true;
    FOR(i,0,m) {
      if(I && s[i] == 'I') {
        cnt++;
        I ^= 1;
      } else if(!I && s[i] == 'O') {
        cnt++;
        I ^= 1;
      } else {
        if(I) cnt--;
        if(cnt > 0) io.push_back(cnt);
        if(s[i] == 'I') {
          cnt = 1;
          I = false;
        }
        else {
          cnt = 0;
          I = true;
        }
      }
    }
    //FOR(i,0,io.size()) cout << io[i] << endl;
    if(cnt != 0) io.push_back(cnt);
    int ans = 0;
    n = 2 * n + 1;
    FOR(i,0,io.size()) {
      int x = io[i] - (n - 1);
      if(x >= 1) ans += (x + 1) / 2;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)|(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[300005];
ll z[65];
ll o[65];
vector<ll>kola;
int main()
{
    fastread;
    ll n,i,j,k,l,m;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];

    ll maxi=log2(a[n]);
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=61;j++)
        {
            if((a[i])&(1LL<<j))
                o[j]++;
            else
                z[j]++;
        }
    }

    ll sum=0;
    for(j=0;j<=61;j++)
    {
        ll temp=((z[j]%mod)*(o[j]%mod))%mod;
        sum=(sum%mod+(((temp%mod)*((1LL<<j)%mod))%mod)%mod)%mod;
    }
    sum=sum%mod;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int m[] = new int [n];
    int count = 0;
    for(int i = 0;i < n;i++){
      m[i] = sc.nextInt();
    }
    Arrays.sort(m);
    for(int i = 0;i < n;i++){
      x -= m[i];
      count++;
    }
    while(x >= 0){
      x -= m[0];
      count++;
    }
    count--;
    System.out.println(count);
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int A[3], min_a = INF, max_a = 0;
	rep(i, 3) {
		cin >> A[i];
		min_a = min(min_a, A[i]);
		max_a = max(max_a, A[i]);
	}
	cout << max_a - min_a << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,s,ans;
int main()
{
	cin>>n;ans=-1;
	while(n--)
	{
		long long x,c;
		cin>>x>>c;
		s+=x*c;ans+=c;
	}
	s--;
	while(s)
	{
		ans+=(s/=9);
		break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
public class Main {
	public static void main(String[] args) {
      Map<String, String> convert = new HashMap<>();
	convert.put("A", "T");
	convert.put("T", "A");
	convert.put("G", "C");
	convert.put("C", "G");
      
      try (Scanner scan = new Scanner(System.in)) {
        String input = scan.next();
        System.out.println(convert.get(input));
      }  
    }
}

Measured memory_bytes: 21332
#include<stdio.h>

void selectionSort(int A[],int N){ // N??????????´??????????0-?????????????????????
    int i = 0;
    int j = 0;
    int minj = 0;
    int temp = 0;
    int counter = 0; 
    for(i = 0; i < N; i++){
         minj = i;
         for(j = i; j < N; j++){
            if(A[j] < A[minj]) minj = j;
         } 
        if(i!=minj){
                temp = A[i];
                A[i] = A[minj];
                A[minj] = temp;
                counter++;
        
         }
    }
    for(i = 0;i < N; i++){
        if(i!=0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", counter);
    return;
}


int main(void){
    int i = 0;
    int N = 0;
    int A[100];
    scanf("%d\n", &N);
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    selectionSort(A, N);
    return 0;
}

Measured memory_bytes: 1808
/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e5+10;

int main(){
    int l,r,d;
    in>>l>>r>>d;
    int cnt=0;
    rep(i,l,r)if(i%d==0)++cnt;
    out<<cnt;
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>

using namespace std;

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

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n;
  cin>>n;
  bool flag=false;
  rep(i,1,10){
    rep(j,1,10){
        if(i*j==n){
            flag=true;
            break;
        }
    }
  }
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] lst = new int[n];
        int one_weigh = 0;
        int two_weigh = 0;
        int div = 0;
        for(int a=0; a<n; a++){
            lst[a] = Integer.parseInt(scan.next());
        }
        for(int a=0; a<n; a++){
            two_weigh += lst[a];
        }
        for(int a=0; a<n; a++){
            div = one_weigh - two_weigh;
            one_weigh += lst[a];
            two_weigh -= lst[a];
            if(one_weigh - two_weigh==0){
                System.out.println(0);
                break;
            }else if(one_weigh - two_weigh>0){
                if(div*(-1)>one_weigh - two_weigh){
                    System.out.println(one_weigh - two_weigh);
                }else{
                    System.out.println(div*(-1));
                }
                break;
            }
        }
    }
}

Measured memory_bytes: 22608
#include <stdio.h>

#define MAX_N 100002

typedef struct { char *p; int tm; } Q;
Q que[(MAX_N<<1)+2]; int top, end;
char name[MAX_N][20];

char buf[20], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int  n, q, tm, i;
	Q  t;

	fgets(p=buf, 20, stdin);
	n = in(), q = in();
	for (i = 0; i < n; i++) {
		fgets(p=name[i], 20, stdin);
		while (*p > ' ') p++; *p++ = 0;
		que[i].p = name[i], que[i].tm = in();
	}

	tm = 0, top = 0, end = n;
	while (top != end) {
		t = que[top]; if (++top == MAX_N) top = 0;
		if (t.tm <= q) {
			printf("%s %d\n", t.p, tm+t.tm);
			tm += t.tm;
		} else {
			t.tm -= q;
			que[end] = t; if (++end == MAX_N) end = 0;
			tm += q;
		}
	}
	return 0;
}


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

int main() {
    string line;
    int cnt, spos;
    bool first = true;

    getline(cin, line);
    line += " ";
    cnt = 0;
    for (int i = 0, l = line.size()-1; i < l; i++) {
        if (line[i] != ' ' && line[i] != '.' && line[i] != ',') {
            if (cnt == 0) spos = i;
            cnt++;
        }
        else {
            if (2 < cnt && cnt < 7) {
                if (!first) cout << " ";
                first = false;
                cout << line.substr(spos, cnt);
            }
            cnt = 0;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

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


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

    if ((N%1000)==0) {
        cout<< 0 <<endl;
    } else {
        cout<< 1000-(N%1000) <<endl;
    }
}

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

using namespace std;

int Q;
deque<char> s;
string tmp;

int main()
{
    cin >> tmp;
    for (char c : tmp) s.push_back(c);
    int dir = 1;
    cin >> Q;
    while (Q--)
    {
        int T;
        cin >> T;
        if (T == 1) dir = -dir;
        else
        {
            int F;
            char C;
            cin >> F >> C;
            if (F == 1)
            {
                if (dir == -1) s.push_back(C);
                else s.push_front(C);
            }
            else
            {
                if (dir == -1) s.push_front(C);
                else s.push_back(C);
            }
        }
    }
    if (dir == 1)
        while (s.size() > 0) { cout << s.front(); s.pop_front(); }
    else
        while (s.size() > 0) { cout << s.back(); s.pop_back(); }
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#define INF 10000
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m,n){
        vector<int>V(n);
        for(int i=0;i<n;i++)V[i]=i+1;
        for(int i=0;V.size()>1;V.erase(V.begin()+i))if(i+=(m-1)%V.size(),i>=V.size())i-=V.size();
        cout<<V[0]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)




using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	cin2(n,m);

	if (n == 2 and m == 2) {
		cout("Yes");
	}else if (n == 2 or m == 2) {
		cout("No");
	}else if ((n == 4 or n == 6 or n == 9 or n == 11) and
		(m == 4 or m == 6 or m == 9 or m == 11)) {
		cout("Yes");		
	}else if ((n == 1 or n == 3 or n == 5 or n == 7 or n == 8 or n == 10 or n == 12) and 
				(m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m ==12)) {
		cout("Yes");		
	}else {
		cout("No");
	}

	
	return 0;
}





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

void solve()
{
	string s,t;
	cin>>s>>t;
	if(s.length()+1==t.length()&&(t.substr(0,s.length())==s))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
    long long a, b, c, d, res;
    cin >> a >> b >> c >> d;
    res = max(a * c, a * d);
    res = max(b * c, res);
    res = max(b * d, res);
    if (a * b < 0 && c * d < 0 && res < 0) res = 0;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e15;
const int L=200;
inline ll power(ll x,ll y) {
	ll ans=1;
	while (y--) ans*=x;
	return ans;
}
inline ll f(ll a,ll b) {
	double a0=a,b0=b;
	double k=(a0-b0)*(a0*a0*a0*a0+a0*a0*a0*b0+a0*a0*b0*b0+a0*b0*b0*b0+b0*b0*b0*b0);
	if (k>INF) return INF;
	else return (a-b)*(a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b);
}
int main() {
	ll i,j,x,l,r,mid,c,b;
	cin>>x;
	for (i=0;i<=L;i++)
		for (j=0;j<=L;j++)
			if (power(i,5)+power(j,5)==x) {
				cout<<i<<' '<<-j<<endl;
				return 0;
			}
//	cout<<f(4,1)<<endl;
	for (i=1;i*i<=x;i++)
		if (x%i==0) {
			for (b=0;b<=L;b++)
				if (f(b+i,b)==x) {
					cout<<b+i<<' '<<b<<endl;
					return 0;
				}
				else if (f(b+x/i,b)==x) {
					cout<<b+x/i<<' '<<b<<endl;
					return 0;
				}
		}
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1100;
int a[maxn];
int main(){
	int n, m;
	//freopen("in.txt", "r", stdin);
	while(cin >> n >> m){
		memset(a, 0, sizeof a);
		if (n == 0 && m == 0) break;
		int ans = -1;
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				int temp; cin >> temp;
				a[j] += temp;
			}
		}
	//sort(a, a + n, less<int>());
	for(int i = 0; i < n; i++){
		ans = max (ans, a[i]);
	}
	printf("%d\n", ans);
}
}


Measured memory_bytes: 3152
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
map<string,int> c;
int main(){
	fastio;
	int n;
	cin>>n;
	rb(i,1,n)
		{
			string s;
			cin>>s;
			c[s]++;
		}
	cout<<"AC x "<<c["AC"]<<endl;
	cout<<"WA x "<<c["WA"]<<endl;
	cout<<"TLE x "<<c["TLE"]<<endl;
	cout<<"RE x "<<c["RE"]<<endl;
	
	return 0;
}


Measured memory_bytes: 3664
N = int(input())

nums = []
max = 0

for i in range(0, N):
    nums.append(int(input()))

mx = sum(nums)
if mx % 10 != 0:
    print(str(mx))
    quit()

checker = [False for i in range(0, mx+1)]

now = 0
res = 0
for i in range(0, N):
    v = nums[i]
    for j in range(now, -1, -1):
        if checker[j]:
            idx = j + v
            if idx > res and idx % 10 != 0:
                res = idx
            checker[idx] = True
    checker[v] = True
    now = now + v

print(str(res))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
char S[100010];
int f[100010],lst[100010][3];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	scanf("%s",S+1);int n=strlen(S+1);
	int R=1;while(R<n&&S[R+1]!=S[R])++R;
	for(int j=0;j<3;++j)lst[0][j]=-1;
	for(int i=1,s=0,L=0;i<=n;++i){
		for(int j=0;j<3;++j)lst[i][j]=lst[i-1][j];
		lst[i][s]=i-1;
		s=(s+S[i]-'a'+1)%3;
		if(S[i]==S[i-1])L=i-1;
		int p=lst[L][(s+1)%3],q=lst[L][(s+2)%3];
		if(S[i]=='b')p=i-1;else q=i-1;
		if(~p){
			inc(f[i],f[p]);
			if(p&&p<=R&&R<i)inc(f[i],p-1>>1);
		}
		if(~q){
			inc(f[i],f[q]);
			if(q&&q<=R&&R<i)inc(f[i],q-1>>1);
		}
		if(s&&(i==1||i>R))inc(f[i],1);
	}
	printf("%d\n",f[n]);
	return 0;
}


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

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    int result = 0;
    REP(A, N) {
        function<char(int, int)> T = [&](int i, int j) {
            return S[(i + A) % N][j];
        };
        bool is_symmetric = true;
        REP(i, N) FOR(j, i + 1, N) {
            if (T(i, j) != T(j, i)) {
                is_symmetric = false;
                break;
            }
        }
        if (is_symmetric) ++result;
    }
    result *= N;
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    vector <ll> fs;
    REP(i, n){
        ll f; cin >> f;
        fs.push_back(f);
    }
    sort(fs.begin(), fs.end());
    fs.push_back(0);
    reverse(fs.begin(), fs.end());
    ll ans = 0;
    ll beki = 0;
    ll cnt = 0;
    while(cnt <= n){
        if (pow(2, beki) == cnt){
            beki++;
            ans += fs[cnt/2];
        } else {
            ans += fs[(cnt+1)/2];
        }
        cnt++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5404
#include<bits/stdc++.h>
#define mp make_pair
// #define pb push_back
#define ll long long
#define endl "\n"
using namespace std;



int main() {
	ll n,wt;
	cin>>n>>wt;
	ll w[n],v[n];
	for(ll i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][1000*n+1];
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=1000*n;j++){
			if(j==0){
				dp[i][j]=0;
			}
			else if(i==0){
				dp[i][j]=1e9+7;
			}
			else if(j<v[i-1]){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-v[i-1]]);
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<=1000*n;i++){
		if(dp[n][i]<=wt){
			ans=i;
		}
	}
	cout<<ans<<endl;
}









Measured memory_bytes: 82500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  int s = 100 * r + 10 * g + b;
  if (s%4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" <<endl;
  }
  
  return 0;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const Int INF = 9999999999;

int main(){
    char a;
    cin >> a;
    a++;
    cout << a << endl;
}

Measured memory_bytes: 256
def euler_phi(n):
    if n == 1: return 1
    res = 1
    x = n
    y = 2
    while y*y <= x:
        k = 0
        while x%y == 0:
            k += 1
            x //= y
        if k: res *= y**(k-1)*(y-1)
        y += 1
    if x > 1: res *= x-1
    return res
    
N = int(input())
print(euler_phi(N))


Measured memory_bytes: 5596
#include <stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK -1

typedef struct {
  int number[MAX];
  int head;
  int tail;
} QUEUE;

int adj[MAX][MAX], d[MAX], color[MAX];
QUEUE Q;

void enqueue(int x){
  Q.number[Q.tail] = x;
  Q.tail++;
  
  if( Q.tail > MAX ) Q.tail = 0;
  
}

int dequeue(void){
  int x;
  
  x = Q.number[Q.head];
  Q.number[Q.head] = 0;
  Q.head++;
  
  return x;
  
}


void BFS(int n){
  int i, j, u;
  
  for( i = 1; i <= n; i++){
    color[i] = WHITE;
    d[i] = -1;
  }
  
  color[1] = GRAY;
  d[1] = 0;
  Q.head = 0;
  Q.tail = 0;
  
  enqueue(1);

  while( Q.head != Q.tail ){
    
    u = dequeue();
    
    // printf("{u} = %d\n", u);
    
    for( j = 1; j <= n; j++){
      if( adj[u][j] == 1 ){
	if( color[j] == WHITE ){
	  color[j] = GRAY;
	  d[j] = d[u] + 1;
	  //printf("d[%d] = %d\n", j, d[j]);
	  enqueue(j);
	}
      }
    }
    
    color[u] = BLACK;
    
  }
  
}


main(){
  int i, j, n, k, u, v;
  
  for( i = 0; i < MAX; i++){
    for( j = 0; j < MAX; j++){
      adj[i][j] = 0;
    }
  }
  
  scanf("%d", &n);
  
  for( i = 1; i <= n; i++){
    scanf("%d%d", &u, &k);
    for( j = 1; j <= k; j++){
      scanf("%d", &v);
      adj[i][v] = 1;
    }
  }
  
  /* 
     for( i = 1; i <= n; i++){
     for( j = 1; j <= n; j++){
     printf("%d ", adj[i][j]);
     }
     printf("\n");
     }
  */
  
  BFS(n);
  
  for( i = 1; i <= n; i++){
    printf("%d %d\n", i, d[i]);
  }
  
  return 0;
  
}

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

int main() {
int n, m;
  cin >> n >>m;
  vector<int> A(n);
  for(int i =0; i<n; ++i){
    cin >> A.at(i);
  }
  double  sum =0.0;
  for(int i =0; i<n;++i){
    sum += A.at(i);
  }
  int count = 0;
  for(int i = 0; i<n; ++i){
  if(A.at(i) >= sum/(4*m)) ++count;
  }
  if(count >= m) cout << "Yes"<< endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
	unsigned int n;
	cin >> n;
	unsigned int m = (unsigned int)(sqrt(n));
	cout << m * m << endl;
	return 0;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    map<ll, ll> mp;
    for (int i = 0; i < N; ++i) {
        int a;  cin >> a;
        ++mp[a];
    }
    int Q;  cin >> Q;
    ll sum = 0;
    for (auto e : mp) sum += e.first * e.second;
    for (int i = 0; i < Q; ++i) {
        int b, c;  cin >> b >> c;
        sum -= b * mp[b];
        sum += c * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
        // DUMP(mp);
    }
}


Measured memory_bytes: 9472
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    if (N == 2) {
      int A = sc.nextInt();
      int B = sc.nextInt();
      System.out.println(A + B);
    } else {
      System.out.println("Hello World");
    }

  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;

int main(){
    string s;
    bool ans;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if ( i % 2 == 0 && (s.at(i) == 'R' || s.at(i) == 'U' || s.at(i) == 'D')) {
            ans = true;
        }
        else if ( i % 2 == 1 && (s.at(i) == 'L' || s.at(i) == 'U' || s.at(i) == 'D')) {
            ans = true;
        }
        else {
            ans = false;
            break;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define W 0
#define G 1
#define B 2

int n,M[N][N],color[N],d[N],f[N],tt;

void d_v(int u){
  int v;
  color[u]=G;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==W)
    d_v(v);
   }
    color[u]=B;
    f[u]=++tt;
}

void dfs(){
  int u;

  for(u=0;u<n;u++)
      color[u]=W;
  tt=0;

  for(u=0;u<n;u++){
      if(color[u]==W)
           d_v(u);
  }

  for(u=0;u<n;u++)
    printf("%d %d %d\n",u+1,d[u],f[u]);
}


int main(){
  int u,v,k,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
     for(j=0;j<n;j++)
        M[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
return 0;
}


Measured memory_bytes: 2060
use std::cmp::max;
use std::collections::BTreeMap;

const INF: i64 = 1e16 as i64;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);

    let total_select = n / 2;
    let total_jump = n - total_select;

    let mut dp = BTreeMap::new();
    dp.insert((1, true), 0);
    dp.insert((0, false), a[0]);
    for i in 1..n {
        let a = a[i];
        let remain = n - (i + 1);
        let max_remain = (remain + 1) / 2;

        let mut next = BTreeMap::new();
        for ((jump_count, prev_jump), cur_max) in dp.into_iter() {
            let cur_count = i - jump_count;
            let can_jump = max_remain + cur_count >= total_select;
            if can_jump {
                let cur = next.entry((jump_count + 1, true)).or_insert(cur_max);
                if *cur < cur_max {
                    *cur = cur_max;
                }
            }
            if prev_jump {
                let cur = next.entry((jump_count, false)).or_insert(cur_max + a);
                if *cur < cur_max + a {
                    *cur = cur_max + a;
                }
            }
        }
        dp = next;
    }

    let mut ans = std::i64::MIN;
    if let Some(a) = dp.get(&(total_jump, true)) {
        ans = max(ans, *a);
    }
    if let Some(a) = dp.get(&(total_jump, false)) {
        ans = max(ans, *a);
    }

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

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String inStr) {
		// String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		String str = inStr;

		char[] cntChar = new char[26];
		for (char c : str.toCharArray()) {
			cntChar[c - 'a']++;
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < cntChar.length; i++) {
			if (cntChar[i] > 0) {
				int cnt = 0;
				for (str = inStr; isMix(str); str = Shrinking(str, (char) (i + 'a'))) {
					// System.out.println(str);
					cnt++;
				}
				if (cnt < ans)
					ans = cnt;
			}
		}

		System.out.println(ans);
	}

	private boolean isMix(String str) {
		char ctop = str.charAt(0);
		for (char c : str.toCharArray()) {
			if (c != ctop)
				return true;
		}
		return false;
	}

	private String Shrinking(String str, char pick) {
		String ans = "";
		for (int i = 0; i < str.length() - 1; i++) {
			if (str.charAt(i + 1) == pick)
				ans = ans + str.charAt(i + 1);
			else
				ans = ans + str.charAt(i);
		}
		return ans;
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


Measured memory_bytes: 40532
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import kotlin.math.*

fun main() {
    var fs = CodeForces.FastReader()
    var n = fs.next()
    var sum:Long = 0
    for (c in n.toCharArray()) {
        sum += Character.getNumericValue(c)
    }
    if(sum%9==0L) println("Yes")
    else println("No")
}
class CodeForces {
    internal class FastReader {
        private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
        private var st: StringTokenizer? = null

        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }

            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return Integer.parseInt(next())
        }

        fun nextLong(): Long {
            return java.lang.Long.parseLong(next())
        }

        fun nextDouble(): Double {
            return java.lang.Double.parseDouble(next())
        }

        fun nextLine(): String {
            var str = ""
            try {
                str = br.readLine()
            } catch (e: IOException) {
                e.printStackTrace()
            }
            return str
        }

        fun readIntArray(n: Int): IntArray {
            val a = IntArray(n)
            for (i in 0 until n) a[i] = nextInt()
            return a
        }

        fun readLongArray(n: Int): LongArray {
            val a = LongArray(n)
            for (i in 0 until n) a[i] = nextLong()
            return a
        }

        fun readDoubleArray(n: Int): DoubleArray {
            val a = DoubleArray(n)
            for (i in 0 until n) a[i] = nextDouble()
            return a
        }
    }
}


Measured memory_bytes: 38136