akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) {

		// ストリームを作成する
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		int[][] paper = new int[10][10];
		while (true) {
			int[] ink = readPair(reader);
			// 終了判定
			if (ink == null) {
				break;
			}
			// インクを落とす
			drop(ink, paper);
		}

		// 結果を集計する
		int white = 0;
		int max = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (paper[i][j] == 0) {
					white++;
				}
				if (paper[i][j] > max) {
					max = paper[i][j];
				}
			}
		}
		System.out.println(white);
		System.out.println(max);
	}

	/**
	 * 紙にインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void drop(int[] ink, int paper[][]) {
		if (ink[2] == 1) {
			// 小インク
			dropSmall(ink, paper);
		} else if (ink[2] == 2) {
			// 中インク
			dropMiddle(ink, paper);
		} else if (ink[2] == 3) {
			dropLarge(ink, paper);
		}

	}

	/**
	 * 紙に小さいインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropSmall(int[] ink, int paper[][]) {
		paper[ink[0]][ink[1]]++;
		if (ink[0] > 0) {
			paper[ink[0] - 1][ink[1]]++;
		}
		if (ink[0] < 9) {
			paper[ink[0] + 1][ink[1]]++;
		}
		if (ink[1] > 0) {
			paper[ink[0]][ink[1] - 1]++;
		}
		if (ink[1] < 9) {
			paper[ink[0]][ink[1] + 1]++;
		}
	}

	/**
	 * 紙に中くらいのインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropMiddle(int[] ink, int paper[][]) {
		dropSmall(ink, paper);
		if (ink[0] > 0 && ink[1] > 0) {
			paper[ink[0] - 1][ink[1] - 1]++;
		}
		if (ink[0] < 9 && ink[1] > 0) {
			paper[ink[0] + 1][ink[1] - 1]++;
		}
		if (ink[0] < 9 && ink[1] < 9) {
			paper[ink[0] + 1][ink[1] + 1]++;
		}
		if (ink[0] > 0 && ink[1] < 9) {
			paper[ink[0] - 1][ink[1] + 1]++;
		}
	}

	/**
	 * 紙に大きいインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropLarge(int[] ink, int paper[][]) {
		dropMiddle(ink, paper);
		if (ink[0] > 1) {
			paper[ink[0] - 2][ink[1]]++;
		}
		if (ink[0] < 8) {
			paper[ink[0] + 2][ink[1]]++;
		}
		if (ink[1] > 1) {
			paper[ink[0]][ink[1] - 2]++;
		}
		if (ink[1] < 8) {
			paper[ink[0]][ink[1] + 2]++;
		}
	}

	/**
	 * ストリームから1行読み込んで、3つ1組の数値として返す。
	 *
	 * @param reader
	 *            入力ストリーム
	 * @return 3つ1組の数値
	 */
	private static int[] readPair(BufferedReader reader) {
		int[] result = new int[4];
		try {
			String line = reader.readLine();
			if (line == null || line.isEmpty()) {
				return null;
			}
			String[] array = line.split(",");
			result[0] = Integer.parseInt(array[0]);
			result[1] = Integer.parseInt(array[1]);
			result[2] = Integer.parseInt(array[2]);
		} catch (IOException e) {
			throw new RuntimeException();
		}
		return result;
	}

}

Measured memory_bytes: 17060
N,K = map(int,input().split())
array = [0]*N
for _ in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for i in range(d):
        array[A[i]-1] +=1
ans = 0
for i in range(N):
    if array[i] ==0:
        ans+=1
print(ans)


Measured memory_bytes: 67736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    long long int n, m;
    vector<long long int> v;
    cin >> n;
    for(int i = 0; i < 5; i++){
        cin >> m;
        v.push_back(m);
    }
    sort(v.begin(), v.end());
    if(n%v[0] == 0){
        cout << 4 + n/v[0] << endl;
    }else{
        cout << 5 + n/v[0] << endl;
    }
}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();

  string s = "_" + input< string >();

  vector< int64 > rd(N + 1), rm(N + 1);
  range(i, 1, N + 1) {
    rd[i] = rd[i - 1] + (s[i] == 'D');
    rm[i] = rm[i - 1] + (s[i] == 'M');
  }

  int q = input();
  while (q--) {
    int k = input();
    int64 res = 0;

    int64 cnt = 0;
    range(i, 1, N + 1) {
      if (i - k >= 0 && s[i - k] == 'D') {
        cnt -= (rm[i] - rm[i - k]);
      }

      if (s[i] == 'M') {
        cnt += (rd[i] - rd[max(0, i - k - 1)]);
      }

      if (s[i] == 'C') res += cnt;
    }

    cout << res << endl;
  }
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 17052
n = int(input())
sub = 101
score = 0
for _ in range(n):
    i = int(input())
    score += i
    if i % 10 != 0 and i < sub:
        sub = i

if score % 10 == 0:
    if sub == 101:
        print(0)
    else:
        print(score - sub)
else:
    print(score)

