akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if(par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y) { return root(x) == root(y); }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    UnionFind uf(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        uf.merge(x, y);
    }
    map<int, vector<ll>> mp;
    for(int i = 0; i < n; i++) {
        mp[uf.root(i)].emplace_back(a[i]);
    }
    int sz = mp.size();
    if(sz == 1) {
        print(0);
        return 0;
    }
    ll ans = 0;
    for(auto &p : mp) {
        sort(RALL(p.second));
        ans += p.second.back();
        p.second.pop_back();
    }
    vector<ll> v;
    for(const auto &p : mp) {
        for(const ll &i : p.second) {
            v.emplace_back(i);
        }
    }
    sort(ALL(v));
    if(v.size() < sz - 1 - 1) {
        print("Impossible");
        return 0;
    }
    for(int i = 0; i < sz - 1 - 1; i++) {
        ans += v[i];
    }
    print(ans);
}

Measured memory_bytes: 12416
local a,b,x=io.read("*n","*n","*n")
if a*a*b/2<=x then
  print(math.atan(2*(a*a*b-x)/(a*a*a))*180/math.pi)
else
  print((math.pi/2 - math.atan(2*x/(a*b*b)))*180/math.pi)
end

Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
xm = max(map(int, input().split()))
ym = min(map(int, input().split()))

ans = False

for i in range(x + 1, y + 1):
    if xm < i and i <= ym:
        ans = True
        break
        
if ans:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;