Measured memory_bytes: 3060
//Link : https://atcoder.jp/contests/agc005/tasks/agc005_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 2002
#define mod 924844033

int add(int x,int y) {
    return ((x+y)%mod+mod)%mod;
}
int mul(int x,int y) {
    return ((ll)x*y%mod+mod)%mod;
}
int fac[N];
int dp[N][N][2];
int M[N];

int tot = 0;
void cal(int st,int n,int k) {
    dp[st][0][0] = 1;
    int maxi = 0;
    if(st+k<=n) {
      dp[st][1][1] = 1;
      maxi = 1;
    }
    if(st-k>=1) {
        dp[st][1][0] = 1;
        maxi = 1;
    }
    int lastPos = st;
    for(int i=1;i*2*k+st<=n;++i) {
        int ind = i*2*k + st;
        lastPos = ind;
        int prevInd = ind - 2*k;
        for(int cc=0;cc<n;++cc) {
            for(int bit=0;bit<2;++bit) {
                if(ind+k<=n) {
                    dp[ind][cc+1][1] = add(dp[ind][cc+1][1], dp[prevInd][cc][bit]);
                    if(dp[ind][cc+1][1]) {
                      maxi = max(maxi,cc+1);
                    }
                }
                dp[ind][cc][0] = add(dp[ind][cc][0], dp[prevInd][cc][bit]);
                if(bit==0) {
                    dp[ind][cc+1][0] = add(dp[ind][cc+1][0], dp[prevInd][cc][bit]);
                    if(dp[ind][cc+1][0]) {
                      maxi = max(maxi,cc+1);
                    }
                }
            }
        }
    }

    for(int cc=tot;cc>=0;--cc) {
        for(int j=maxi;j;--j) {
            int x = add(dp[lastPos][j][0],dp[lastPos][j][1]);
            if(j+cc<=n) {
                M[j+cc] = add(M[j+cc], mul(M[cc],x));
            }
        }
    }
    tot += maxi;
}
void solve() {
    fac[0] = 1;
    for(int i=1;i<N;++i) {
        fac[i] = mul(fac[i-1],i);
    }
    int n,k;scanf("%d %d",&n,&k);
    M[0] = 1;
    for(int i=1;i<=2*k && i<=n;++i) {
        cal(i,n,k);
    }
    int parity = 1,ret = 0;
    for(int i=0;i<=n;++i) {
        int tmp = mul(fac[n-i],M[i]);
        tmp = mul(tmp,parity);
        ret = add(ret,tmp);
        parity = mul(parity,-1);
    }
    printf("%d\n",ret);
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(abs(a-b) > abs(a-c)) {
    cout << "B\n";
  } else {
    cout << "A\n";
  }
}


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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=2000+5,inf=N*10;
char qa[N*2],*a=qa+N,b[N];
int need[N],need2[N],q[N],nq[N],suf[N];
int ans=inf;
int n;

bool need_xiao(int a,int b)
{
	return need[a]<need[b];
}

void solve(char *a)
{
	need[0]=inf;
	rep(i,1,n)need[i]=b[i]=='1'?0:need[i-1]+1;
	need[0]=need[n];
	rep(i,1,n)need[i]=b[i]=='1'?0:need[i-1]+1;
	need2[n+1]=inf;
	per(i,n,1)need2[i]=b[i]=='1'?0:need2[i+1]+1;
	need2[n+1]=need2[1];
	per(i,n,1)need2[i]=b[i]=='1'?0:need2[i+1]+1;
	rep(i,1,n)q[i]=i;
	sort(q+1,q+n+1,need_xiao);
	need[0]=0;
	rep(tmp,0,n-1)
	{
		int top=0;
		rep(i,1,n)
		if(a[q[i]]!=b[q[i]])nq[++top]=q[i];
		suf[top+1]=0;
		per(i,top,1)suf[i]=max(suf[i+1],need2[nq[i]]);
		rep(i,0,top)chmin(ans,tmp+top+(max(0,need[nq[i]]-tmp)+suf[i+1])*2);
		a[0]=a[n];
		--a;
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%s%s",a+1,b+1);n=strlen(a+1);
	solve(a);
	reverse(a+1,a+n+1);reverse(b+1,b+n+1);
	solve(a);
	if(ans==inf)puts("-1");
	else cout<<ans;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
ans=0
cnt=[0]*m
for i in range(n):
    for j in range(1,a[i][0]+1):
        cnt[a[i][j]-1]+=1
for i in range(m):
    if cnt[i]==n:
        ans+=1
print(ans)


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

int main() {
    ll N;
    cin >>N;
    long double ans =0;
    for(int i=0;i<N;i++){
        long double a;
        cin >> a;
        ans += (1/a);
    }
    cout <<  setprecision(10)<<1/ans <<endl;
    return 0;
}

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

#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
#pragma GCC target (sse, sse2, sse3, ssse3, sse4,popcnt,tune=native)

#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) for(int i=0; i<n; i++)
#define CIN   ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define SZ(a) (int)(a.size())
#define Read() freopen("in.txt", "r", stdin)
#define Write() freopen("out.txt", "w", stdout)
#define mem(a, v) memset(a, v, sizeof(a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Unique(x)  x.erase(unique(all(x)), x.end())
#define pi acos(-1.0)
#define vec vector
#define mp make_pair
#define paii pair<int, int>
#define padd pair<dd, dd>
#define pall pair<ll, ll>
#define fr first
#define sc second
//#define endl "\n"
#define vec vector

using namespace std;

#define int long long

const int MAXN = 247, inf = 1e17 + 47;

vec<vec<int> >  graf(MAXN);
int n;

void read(){
    cin>> n;
    loop(a, n) {
        loop(b, n) {
            char p;
            cin >> p;
            if(p == '1') graf[a].pb(b);
        }
    }
}

bool bip = true;
vec<int> color(MAXN, -1);

void dfs(int p1, int cl) {
    color[p1] = cl;
    for(int &p2 : graf[p1]){
        if(color[p2] == cl) {
            bip = false;
            return;
        }
        if(color[p2] == (cl ^ 1)) {
            continue;
        }
        dfs(p2, (cl ^ 1));
    }
}

void solve() {
    dfs(0, 0);
    if(!bip){
        cout << -1 << endl;
        return;
    }

    vec<vec<int> > A(n, vec<int>(n, inf));
    loop(i, n) A[i][i] = 0;
    loop(a, n) {
        for(int b : graf[a]) {
            A[a][b] = 1;
        }
    }

    for(int k = 0; k < n; ++k) {
        for(int a = 0; a < n; ++a){
            for(int b = 0; b < n; ++b) {
                if(A[a][b] > A[a][k] + A[k][b])
                    A[a][b] = A[a][k] + A[k][b];
            }
        }
    }


    int ans = 0;
    loop(a, n) {
        loop(b, n) {
            if(A[a][b] != inf) ans = max(ans, A[a][b]);
        }
    }

    cout << ans + 1 << endl;
}

signed main() {
    #ifdef COFFEE_MACHINE
        Read();
        Write();
    #endif
    CIN;
    int t = 1;
    //cin >> t;
    while(t--) {
        read();
        solve();
    }
}


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

const int T_MAX = 200005;

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

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

typedef long long lint;

int uni[200001];
const int lang=100000;

int root(int a){
    if(uni[a]<0) return a;
    else return uni[a]=root(uni[a]);
}
bool connect(int ia,int ib){
    int a=root(ia),b=root(ib);
    if(a==b) return false;
    if(uni[a]>uni[b]){
        uni[b]+=uni[a];
        uni[a]=b;
    }else{
        uni[a]+=uni[b];
        uni[b]=a;
    }
    return true;
}

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

    for(int i=0;i<=200000;i++) uni[i]=-1;
    for(int i=0;i<N;i++){
        int K;
        cin >> K;
        for(int j=0;j<K;j++){
            int L;
            cin >> L;
            connect(i,L+lang);
        }
    }
    int r=root(0);
    for(int i=0;i<N;i++){
        if(root(i)!=r){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}//

Measured memory_bytes: 1024
#![allow(dead_code, unused_imports, deprecated)]
 
use std::collections::HashMap;
use std::cmp::Reverse;

use maplit::*;

use num::Integer;

use proconio::input;
use proconio::marker::*;
use proconio::fastout;

#[fastout]
fn main() {
  input!{
    k: usize,
  };

  let mut res = 0usize;
  for a in 1..=k {
    for b in 1..=k {
      for c in 1..=k {
        res += a.gcd(&b).gcd(&c)
      }
    }
  }
  
  println!("{}", res);
}

Measured memory_bytes: 2196
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b;
    string op;
    cin >> a >> op >> b;
    while(op!="?"){
    int c;
    if(op=="+") c = a+b;
    if(op=="-") c = a-b;
    if(op=="*") c = a*b;
    if(op=="/") c = a/b;
    cout << c << endl;
    cin >> a >> op >> b;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A=0, B=0, BA=0,ans=0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int L = S.size();
    
    for (int j = 0; j < L-1; j++) {
      if (S.at(j) == 'A' && S.at(j+1) == 'B') {
        ans++;
      }
    }
    if (S.at(0) == 'B' && S.at(L-1) == 'A') {
      BA++;
    }
    else if (S.at(0) == 'B') {
      B++;
    }
    else if (S.at(L-1) == 'A') {
      A++;
    }
  }
  if (BA == 0) {
    ans += min (B,A);
  }
  else if (A+B == 0) {
    ans += BA -1;
  }
  else {
    ans += BA + min (B,A);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    float q=n/1000.0;
    if(n%1000==0)
      cout<<"0\n";
    else
    cout<<(((int)q)+1)*1000-n<<"\n";
  

}

Measured memory_bytes: 3620
// Last Change: 10/19/2019 23:23:20.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

//'100'は適宜変更。入れないとあふれる。
const ll INF = numeric_limits<ll>::max() / 100;
// cost[i][j]:iからjへ行くまでの最短コスト
vector<vector<ll>> cost;

// i->jへの既知のルートと、kを経由していくのとでどちらが近いか。
bool WarshallFloyd(int V) {
  for (int k = 0; k < V; ++k) {
    for (int i = 0; i < V; ++i) {
      for (int j = 0; j < V; ++j) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }

  //負の閉路判定
  for (int i = 0; i < V; ++i) {
    if (cost[i][i] < 0) {
      return true;
    }
  }

  return false;
}

int main() {
  ll N, M, L;
  cin >> N >> M >> L;

  cost.assign(N, vector<ll>(N, INF));
  for (ll i = 0; i < N; ++i) {
    cost[i][i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    cost[a][b] = min(cost[a][b], c);
    cost[b][a] = min(cost[b][a], c);
  }
  WarshallFloyd(N);

  //////////
  vector<vector<ll>> cost2;
  cost2.assign(N, vector<ll>(N, INF));
  swap(cost, cost2);
  for (ll i = 0; i < N; ++i) {
    for (ll j = i + 1; j < N; ++j) {
      if (cost2[i][j] <= L) {
        cost[i][j] = 1;
        cost[j][i] = 1;
      }
    }
  }
  WarshallFloyd(N);

  ll Q, s, t, res;
  cin >> Q;
  for (ll i = 0; i < Q; ++i) {
    cin >> s >> t;
    --s, --t;
    res = cost[s][t];
    if (res == INF) {
      res = 0;
    }
    cout << res - 1 << endl;
  }
}



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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	lint ans=0;
	for(int i=1;i<n;i++){
		if(a[i-1]>a[i]){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	printf("%lld\n",ans);

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, k, ans=0;
	vector<int> v;

	cin>> n >> k;
	v.resize(n);

	rep(i, n) cin >> v[i];

	int l=0, r=1000000001, mi, tmp;
	while(r-l>1){
		mi=(l+r)/2;
		tmp=0;
		rep(i, n){
			tmp+=(v[i]-1)/mi;
		}
		if(tmp<=k) r=mi;
		else l=mi;
	}

	cout<< r << endl;
 
	return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j * i < N; j++) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int x,y,z;
    while(cin>>x>>y>>z, x|y|z){
        double mr=sqrt(min(x*x+y*y,min(y*y+z*z,z*z+x*x)));
        int n; cin>>n;
        while(n--){
            int r; cin>>r;
            if(mr<r*2) cout<<"OK"<<endl;
            else cout<<"NA"<<endl;
        }
    }
}

Measured memory_bytes: 1156
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    bool n = false, w = false, s = false, e = false;
    for (int i = 0; i < nap.size(); ++i)
    {
        if (nap[i] == 'N')
            n = true;
        if (nap[i] == 'W')
            w = true;
        if (nap[i] == 'S')
            s = true;
        if (nap[i] == 'E')
            e = true;
    }
    if (!(n ^ s) && !(w ^ e))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    C_i = CSF[i][0]
    S_i = CSF[i][1]
    t = S_i + C_i
    for j in range(i+1,N-1):
        C_j, S_j, F_j = CSF[j]
        if t > S_j:
            w = t%F_j
            if w == 0:
                t += C_j
            else:
                t += F_j - w + C_j
        else:
            t = S_j + C_j
    print(t)
print(0)
            

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second     
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define repr(i,a,b)      for(int i=b-1;i>=a;i--)
#define trav(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN             10001

using namespace std;

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 


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



void solve()
{   
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int red[a];
    int gr[b];
    int cl[c];
    rep(i,0,a)
    cin>>red[i];
    rep(i,0,b)
    cin>>gr[i];
    rep(i,0,c)
    cin>>cl[i];
    sort(red,red+a,greater<int>());
    sort(gr,gr+b,greater<int>());
    sort(cl,cl+c,greater<int>());
    int sum=0;
    rep(i,0,x)
    sum+=red[i];
    rep(i,0,y)
    sum+=gr[i];
    int j=x-1;
    int k=y-1;
    int l=0;
    while((red[j]<cl[l] || gr[k]<cl[l]) && (j>=0 || k>=0) && l<c)
    {
    	if(j<0 && k>=0)
    	{
    		if(gr[k]<cl[l])
    		{
    			sum-=gr[k];
    			sum+=cl[l];
    			k--;
    			l++;
    		}
    		else
    		{
    			break;
    		}
    	}
    	else if(j>=0 && k<0)
    	{
    		if(red[j]<cl[l])
    		{
    			sum-=red[j];
    			sum+=cl[l];
    			j--;
    			l++;		
    		}
    		else
    			break;
    	}
    	else
    	{
    	if(red[j]<gr[k])
    	{
    		sum-=red[j];
    		sum+=cl[l];
    		j--;
    		l++;
       	}
    	else
    	{
    		sum-=gr[k];
    		sum+=cl[l];
    		k--;
    		l++;
    	}}
    }
    cout<<sum;
}   
    


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const long long base=1e9+7;
#define ll long long
ll a[2010],t[2010];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    ll n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
         cin>>a[i];
    long long kq=0;
    for (int i=1;i<n;i++)
        for (int j=i+1;j<=n;j++) if (a[i]>a[j]) kq++;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            if (a[i]<a[j]) t[i]++;
    ll q=0;
    for (int i=1;i<=n;i++) q+=t[i];
    kq=(kq*k)%base;
    q=(((k*(k-1)/2)%base)*q)%base;
    kq=(kq+q)%base;
    cout<<kq;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	string S;
	cin>>S;
	
	int N;
	N = S.size()+1;
	
	vector<bool> down_flag(N,false);
	vector<bool> up_flag(N,false);
	
	for(int i=0;i<S.size()-1;i++){
		if(S[i]=='>'&&S[i+1]=='<'){
			down_flag[i+1]=true;
		}
	}
	if(S[0]=='<'){
		down_flag[0]=true;
	}
	else{
		up_flag[0]=true;
	}
	if(S[N-2]=='>'){
		down_flag[N-1]=true;
	}
	else{
		up_flag[N-1]=true;
	}
	
	for(int i=0;i<S.size()-1;i++){
		if(S[i]=='<'&&S[i+1]=='>'){
			up_flag[i+1]=true;
		}
	}
	vector<int> ans(N,0);
	
	for(int i=0;i<N;i++){
		if(!down_flag[i])continue;
		int ind = i;
		int now = 0;
		while(true){
			if(ind<0||ind>=N)break;
			if(up_flag[ind]){
				ans[ind]=max(ans[ind],now);
				break;
			}
			ans[ind] = now;
			now++;
			ind--;
		}
		
		ind=i;
		now=0;
		while(true){
			if(ind<0||ind>=N)break;
			if(up_flag[ind]){
				ans[ind]=max(ans[ind],now);
				break;
			}
			ans[ind] = now;
			now++;
			ind++;
		}
	}
	long long c = 0;
	for(int i=0;i<N;i++){
		c+=(long long)ans[i];
	}
	
	cout<<c<<endl;
	
	
    return 0;
}



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

int main() {
    int K, X;
    cin >> K >> X;
    int right = min(1000000, K+X-1);
    int left = max(-1000000, X-K+1);
    for(int i=left;i<=right;i++){
        cout << i;
        if(i==right){
            cout << endl;
        }else{
            cout << " ";
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int A,B;
   
    scanf("%d %d",&A,&B);
    
    int time=0;
    
    time=A+B;
    
    if (time>23) {
        time=time%24;
    }
    
    printf("%d\n",time);
    
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  int n;
  cin >> n;
  vector<vector<int>> grid(2, vector<int>(n));
  for(int i=0; i<2; i++){
    for(int j=0; j<n; j++) cin >> grid[i][j];
  }
  int maxx = 0;
  for(int i=0; i<n; i++){
    int sum = 0;
    for(int j=0; j<=i; j++){
      sum += grid[0][j];
    }
    for(int j=i; j<n; j++){
      sum += grid[1][j];
    }
    maxx = max(maxx,sum);
  }
  cout << maxx << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
int r5 (int a){
    int x = a * a * a * a * a;
    return x;
}

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

    bool fl = false;
    for(int i = 1 ; i<150;i++){
        for(int j = -120; j < 150; j++){
            if(n == (r5(i) - r5(j))){
                cout << i << " " << j <<endl;
                return 0;
            }
        }
    }
}





Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC075
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = hw[0];
            var w = hw[1];
            var s = Enumerable.Range(0, h).Select(i => Console.ReadLine().ToArray()).ToArray();

            var adjacents = new (int dx, int dy)[]
            {
                (-1, -1), (0, -1), (1, -1),
                (-1, 0), (0, 0), (1, 0),
                (-1, 1), (0, 1), (1, 1),
            };

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (s[i][j] == '#') continue;

                    var count = 0;
                    foreach (var adjacent in adjacents)
                    {
                        var x = i + adjacent.dx;
                        if (x < 0 || h <= x) continue;
                        var y = j + adjacent.dy;
                        if (y < 0 || w <= y) continue;

                        if (s[x][y] == '#') count++;
                    }

                    s[i][j] = (char)(count + 48);
                }
            }

            foreach (var si in s)
            {
                Console.WriteLine(new string(si));
            }
        }
    }
}


Measured memory_bytes: 28348
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
lld pref[300000];
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,l,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
  // cin>>TESTS;
     while(TESTS--)
     {
         cin>>n>>k;
         arr[0]=0;
         rep(i,1,n){
             cin>>arr[i];
         }
         sort(arr,arr+n+1);
         pref[0]=0;
         rep(i,1,n) pref[i]=pref[i-1]+arr[i];
         if (pref[n]<k){cout<<n;return 0;}
         lld ans=0;
         rep(i,1,n){
            lld sear;
            lld add;
            if (pref[i]<k){sear=k;add=0;}
            else {sear=k-arr[i];add=arr[i];}
            lld ind=lower_bound(pref,pref+n+1,sear)-pref;
           // if (add!=0){if (pref[ind]+add-arr[i]>=k) ans++;}
            if (add==0) {
                bool pos1=false;
                bool pos2=false;
                repr(j,ind,1){
                    if (j==i)continue;
                    if (pref[ind]-add-arr[j]>=k)add+=arr[j];
                }
                if (pref[ind]-add-arr[i]>=k)pos1=true;
                lld sum=arr[i];
                repr(j,n,1){
                    if (j==i)continue;
                    if (sum+arr[j]<k+arr[i])sum+=arr[j];
                }
                if (sum<k)pos2=true;
                if (pos1&&pos2)ans++;
            }
            //cout<<pref[ind]<<" "<<arr[i]<<"\n";

         }
         cout<<ans;
     }
    return 0;
}