signed main(){
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 764
#include <stdio.h>

int main(){
	
	
	long long num[100000];
	long long c;
	scanf("%lld", &c);
	for(long long i=0;i <c;i++){
		scanf("%lld", &num[i]); 
	}
	for(long long i=0;i < c;i++){
		if(num[i] == 0){ 
			printf("0\n");
			return 0;
		}
	}
	long long int sum = 1;
	for(int i=0;i<c;i++){
		if(num[i] <= 1000000000000000000/sum){
        	sum *= num[i];
    	}else{
        	printf("-1\n");
       		return 0;
		}		
	}	printf("%lld\n", sum);
		return 0;	
}

Measured memory_bytes: 2508
#!usr/bin/env python3
import math
import sys
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LIR(n):
    return [LI() for i in range(n)]

class SegmentTree:
    def __init__(self, size, f=lambda x,y : x+y, default=0):
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def get(self, a, b=None):
        if b is None:
            b = a + 1
        l, r = a + self.size, b + self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

def solve():
    n,d,a = LI()
    g = LIR(n)
    g.sort()
    X = [i for (i,_) in g]
    s = SegmentTree(n)
    ans = 0
    for i in range(n):
        x = g[i][0]
        j = bisect.bisect_left(X,x-2*d)
        h = g[i][1]-s.get(j,i)
        if h <= 0:
            continue
        k = math.ceil(h/a)
        ans += k
        s.update(i,k*a)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H,W,h,w;
  cin >> H >> W >> h >> w;
  if(H % h == 0 && W % w == 0){
    std::cout << "No" << std::endl;
    return 0;
  }
  else{
    std::cout << "Yes" << std::endl;
    ll a = 1e8;
    rep(i,H){
      rep(j,W){
        if(j) cout << " ";
        if(i % h == 0 && j % w == 0){
          cout << a - 1;
        }
        else if(i % h == h-1 && j % w == w-1){
          cout << - a ;
        }
        else cout << 0 ;
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
const int N=2e7+7,mod=1e9+7;
int n,m,k,ans,fac[N],inv[N];
int C(int a,int b){return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod;}
int add(int&x,long long y){x=(x+y)%mod;}
int main()
{
	fac[0]=1;for(int i=1;i<N;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;for(int i=2;i<N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[i-1]*inv[i]%mod;
	cin>>n>>m>>k;
	for(int u=1;u<=k;u++)
	{
		if(u>=2)add(ans,1ll*u*(u-1)%mod*n%mod*m%mod*C(n+m-2,u-2)%mod*fac[u-2]%mod*C(n+m-u,k-u)%mod*fac[k-u]);
		add(ans,1ll*u*C(n+m,u)%mod*fac[u]%mod*C(n+m-u,k-u)%mod*fac[k-u]);
		add(ans,1ll*C(n+m,k)*fac[k]);
	}
	cout<<ans;
}

Measured memory_bytes: 156544
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] v = new int[n];
        Map<Integer, Integer> ki = new HashMap<>();
        Map<Integer, Integer> gu = new HashMap<>();
        for(int i=0; i<n; i++) {
            v[i] = Integer.parseInt(sc.next());
            if(i % 2 == 1) {
                if(ki.containsKey(v[i])) ki.put(v[i], ki.get(v[i])+1);
                else ki.put(v[i], 1);
            }else {
                if(gu.containsKey(v[i])) gu.put(v[i], gu.get(v[i])+1);
                else gu.put(v[i], 1);
            }
        }
        ki.put(0, 0);
        gu.put(0, 0);
        int kimax = 0;
        int gumax = 0;
        int kisemax = 0;
        int gusemax = 0;
        for(int key : ki.keySet()) {
            if(ki.get(kimax) < ki.get(key)) kimax = key;
        }
        for(int key : ki.keySet()) {
            if(key == kimax) continue;
            if(ki.get(kisemax) < ki.get(key)) kisemax = key;
        }
        for(int key : gu.keySet()) {
            if(gu.get(gumax) < gu.get(key)) gumax = key;
        }
        for(int key : gu.keySet()) {
            if(key == gumax) continue;
            if(gu.get(gusemax) < gu.get(key)) gusemax = key;
        }
        if(kimax == gumax) System.out.println(n - max(ki.get(kimax)+gu.get(gusemax), ki.get(kisemax)+gu.get(gumax)));
        else System.out.println(n - ki.get(kimax) - gu.get(gumax));
        
    }
    public static int min(int a, int b) {
        if(a <= b) return a;
        else return b;
    }
    public static int max(int a, int b) {
        if(a <= b) return b;
        else return a;
    }
}

Measured memory_bytes: 52752
A = []
for i in range(3):
	A.append(list(map(int,input().split())))

if A[0][0]+A[1][1]==A[0][1]+A[1][0] and A[0][0]+A[1][2]==A[0][2]+A[1][0] and A[0][0]+A[2][1]==A[0][1]+A[2][0] and A[0][0]+A[2][2]==A[0][2]+A[2][0]:
	print("Yes")
else:
	print("No")

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

template <typename T>
using lim = numeric_limits<T>;

const double PI = acos(-1);
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	double r; cin >> r;
	cout << setprecision(10) << fixed << r*2*PI << "\n";

}

Measured memory_bytes: 3776
# ABC 135: B – 0 or 1 Swap
N = int(input())
p = [int(s) for s in input().split()]

p_sorted = sorted(p)

diff = 0
for i in range(N):
    if p[i] != p_sorted[i]:
        diff += 1

print('YES' if diff == 2 or diff == 0 else 'NO')

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

using namespace std;

int main(){
 int n,a,b; 
  cin >>  n >> a >> b;
 string s;
  cin >> s;
  
  int pass=0;
  int foreign=0;
  for(int i=0;i<n;i++){
      if(s[i]=='a'&&pass<a+b) {
    cout << "Yes" << endl;
    pass++;
   } 
   else if(s[i]=='b'&&pass<a+b&&foreign<b){ 
   cout << "Yes" << endl;
    pass++;
    foreign++; 
     }
    else{ cout << "No" << endl;
    
    }
  }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;

ll gcd(ll a,ll b){
    ll r;
    while(a%b!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return b;
}

ll count(ll a,ll c,ll d){
    return a/c+a/d-a/(c*d/gcd(c,d));
}

int main(){
   ll a,b,c,d;
   cin >> a >> b >> c >> d;
   cout << b-(a-1)-(count(b,c,d)-count(a-1,c,d)); 
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static class Packet implements Comparable<Packet>{
		long time;
		int source, dest;

		public Packet(long time, int source, int dest) {
			super();
			this.time = time;
			this.source = source;
			this.dest = dest;
		}

		@Override
		public int compareTo(Packet arg0) {
			if(this.time < arg0.time){
				return -1;
			}else if(this.time > arg0.time){
				return 1;
			}else{
				return 0;
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if (n == 0 && m == 0) {
				break;
			}
			
			boolean[] is_infected = new boolean[n];
			is_infected[0] = true;
			
			Packet[] packets = new Packet[m];
			
			for(int i = 0; i < m; i++){
				packets[i] = new Packet(sc.nextLong(), sc.nextInt() - 1, sc.nextInt() - 1); 
			}
			
			Arrays.sort(packets);
			
			int count = 1;
			for(int i = 0; i < m; i++){
				if(is_infected[packets[i].source] && !is_infected[packets[i].dest]){
					is_infected[packets[i].dest] = true;
					count++;
				}
			}
			
			System.out.println(count);
		}

	}

}

Measured memory_bytes: 16000
import sys
import itertools
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=[0 for i in range(N)]
for i in range(K):
    d=int(input())
    tmp=nl()
    for j in range(d):
        A[tmp[j]-1]+=1
c=0
for i in range(N):
        if(A[i]==0):
            c+=1

print(c)


Measured memory_bytes: 9236
n, k = map(int, input().split())

ret = 0

for i in range(k, n+2):
    min_val = i * (i - 1) // 2
    max_val = (n * (n + 1) // 2) - ((n - i) * (n - i + 1) // 2)
    ret += (max_val - min_val) + 1

print(ret % (10 ** 9 + 7))


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

int main() {
  char c;
  cin >> c;
  if (c == 'a'|| c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

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

#define PII	pair<int , int>

using namespace std;


int main()
{
	int n;
	PII xy;
	PII buy;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> xy.first >> xy.second >> buy.first >> buy.second;

		int sum1 , sum2;

		sum1 = sum2 = xy.first * buy.first + xy.second * buy.second;

		if (buy.first < 5)
		{
			sum2 += xy.first * (5 - buy.first);
		}
		if (buy.second < 2)
		{
			sum2 += xy.second * (2 - buy.second);
		}

		sum2 *= 0.8;

		cout << min(sum1 , sum2) << endl; 
	}

	return 0;
}

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

int main(){
	ll n;
	cin >> n;
	
	ll k = n;
	ll ans = 0;
	for(ll i = 2; i * i <= n; ++i){
		int count = 0;
		while(k % i == 0){
			k /= i;
			count++;
		}
		for(int j = 1; j <= count; ++j){
			count -= j;
			ans++;
		}
	}
	if(1 < k){
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3636
n,k,*a=map(int,open(0).read().split())
r=range(n)
while(min(a)<n)*k:
 k-=1;b=[0]*n*3
 for i in r:b[max(0,i-a[i])]+=1;b[i-~a[i]]-=1
 for i in r:b[i+1]+=b[i]
 a=b[:n]
print(*a)

Measured memory_bytes: 173504
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline LL Read()
{
	LL x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, m, d[MAXN];
LL w[MAXN];

inline bool Chk(LL x)
{
	LL cur = 0;
	for (int i = 1; i <= n; i ++)
	{
		if (x >= w[i])
			cur += (x - w[i]) / d[i] + 1;
		if (cur >= m)
			return true;
	}
	return false;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
		w[i] = Read(), d[i] = Read();
	LL l = 0, r = 1LL << 61, ret = r;
	while (l <= r)
	{
		LL mid = l + r >> 1;
		if (Chk(mid))
			ret = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	return printf("%lld\n", ret), 0;
}


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

using namespace std;

int main() {
    
    string s1;
    string s2;
    cin>>s1>>s2;
    int n1=s1.length();
    int i=n1+1;
    
    int n2=s2.length();
    int j=n2+1;
    int a[n1+1][n2+1];

    for( i=0;i<=n1;i++)
    {
        for(int j=0;j<=n2;j++)
        {
            if(i==0||j==0)
            a[i][j]=0;
            else 
            {if(s1[i-1]==s2[j-1])
            a[i][j]=a[i-1][j-1]+1;
            else
            a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
        
    }
    }
    
    char s[a[n1][n2]];
     i=n1;
     j=n2;
        int count=a[n1][n2];

    while((j!=0)&&(i!=0))
    {
        if(a[i-1][j]==a[i][j])
        i--;
        else if(a[i][j-1]==a[i][j])
        j--;
        else
        {
            s[count-1]=s1[i-1];
            i--;
            j--;
            count--;

        }
        
        
    }
    for(int i=0;i<a[n1][n2];i++)
    cout<<s[i];
    
    
    
    
    
return 0;
        
    
}

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    scanf("%d", &i);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    scanf("%lld", &i);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

constexpr char BR = '\n';

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

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

    vll fac(N+1, 1);
    for (int k = 2; k <= N; k++)
    {
        for (int j = k; j <= N; j += k)
        {
            ++fac[j];
        }
    }

    ll ans = 0;
    for (int k = 1; k <= N; k++)
    {
        ans += k * fac[k];
    }
    io << ans << BR;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

template<class T> T gcd(T a, T b) {
  if (a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, k;
  cin >> n >> k;
  vi32 a(n);
  rep(i, n) cin >> a[i];
  sort(all(a)); reverse(all(a));
  if (a[0] < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int mn = a[0];
  reps(i, n - 1) mn = gcd(mn, a[i]);
  rep(i, n) {
    if (a[i] < k) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    }
    if ((a[i] - k) % mn == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 640
N, M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
L = []

for i in range(M-1):
    L.append(X[i+1] - X[i])

L.sort()

if M - N <= 0:
    print(0)
else:
    print(sum(L[:M - N]))

Measured memory_bytes: 20624
#include<stdio.h>
long long div[10000];
int inde;

void getDiv(long long n){
  inde = 0;
  long long i;
  for(i=1;i*i<=n;i++)
    if(n%i == 0)
	{
	  div[inde++] = i;
	  if(i*i != n)
	    div[inde++] = n/i;
	}
}

long long gcd(long long x,long long y)
{
  long long r;
  if(x < y)
    {
      long long tmp = x;
      x = y;
      y = tmp;
    }
  while(y > 0)
    {
      r = x%y;
      x = y;
      y = r;
    }
  return x;
}

int main()
{
  long long n;
  
  while(1)
    {
      scanf("%lld",&n);
      if(n == 0)
	break;
      long long cnt = 0;
      long long i,j;
      getDiv(n);
      for(i=0;i<inde;i++)
	{
	  for(j=i;j<inde;j++)
	    {
	      long long a,b;
	      a = div[i];
	      b = div[j];
	      if(a/gcd(a,b)*b == n)
		cnt++;
	    }
	}
      printf("%lld\n",cnt);
    }
  
  return 0;
}

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

using ll=long long; 

bool hantei(int n){
	int ans=n;
	vector<int> yaku;
	for(int i=2; i*i<=ans; i++){
		int cnt=0;
		while(n%i==0){
			cnt++;
			n/=i;
		}
		yaku.push_back(cnt+1);
	}
	int ret=1;
	for(int i=0; i<yaku.size(); i++){
		ret*=yaku[i];
	}
	return ret==8;
}

void solve(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1; i<=n; i+=2){
		if(hantei(i)){
			cnt++;
		}
	}	
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}



Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;


set<int> nearStart;
set<int> nearGoal;
set<int> result;

signed main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
      int a, b;
      cin >> a >> b;
      if ( a == 1){
        nearStart.insert(b);
      } else if ( a == N){
        nearGoal.insert(b);
      } else if ( b == 1){
        nearStart.insert(a);
      } else if ( b == N){
        nearGoal.insert(a);
      }
    }
    set_intersection(nearStart.begin(),nearStart.end(),
                        nearGoal.begin(), nearGoal.end(),
                        inserter(result, result.end()));
    if (result.empty()){
      cout << "IMPOSSIBLE" << endl;
    }else{
      cout << "POSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 9600
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// ダブリング再実装

func main() {
	S := nextLine()
	N := len(S)
	ans := make([]int, N)
	MAXD := 333
	nex := make([][]int, MAXD+1)
	for i := 0; i < MAXD+1; i++ {
		nex[i] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		switch S[i] {
		case 'R':
			nex[0][i] = i + 1
		case 'L':
			nex[0][i] = i - 1
		}
	}
	for p := 0; p < MAXD; p++ {
		for r := 0; r < N; r++ {
			nex[p+1][r] = nex[p][nex[p][r]]
		}
	}
	for p := MAXD; p >= 0; p-- {
		if int(1e10)>>p&1 == 1 {
			for _, v := range nex[p] {
				ans[v]++
			}
			fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
			break
		}
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

int main(){
  string s,t;cin>>s>>t;
  int mini=0,mins=100007;
  
  for(int i=0;i+t.size()<=s.size();i++){
  	mini=0;
    for(int j=0;j<t.size();j++){
      if(t[j]!=s[j+i])mini++;
    }
    // cout<<mini<<" ";
    mins=min(mins,mini);
  }
  cout<<mins<<"\n";
 return 0; 
}

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

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

  cout << (N % K != 0 ? '1' : '0') << endl;
}

Measured memory_bytes: 3624
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m=map(int,input().split())
k=[]
s=[]
for _ in range(m):
	tmp=input_array()
	k.append(tmp[0])
	s.append(tmp[1:])
p=input_array()
ans=0
for i in range(2**n):
	tmp=[]
	ans_tmp=0
	for j in range(n):
		tmp.append(i>>j&1)
	for c in range(m): # スイッチのチェック
		sw=s[c]
		sum_sw=0
		for l in sw:
			if tmp[l-1]==1:
				sum_sw+=1
		if sum_sw%2==p[c]:
			ans_tmp+=1
	if ans_tmp==m:
		ans+=1

print(ans)

Measured memory_bytes: 9172
using System;

namespace ABC169C
{
    class Program
    {
        static void Main(string[] args)
        {
            var aa = Console.ReadLine().Split(" ");
            //ulong a = ulong.Parse(aa[0]);
            //ulong b = (ulong)(double.Parse(aa[1]) * 100);
            //ulong x =a * b;
            //x /= 100;
            ulong a = ulong.Parse(aa[0]);
            ulong b = ulong.Parse(aa[1].Replace(".", ""));
            ulong x = a * b / 100;
            
            Console.WriteLine(x);

        }
    }
}

Measured memory_bytes: 17740
#include<stdio.h>
#include<string.h>
int n,m,t;
	char a[105][105];
	char b[105]={"0"};
	char c[10005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	scanf("%s",a[i]);
	for(int i=0;i<n-1;i++)
	for(int j=0;j<n-1-i;j++)
	{
		t=strcmp(a[j],a[j+1]);
		if(t>0)
		{
		strcpy(b,a[j]);
		strcpy(a[j],a[j+1]);
		strcpy(a[j+1],b);
	     }
	}
	strcpy(c,a[0]);
	for(int i=1;i<n;i++)
	strcat(c,a[i]);
	printf("%s",c);
	return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {


	int a, b, c;
	cin >> a >> b >> c;
	cout << c - min(a - b, c) << endl;









}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
vector<vector<int>> adj;
vector<bool> vis;
const ll MOD = 1e9 + 7;
ll n, k, res;
int dfs(int s)
{
    ll r = 2;
    if(s == 0) r = 1;
    F0R(i, sz(adj[s]))
    {
        if(!vis[adj[s][i]]) 
        {
            if(k - r < 0) res = 0; 
            res *= (k - r);
            res %= MOD;
            r++;
            vis[adj[s][i]] = true;
            dfs(adj[s][i]);
        }
    }
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    res = k;
    adj.assign(n, vector<int>());
    F0R(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vis.assign(n, false);
    vis[0] = true;
    dfs(0);
    cout << res;
    return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

bool solve(ll y, ll m, ll d) {
  if (y < 2019) return true;
  if (y > 2019) return false;

  if (m < 4) return true;
  if (m > 4) return false;

  if (d < 30) return true;
  if (d > 30) return false;

  return true;
}

int main(void) {
  string S;
  cin >> S;

  ll y = 0;
  REP(i, 0, 4) y = y * 10 + (S[i] - '0');

  ll m = 0;
  REP(i, 5, 7) m = m * 10 + (S[i] - '0');

  ll d = 0;
  REP(i, 8, 10) d = d * 10 + (S[i] - '0');

  // cerr << y << " " << m << " " << d << endl;

  cout << (solve(y, m, d) ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    
    ll n,x,t;
    cin>>n>>x>>t;
    ll ans = n/x;
    if(n%x!=0) ans++;
    cout<<ans*t<<"\n";
}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

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

	int ans = 0;
	ans += max(a,b);
	if(a>b) a--;
	else b--;
	ans += max(a,b);

	cout << ans << endl;
	

}

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

int main(){
    int n, m, flag = 0; 
    int s[7];
    char c[7];

    cin >> n >> m;
    for(int i = 0; i < m; i++) cin >> s[i] >> c[i];

    if(m == 0 && n > 1){
        cout << to_string((int)pow(10,n-1)) << endl;
        exit(0);
    }

    for(int i = 0; i < (int)pow(10,n); i++){
        string t = to_string(i);
        bool flag = true;
        for(int j = 0; j < m; j++){
            if(n > 1 && s[i] == 1 && c[i] == '0')
                flag = flag && false;
            if(t[s[j]-1] == c[j])
                flag = flag && true;
            else
                flag = flag && false;

            if(n > 2 && i < 100)
                flag = flag && false;
            else if(n > 1 && i < 10)
                flag = flag && false;
            
        }
        

        if(flag){
            cout << t << endl;
            exit(0);
        }
    }

    cout << "-1" << endl;

    return 0;
}

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

int main() {
  int N;
  long A[100010];
  long B[100010];

  cin >> N;
  for (int i = 0; i <= N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  
  long ans = 0;
  for (int i = 0; i < N; i++) {
    bool flg = true;
    int f = 0;
    int life = 0;
    while(flg) {
      f = A[i] - B[i];
      if (f<0) {
        flg = false;
        ans += A[i];
        life = B[i]-A[i];
        f = A[i+1] - life;
        if (f < 0) {
          ans += A[i+1];
          A[i+1] = 0;
        } else if (f==0) {
          ans += A[i+1];
          A[i+1] = 0;
        } else {
		  ans += life;
          A[i+1] = f;
        }
      } else if (f==0) {
        flg = false;
        ans += A[i];
      } else {
        flg = false;
        ans += B[i];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
from collections import deque

k = int(input())

dq = deque(range(1, 10))
cnt = 9
li = []
while cnt < 10 ** 5 + 10:
    num = dq.popleft()
    li.append(num)
    lst = num % 10
    if lst == 0:
        dq.append(num * 10)
        dq.append(num * 10 + 1)

    elif lst == 9:
        dq.append(num * 10 + 8)
        dq.append(num * 10 + 9)

    else:
        for i in range(lst - 1, lst + 2):
            dq.append(num * 10 + i)

    cnt += 1

ans = li[k-1]
print(ans)


Measured memory_bytes: 50800
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e5+5

void solve(){
    int a, b;
    cin>>a>>b;
    ll x = (a+b)/2;
    if((a+b)%2==0){
        print(x);
    }
    else print("IMPOSSIBLE");
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   

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



Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  val m = (1 << 9) - 1

  def solve(sc: => Scanner): Unit = {
    println(getPrimeList.filter(_ % 5 == 4).take(sc.nextInt).force.mkString(" "))
  }

  def recursive(now: Int, A: Array[List[Int]]): Int = {
    if (A(now).size == 0) (now) else {
      val next = A(now).head
      A(now) = A(now).filter(_ != next)
      A(next) = A(next).filter(_ != now)
      recursive(next, A)
    }
  }

  def getPermutation(now: Long = 0): Stream[Long] = {
    Stream.cons(now, getPermutation(now + 1))
  }

  def getPrimeList(): Stream[Long] = {
    getPrimeListRecursive(getPermutation(2))
  }

  def getPrimeListRecursive(A: Stream[Long]): Stream[Long] = {
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))
  }

  def check(A: Array[List[Int]]): Boolean = {
    A.map(_.size == 0).fold(true)((a, b) => a & b)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 32464
H,W=map(int,input().split())
graph=[list(input()) for _ in range(H)]
onesteps=((-1,0),(0,-1),(1,0),(0,1))
for x in range(H):
    for y in range(W):
        if graph[x][y]=="#":
            flag=0
            for dx,dy in onesteps:
                if (0<=x+dx<H) and (0<=y+dy<W):
                    if graph[x+dx][y+dy]=="#":
                        flag+=1
            if flag==0:
                print('No')
                exit(0)
print('Yes')

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
a,b,c,d,e=MI()
time=60*(c-a)+(d-b)
print(time-e)
    
        


Measured memory_bytes: 9488
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] input = new int[n];

		for (int i = 0; i < n; i++) {
			input[i] = sc.nextInt();
		}
		
		int swap = selectionSort(input);
		System.out.println(format(input));
		System.out.println(swap);
	}
	
	static int selectionSort(int[] a) {
		int swap = 0;
		for (int i = 0; i < a.length; i++) {
			int minj = i; // i????????\?????§????°????????´????????????????????????????
			for (int j = i; j < a.length; j++) {
				if (a[minj] > a[j]) {
					minj = j;
				}
			}
			if (minj != i) {
				int tmp = a[i];
				a[i] = a[minj];
				a[minj] = tmp;
				swap++;
			}
		}
		return swap;
	}
	
	static String format(int[] a) {
		return IntStream.of(a).mapToObj(n -> String.valueOf(n)).collect(Collectors.joining(" "));
	}
}

Measured memory_bytes: 32340
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;

class info
{
public:
	int value;
	vector <bool> visited;

	info()
	{
		value = 0;
	}
};

int main( void )
{
	int case_no = 1;
	int w_max;
	while ( cin >> w_max && w_max )
	{

		// Â
		int n;
		cin >> n;

		// îñ
		vector <int> v( n );
		vector <int> w( n );

		// üÍ
		for ( int i = 0; i < n; i++ )
		{
			string in;
			cin >> in;
			replace( in.begin(), in.end(), ',', ' ' );

			int vi, wi;
			istringstream is( in );
			is >> vi >> wi;

			v[i] = vi;
			w[i] = wi;
		}

		// sort
		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i+1; j < n; j++ )
			{
				if ( w[i] > w[j] )
				{
					swap( w[i], w[j] );
					swap( v[i], v[j] );
				}
				else if ( w[i] == w[j] )
				{
					if ( v[i] < v[j] )
					{
						swap( v[i], v[j] );
					}
				}
			}
		}

		vector <info> dp( w_max + 1 );

		for ( int i = 0; i < n; i++ )
		{
			int& wi = w[i];
			int& vi = v[i];

			if ( dp[wi].value < vi )
			{
				dp[wi].value = vi;
				dp[wi].visited = vector <bool>( n );
				dp[wi].visited[i] = true;
			}
		}

		for ( int i = 0; i <= w_max; i++ )
		{
			if ( dp[i].value > 0 )
			{
				for ( int j = 0; j < n; j++ )
				{
					int& wj = w[j];
					int& vj = v[j];
					if ( i + wj > w_max )
						continue;

					if ( dp[i].visited[j] )
						continue;

					if ( dp[i].value + vj > dp[i+wj].value )
					{
						dp[i+wj].value = dp[i].value + vj;
						dp[i+wj].visited = dp[i].visited;
						dp[i+wj].visited[j] = true;
					}
				}
			}
		}

		int maxw = 0;
		int maxv = 0;
		for ( int i = 0; i <= w_max; i++ )
		{
			if ( dp[i].value <= 0 )
				continue;

			if ( maxv < dp[i].value )
			{
				maxw = i;
				maxv = dp[i].value;
			}
		}

		cout << "Case " << case_no << ":" << endl;
		cout << maxv << endl;
		cout << maxw << endl;

		case_no ++;
	}

	return 0;
}

Measured memory_bytes: 0
class Dice():
    def __init__(self):
        self.num = [0 for _ in range(6)]
    
    def set_num(self, n0, n1, n2, n3, n4, n5):
        self.num[0] = n0
        self.num[1] = n1
        self.num[2] = n2
        self.num[3] = n3
        self.num[4] = n4
        self.num[5] = n5
    
    def roll(self, order):
        tmp = self.num.copy()
        
        if order == "N":
            self.set_num(tmp[1], tmp[5], tmp[2], tmp[3], tmp[0], tmp[4])
        elif order == "S":
            self.set_num(tmp[4], tmp[0], tmp[2], tmp[3], tmp[5], tmp[1])
        elif order == "E":
            self.set_num(tmp[3], tmp[1], tmp[0], tmp[5], tmp[4], tmp[2])
        elif order == "W":
            self.set_num(tmp[2], tmp[1], tmp[5], tmp[0], tmp[4], tmp[3])
        else:
            print("Error: 不正な入力です")

    def get_top_num(self):
        return self.num[0]
        
    
# Input
init_num = [int(_) for _ in input().split()]
order_string = str(input())

# Main 
dice = Dice()
dice.set_num(init_num[0], init_num[1], init_num[2], init_num[3], init_num[4], init_num[5])

for i, order in enumerate(order_string):
    dice.roll(order)

print(dice.get_top_num())


Measured memory_bytes: 5608
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;


 VI sosuu,kosuu;
            signed main(){
            	int n;
   cin>>n;
            	int nn=n;
            	for(int i=2;i<=100000;i++){
            		if(nn%i!=0) continue;
            		int an=0;
            		while(nn%i==0){
            		an++;
            		nn/=i;
            		}
            		sosuu.pb(i);
            		kosuu.pb(an);
            	}
            	if(nn>1){
            		sosuu.pb(nn);
            		kosuu.pb(1);
            		
            		
            	}
            	cout<<n<<":";
            	for(int  i=0;i<sosuu.size();i++){
            		
            		for(int k=0;k<kosuu[i];k++)cout<<" "<<sosuu[i];
            	}
            	cout<<endl;
            	
            }
             

Measured memory_bytes: 3144
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int main() {
  int n, t[50], ans = 0;
  char s[50][110], x[110];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    scanf("%d", &t[i]);
    ans+=t[i];
  }
  scanf("%s", x);
  for (int i = 0; i < n; i++) {
    ans -= t[i];
    if (strcmp(s[i], x) == 0) {
      break;
    }
  }
  printf("%d\n", ans);
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 3005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li][li][4];
int cev;
string s;
vector<int> v;

inline int f(int l,int r,int kim){
	int cevv=0;
	if(kim==0)cevv=-inf;
	else cevv=inf;
	if(l>r)return 0;
	if(~dp[l][r][kim])return dp[l][r][kim];
	if(kim==0){
		cevv=max(cevv,f(l+1,r,!kim)+a[l]);
		cevv=max(cevv,f(l,r-1,!kim)+a[r]);
	}
	else{
		cevv=min(cevv,f(l+1,r,!kim)-a[l]);
		cevv=min(cevv,f(l,r-1,!kim)-a[r]);
	}
	return dp[l][r][kim]=cevv;
}

main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
	}
	printf("%lld\n",f(1,n,0));
	return 0;
}


Measured memory_bytes: 282624