Measured memory_bytes: 2304
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

ll digit(ll n)
{
  ll result;

  result = 0;
  while (n > 0)
  {
    n = n / 10;
    result += 1;
  }
  return (result);
}

int main(void) {
  /* 標準入力フラグ */
  int   scan;

  /* 数入力 */
  ll    answer;
  ll    k; 
  answer = 1;
  scan = scanf("%lld", &k);

  /* プログラムを書く */
  ll    mod;
  mod = k % 10;
  if (mod == 0 || mod == 2 || mod == 4 || mod == 5 || mod == 6 || mod == 8) {
    printf("-1");
    return (0);
  }

  if (k % 7 == 0) {
    k = k / 7;
  } 
  
  ll  amari;
  ll  l;
  l = 9 * k;
  amari = 1;
  while (1) {
    amari = 10 * amari % l;
    if (amari == 1) {
      break ;
    } else {
      answer++;
    }
  }

  /* 数回答 */
  printf("%lld", answer);

  return (0);
}



Measured memory_bytes: 1700
import numpy as np
bisect_left = np.searchsorted
input()
a = np.int32(input().split())
b = np.int32(input().split())
ans = 0
for k in range(29):
    low = pow(2, k)
    high = pow(2, k + 1)
    x = a % high
    y = b % high
    y.sort()
    y = np.hstack((y - high, y))
    left = bisect_left(y, low - x)
    right = bisect_left(y, high - x)
    if np.sum(right - left) % 2:
        ans += low
print(ans)

Measured memory_bytes: 35908
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  int n_mul_4 = 0;
  int n_mul_2 = 0;
  int n_odd = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    std::cin >> a;
    if (a % 2) { ++n_odd; }
    if (a % 4 == 0) { ++n_mul_4; }
    else if (a % 2 == 0) { ++n_mul_2; }
  }
  std::cout << ((n_odd <= n_mul_4 || (!n_mul_2 && n_odd <= n_mul_4 + 1)) ? "Yes" : "No") << std::endl;
  return 0;
}

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

int main() {
    vector<string> v(3);
    cin >> v[0];
    cin >> v[1];
    cin >> v[2];

    vector<int> pointers(3, 0);
    char c = v[0][0];
    pointers[0]++;
    while (true) {
        if (pointers[c - 'a'] == v[c - 'a'].size()) {
            cout << (char) toupper(c) << endl;
            return 0;
        }
        c = v[c - 'a'][pointers[c - 'a']++];
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


template<typename T>
struct BIT {
    int n;
    vector<T> bit;
    BIT() = default;
    //1-indexed
    BIT(int n_) : n(n_+1), bit(n+1, 0){}
    T sum(int i){
        T s(0);
        for(int x = i;x > 0; x-=(x&-x)) s += bit[x];
        return s;
    }
    //[l, r)
    T sum(int l, int r){
        return sum(r-1)-sum(l-1);
    }
    void add(int i, T a){
        if(i == 0) return;
        for(int x = i;x <= n;x+=(x&-x)) bit[x] += a;
    }
    int lower_bound(int w){
        if(w <= 0) return 0;
        int x = 0, r = 1;
        while(r < n) r <<= 1;
        for(int k = r;k > 0;k>>=1) if(x+k <= n and bit[x+k] < w) w -= bit[x+k], x += k;
        return x+1;
    }
    //0-indexed
    T sum0(int i){ return sum(i+1); };
    T sum0(int l, int r){ return sum(r)-sum(l); }
    void add0(int i, T a){ add(i+1, a); }
};


int N;
string S;
int Q;
BIT<int> bit[30];


signed main(){
    cin >> N;
    cin >> S;

    rep(i, 0, 26) bit[i] = BIT<int>(N);

    rep(i, 0, N) bit[S[i]-'a'].add0(i, 1);

    cin >> Q;
    rep(i, 0, Q){
        int q;
        cin >> q;
        if(q == 1){
            int k;
            char c;
            cin >> k >> c;
            k--;
            bit[S[k]-'a'].add0(k, -1);
            bit[c-'a'].add0(k, 1);
            S[k] = c;
        }
        else {
            int l, r, ans = 0;
            cin >> l >> r;
            l--;
            rep(j, 0, 26) if(bit[j].sum0(l, r) != 0) ans++;
            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 102532
#include <stdio.h>

main(){
  int N;
  scanf("%d",&N);
  int A[N+1], i, j, hozon,count=0;

  for(i=0; i<N; i++){
    scanf("%d",&A[i]);
  }
  for(i=0; i<N; i++){
    for(j=N-1; j>i; j--){
      if(A[j-1] > A[j]){
	hozon = A[j];
	A[j] = A[j-1];
	A[j-1] = hozon;
	count++;
      }
    }
  }
  for(i=0; i<N; i++){
    if(i > 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod=1e9+7;

int main()
{
  fastio
  int n;
  cin>>n;
  int t;
  t=n%10;
  if(t==7)
  {
    cout<<"Yes";
    return 0;
  }
  n/=10;
  t=n%10;
  if(t==7)
  {
    cout<<"Yes";
    return 0;
  }
  n/=10;
  if(n==7)
  cout<<"Yes";
  else
  cout<<"No";
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

int main(){
  long long int N;
  std::string S;
  scanf("%lld", &N);
  std::cin >> S;
  //std::cerr << S << std::endl;
  
  long long int ans = 1;
  for(long long int i = 1; i < N; i++){
    if(S[i] != S[i-1]){
      ans++;
      //std::cerr << i << std::endl;
    }
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 512
program Frog_1
    implicit none
    integer(4), parameter:: inf=2000000005
    integer(4):: n,i
    integer(4), allocatable:: h(:), dp(:)

    read*, n
    allocate(h(-1:n), dp(-1:n))

    h(-1:0) = 100000
    read*, h(1:n)
    dp(:) = inf
    dp(1) = 0

    do i=2,n
        dp(i) = min(dp(i-1) + abs(h(i)-h(i-1)), dp(i-2) + abs(h(i)-h(i-2)))
    end do

    print*, dp(n)


end program Frog_1

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

struct data
{
  int input;
  int ind;
};

int main()
{
  int N;
  std::cin >> N;
  std::vector<data> A(N);
  for(int i= 0; i < N; i++)
  {
    std::cin >> A[i].input;
    A[i].ind = i;
  }
  
  std::sort(A.begin(), A.end(), 
      [](const data &a, const data &b){return a.input < b.input;});
  for(auto it: A)
  {
    std::cout << it.ind + 1 << std::endl;
    // std::cerr << "input " << it.input << std::endl;
    // std::cerr << "ind " << it.ind << std::endl;
  }
  // for(int i = 0; i< N; i++)
  // {
  //   std::cout << A[i].input << std::endl;
  // }
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
int main()
{
  int i, j, N, A[100], min, n, count = 0;
  scanf("%d",&N);
  for (i = 0; i < N; i++)
    scanf("%d",&A[i]);
  for (i = 0; i < N; i++){
    min = i;
    for (j = i; j < N; j++){
      if (A[j] < A[min])
	min = j;
    }
    if (i != min){
      n = A[i];
      A[i] = A[min];
      A[min] = n;
      count++;
    }
  }
  for (i = 0; i < N; i++){
    printf("%d",A[i]);
    if (i < N-1)
      printf(" ");
  }
  printf("\n%d\n",count);
  
  return 0;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long

int ret(int get)
{
	if (get < 0) return - get;
	return get;
}

int main(void)
{
	int n, m;
	cin >> n >> m;
	vec<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	vec<int> c(m), d(m);
	rep(i, m) cin >> c[i] >> d[i];

	rep(i, n) {
		int MIN = 1000000007;
		int keep;
		rep(j, m) {
			int get = ret(a[i] - c[j]) + ret(b[i] - d[j]);
			if (MIN > get) {
				MIN = get;
				keep  = j;
			}
		}
		cout << keep + 1 << endl;
	}	

	return 0;
}

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

void solve() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  int cnt = 0;
  while(a >= b) b <<= 1, ++cnt;
  while(b >= c) c <<= 1, ++cnt;
  cout << (cnt <= k ? "Yes" : "No") << endl;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


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

int main(){
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string a, b, c; cin >> a >> b >> c;
  ll la = a.length(),lb = b.length(), lc = c.length();
  bool ab[20001] = {}, cb[20001] = {}, ac[20001] = {};
  fill_n(ab,20001,true); fill_n(cb,20001,true); fill_n(ac,20001,true);
  repr(i,-1*la,0) rep(j,min(lb,la+i)) ab[10000+i] &= (a[j-i]=='?'||b[j]=='?'||a[j-i]==b[j]);
  rep(i,lb) rep(j,min(lb-i,la)) ab[10000+i] &= (a[j]=='?'||b[j+i]=='?'||a[j]==b[j+i]);
  repr(i,-1*lc,0) rep(j,min(lb,lc+i)) cb[10000+i] &= (c[j-i]=='?'||b[j]=='?'||c[j-i]==b[j]);
  rep(i,lb) rep(j,min(lb-i,lc)) cb[10000+i] &= (c[j]=='?'||b[j+i]=='?'||c[j]==b[j+i]);
  repr(i,-1*la,0) rep(j,min(lc,la+i)) ac[10000+i] &= (a[j-i]=='?'||c[j]=='?'||a[j-i]==c[j]);
  rep(i,lc) rep(j,min(lc-i,la)) ac[10000+i] &= (a[j]=='?'||c[j+i]=='?'||a[j]==c[j+i]);
  // debug(ab+10000-(la-1),ab+10000+lb);
  // debug(cb+10000-(lb-1),cb+10000+lc);
  // debug(ac+10000-(la-1),ac+10000+lc);

  ll result = la + lb + lc;
  repr(apos,-4001,4001) repr(cpos,-4001,4001) {
    if (ab[10000+apos]&&cb[10000+cpos]&&ac[10000+apos-cpos]) {
      ll l = min(0,min(apos,cpos));
      ll r = max(lb,max(apos+la,cpos+lc));
      // if (result>r-l) cout << apos << " " << cpos << "->" << r-l << endl;
      result = min(result,r-l);
    }
  }
  cout << result << endl;
  return 0;
}

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

int n,f[100005],P[100005];
vector<int> V,g[100005];

void DFS(int u,int root)
{
    f[u]=1;
    for(int i=0;i<g[u].size();i++)
        if(g[u][i]!=root)
        {
            DFS(g[u][i],u);
            P[g[u][i]]=u;
            f[u]+=f[g[u][i]];
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    DFS(1,0);
    while(n!=1)
    {
        V.push_back(n);
        n=P[n];
    }
    V.push_back(1);
    int tmp=V[(V.size()-2)/2];
    if(f[tmp]>=f[1]-f[tmp])
        cout<<"Snuke";
    else
        cout<<"Fennec";
}


Measured memory_bytes: 14972
#include<iostream>


using namespace std;

int main(){
	
	char S[3];
	int A = 0;
	int B = 0;
	
	for(int i = 0; i < 3; i++){
		cin>>S[i];
		
		if(S[i] == 'A'){
			A++;
			
		}else{
			B++;
			
		}
	}
	
	if(A == 2 || B == 2){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int n, q;
int A[100005];
ll psum[100005], osum[100005];

int main(){
    fio;
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> A[i];
        psum[i] = psum[i-1] + A[i];
        osum[i] = A[i];
        if(i > 1) osum[i] += osum[i-2];
    }
    for(int x; q--;){
        cin >> x;
        //cout << "x = " << x << '\n';
        int id = lb(A+1,A+n+1,x) - A;
        int lo = id, mi, hi = n;
        while(lo < hi){
            mi = (lo + hi) >> 1;
            int jd = lb( A+1,A+n+1,x+x - A[mi] ) - A;
            if(mi - jd < n - mi) lo = mi + 1;
            else hi = mi;
        }
        //cout << "hi = " << hi << '\n';
        ll ans = psum[n] - psum[hi-1];
        if(2*hi - n - 2 >= 0) ans += osum[2*hi - n - 2];
        cout << ans << '\n';
    }
}

Measured memory_bytes: 3712
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int s;cin >> s;
	int h = s / 3600;s = s % 3600;int m = s / 60; s %= 60;
	cout << h << ":" << m << ":" << s << "\n";
	return 0;
}



Measured memory_bytes: 3216
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		String input = bf.readLine();
 		int j = -1;
 		boolean found = false;
 		for(j = 0;j<input.length();j++){
 			if (input.charAt(j) == 'R'){
 				found = true;
 				break;
 			}
 		}
 		int count = 1;
 		for(int k = j+1;k<input.length();k++){
 			if (input.charAt(k) == 'R')
 				count++;
 			else
 				break;
 		}
 		if (!found)
 			out.println(0);
 		else
 			out.println(count);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25316
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
 
int main(){
    double a, b, c, d, e, f, x, y, det;
    while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF){
        det = b * d - a * e;
        y = (c * d - a * f) / det;
        x = (c - b * y) / a;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair< int, int > Pi;

bool cmp(const pair< Pi, Pi >& p, const pair< Pi, Pi >& q)
{
  if(p.first.first + p.second.first, q.first.first + q.second.first)
    return(p.first.first + p.second.first < q.first.first + q.second.first);
  return(p.first.first * p.first.second + p.second.first * p.second.second <
         q.first.first * p.first.second + q.second.first * q.second.second);
}

// ax + by = d
pair< Pi, Pi > ask(int a, int b, int d)
{
  pair< Pi, Pi > ret({INF, INF}, {INF, INF});
  for(int x = 0; x < 10000; x++) {
    int f = abs(d - a * x);
    if(f % b == 0) ret = min(ret, {{x, a}, {f / b, b}}, cmp);
  }
  return(ret);
}

int main()
{
  int a, b, d;
  while(cin >> a >> b >> d, a) {
    auto alpha = ask(a, b, d), beta = ask(b, a, d);
    auto ret = min(alpha, beta, cmp);
    if(ret == beta) swap(ret.first, ret.second);
    cout << ret.first.first << " " << ret.second.first << endl;
  }
}

Measured memory_bytes: 2936