akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int datacount;
    cin >> datacount;
    for (; datacount > 0; datacount--) {
        string s;
        cin >> s;
        vector<vector<int>> v;
        int index = -1;
        long long nownum = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '[') {
                v.push_back(vector<int>());
                index++;
            } else if (s[i] == ']') {
                sort(v[index].begin(), v[index].end());
                int count = 0;
                for (int i = 0; i <= v[index].size() / 2; i++)count += v[index][i];

                index--;
                if (index < 0) {
                    cout << count << endl;
                } else {
                    v.pop_back();
                    v[index].push_back(count);
                }
            } else {
                nownum = nownum * 10 + (s[i] - '0');
                if (s[i + 1] == ']') {
                    v[index].push_back(nownum / 2 + 1);
                    nownum = 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
const int N = 100001;
string s1, s2, ans;
int dp[3001][3001];
int main(){
    cin >> s1 >> s2;
    for(int i = 0; i < s1.size(); i++){
        for(int j = 0; j < s2.size(); j++){
            if(s1[i] == s2[j])
                dp[i + 1][j + 1] = dp[i][j] + 1;
            else
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
    }
    int i=s1.size(),j=s2.size();
    while(i > 0 && j > 0){
        if(dp[i-1][j] == dp[i][j])
            i--;
        else if(dp[i][j-1] == dp[i][j])
            j--;
        else{
            ans+=s1[i-1];
            i--;
            j--;
        }
    }
    reverse(all(ans));
    cout<<ans;
}



Measured memory_bytes: 38196
#include <bits/stdc++.h>
using namespace std;
 int main() {
int a,b,c;
   cin >> a;
   int x,y,z;
   z = a/100;
   b = a%100;
   y = b/10;
   x = b%10;
   
   if(a==(100*x+10*y+z)) cout <<"Yes"<<endl;
   else cout <<"No"<<endl;
   }
   


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

using namespace std;

int main()
{
	int N, Q, ans;
	
	cin >> N >> Q;
	
	string S;
	
	cin >> S;
	
	vector<int> l(Q), r(Q);
	
	for (int i = 0; i < Q; i++) {
		cin >> l[i] >> r[i];
	}
	
	vector<int> t(N, 0);
	
	for (int i = 0; i < N; i++) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			t[i + 1] += t[i] + 1;
		}
		else {
			t[i + 1] = t[i];
		}
	}
	
	for (int i = 0; i < Q; i++) {
		cout << t[r[i] - 1] - t[l[i] - 1] << endl;
	}
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n,i,j,k;
	cin>>n>>k;
	long int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	long int dp[n];
	dp[0]=0;
	dp[1]=a[1]-a[0];
	if(dp[1]<0)
	dp[1]=dp[1]*-1;
	for(i=2;i<n;i++)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		for(j=2;j<=k;j++)
		{
			if(i-j<0)
			break;
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout<<dp[n-1];
    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,temp;
	std::vector<std::vector<int>> v;
	std::cin >> n;
	for (size_t i = 0; i < 2; i++) {
		std::vector<int> tempv;
		for (size_t j = 0; j < n; j++) {
			std::cin >> temp;
			tempv.push_back(temp);
		}
		v.push_back(tempv);
	}

	int maxAme = -1;
	for (size_t i = 0; i < n; i++) {
		int ame = 0;
		for (size_t j = 0; j <= i; j++) {
			ame += v[0][j];
		}
		for (size_t j = i; j < n; j++) {
			ame += v[1][j];
		}
		maxAme = max(maxAme, ame);
	}

	std::cout << maxAme << '\n';
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=sorted([int(c) for c in input().split()])
D={c:0 for c in A}
for a in A:
  D[a]+=1
tmp=0
for d in D:
  D[d]=(D[d]+1)%2+1
  if(D[d]==2):
    tmp+=1
if(tmp%2==1):
  print(len(D)-1)
else:
  print(len(D))

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n){
        int x; cin>>x;
        a[i]=--x;
    }
    ll cnt=0,tmp=0;
    while(true){
        if(tmp==1){
            cout<<cnt<<endl;
            break;
        }
        else if(cnt>=n){
            cout<<"-1"<<endl;
            break;
        }
        cnt++;
        tmp=a[tmp];
    }
    return 0;
}


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

long long int n,d;
int a[15][15];
double cc = 0 ;

int main(){
    cin>>n>>d;
    int cnt = 0;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < d ; j++){
            cin>>a[i][j];
        }
    }
    for(int i = 0 ; i < n - 1  ; i++){
        for(int j = i + 1 ; j < n ; j++){
            for(int k = 0 ; k < d ; k++){
                cc += abs(a[i][k] - a[j][k])*abs(a[i][k] - a[j][k]);
            }
            cc = sqrt(cc);
            if (floor(cc) == ceil(cc))
                cnt += 1;
            cc = 0;
        }
    }
    cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  ll K,t=0;
  cin>>S>>K;
  bool CAN=true;
  for(ll i=0; i<min((long long)S.size(),K); ++i){
    if(S.at(i)>'1'){
      cout<<S.at(i)<<endl;
      return 0;
    }
  }
  cout<<1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int D,T,S;
	cin >> D >> T >> S;
	if (T * S >= D)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main(void){
	
	int a,b,op;
	int answer;	

	while(1){
		scanf("%d %c %d",&a,&op,&b);

		if(op=='+')answer=a+b;
		if(op=='-')answer=a-b;
		if(op=='*')answer=a*b;
		if(op=='/')answer=a/b;
	
		if(op=='?')break;
		printf("%d\n",answer);
	}
	return 0;
}

Measured memory_bytes: 600
use std::io;
use std::cmp::Ordering;

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

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

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

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

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

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

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

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

fn main() {
    input!{
        a: i32,
        b: i32,
    }

    match a.cmp(&b){
        Ordering::Less => println!("a < b"),
        Ordering::Greater => println!("a > b"),
        Ordering::Equal => println!("a == b"),
    }
}



Measured memory_bytes: 5024
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;

int atcoder(){
    //入力
    int a,b,c;
    cin >> a >> b >> c;
    int cnt=0;
    int ans;
    
    for(int i=100; cnt<c; --i){
        if(a%i==0 && b%i==0) cnt++;
        ans = i;
    }

    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import java.util.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String o="APPROVED";
		int n=sc.nextInt();
        int[] a=new int[n];
      for(int i=0;i<n;i++){
      	a[i]=sc.nextInt();
      }
      for(int i=0;i<n;i++){
      	if(a[i]%2==0&&(a[i]%3!=0&&a[i]%5!=0))o="DENIED";
      }
        
      	System.out.println(o);
    }
    
}

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

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  while(y >= 2*x) {
    ans++;
    x *= 2;
  }
  ans++;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define int long long
bool isprime(int num){ // 判断是否是素数
    if(num==1){
        return false;
    }
    if(num==2)
        return true;
    if(num%2==0)
        return false;
    double sqrtNum = sqrt(num);
    for (int  i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
vector<int> v;
signed main(){
    int n,m;
    cin>>n>>m;
    int temp=min(n,m);
    for(int i=1;i*i<=temp;i++){ // 求一个数的因子的模板
        if(temp%i==0){
            v.push_back(i);
            if(i*i!=temp){
                v.push_back(temp/i);
            }
        }
    }
    int ans=0;
    int t=max(n,m);
    for(int i=0;i<v.size();i++){
        if(t%v[i]==0&&isprime(v[i]))
            ans++;
    }
    cout<<ans+1;
    return 0;
}

Measured memory_bytes: 384
#オイラーのφ関数
import math
n = m =int(input())
i = 2
while i <= math.sqrt(n):
    if n%i == 0:
        m = int(m*(1-1/i))
        while n%i == 0:n //=i
    i+=1
if n != 1:m = int(m*(1-1/n));
print(m)


Measured memory_bytes: 5660
#include <iostream>
#include <string>
#include <limits.h>


int main()
{
	int min = INT_MAX, nrMax = INT_MAX;
	std::string str;
	std::getline(std::cin, str);
	
	for (int i = 0; i < 26; ++i)
	{
		int nr = 0;
		bool flag = false, flag2 = true;
		
		for (int j = 0; j < str.length(); ++j)
			if (str[j] != 'a' + i)
				flag = true;
		
		for (int j = 0; j < str.length(); ++j)
			if (str[j] == 'a' + i)
				flag2 = false;
		
		if (flag2)
			continue;
		
		if (!flag)
		{
			std::cout << 0;
			return 0;
		}
		
		std::string str2 = str;
		
		while (flag)
		{
			bool flag3 = false;
			for (int j = 0; j < str.length() - nr; ++j)
			{
				if (str2[j] == 'a' + i && j != 0 && str2[std::max(j - 1, 0)] != 'a' + i)
				{
					str2[j - 1] = 'a' + i;
					flag3 = true;
				}
//				getch();
			}
			
			++nr;
			
			flag = false;
			for (int j = 0; j < str.length() - nr; ++j)
				if (str2[j] != 'a' + i)
					flag = true;
//			std::cout << str2 << " ";
			
		}
		
		if (nr < nrMax)
			nrMax = nr;
		
	}
	std::cout << nrMax;
}

Measured memory_bytes: 256
def dfs(f):
    if vis[f] == 1:
        return
    vis[f] = 1 #fを訪問済にする
    for t in v[f]: #fとつながっている頂点を読み込む
        if f != a or t != b: #(a,b)の組み合わせでなければ繰り返す
            dfs(t)

n, m = map(int, input().split())
v = [[] for i in range(n)]
e = []

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    e.append([a, b])

ans = 0

for a, b in e:
    vis = [0]*n
    dfs(a)
    if vis[b] == 0: #aからa-bの辺以外を辿ってbに行けるなら1になる
        ans += 1

print(ans)

Measured memory_bytes: 9220
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] size; // size of subtree, including self
    List<Integer>[] graph;
    long[] dp,ans;
    final long mod = 1000000000+7;
    long[] frac,inv; // inv[i] = the inversion of i! mod M
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
        out.flush();
//        System.out.println(main.solve());
    }
    long solve() throws IOException{
        int k = sc.nextInt();
        if(k<=12) {
            out.println(k);
            return k;
        }
        List<Node> curr = new ArrayList<>(), next = new ArrayList<>();
        for(int i=1;i<=9;i++){
            curr.add(new Node(i));
        }
        Set<Node> used = new HashSet<>();
        Node res = new Node(233);
        int cnt = 0;
        while(cnt < k){
            for(Node n:curr){
                cnt += 1;
                if(cnt==k){
                    res = n;
                    break;
                } else{
                    used.add(n);
                    for(int i=-1;i<=1;i++){
                        if(n.val+i>=0&&n.val+i<=9){
                            Node temp = new Node(n.val+i);
                            temp.prev = n;
                            next.add(temp);
                        }
                    }
                }
            }
            if(cnt<k){
                curr = next; next = new ArrayList<>();
            }
        }
        StringBuilder sb = new StringBuilder();
        while(res!=null){
            sb.append(res.val);
            res = res.prev;
        }
        out.println(sb.reverse().toString());
        return 0;

    }
    class Node{
        int val; Node prev;
        public Node(int x){
            val = x;
        }
    }
}



Measured memory_bytes: 52600
#include <cstdio>
#include <vector>
#include <functional>
#include <algorithm>
#include <set>
using namespace std;

using i32 = int;
using i64 = long long;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
T read() {
  T a = 0;
  for(;;) {
    char c = getchar();
    if ('0' <= c && c <= '9') {
      a = a * 10 + c - 48;
    } else {
      return a;
    }
  }
}

signed main() {
//  i32 x, y, z, k;
//  scanf("%d%d%d%d", &x, &y, &z, &k);
  i32 x = read<i32>(),
      y = read<i32>(),
      z = read<i32>(),
      k = read<i32>();
  vector<i64> A(x), B(y), C(z);
//  REP(i, x) scanf("%lld", &A[i]);
//  REP(i, y) scanf("%lld", &B[i]);
//  REP(i, z) scanf("%lld", &C[i]);
  REP(i, x) A[i] = read<i64>();
  REP(i, y) B[i] = read<i64>();
  REP(i, z) C[i] = read<i64>();
  sort(ALL(A), greater<i64>());
  sort(ALL(B), greater<i64>());
  sort(ALL(C), greater<i64>());
  using P = pair<i64, i64>;
  set<P> Q;
  Q.insert({-(A[0] + B[0] + C[0]), 0});
  REP(_, k) {
    i64 p = -(*Q.begin()).first;
    i64 q = (*Q.begin()).second;
    printf("%lld\n", p);
    Q.erase(Q.begin());
    i32 u = q & 1023;
    i32 v = q >> 10 & 1023;
    i32 w = q >> 20 & 1023;
    i64 u1 = q + 1;
    i64 v1 = q + (1 << 10);
    i64 w1 = q + (1 << 20);
    if (u + 1 < x) Q.insert({-(A[u + 1] + B[v] + C[w]), u1});
    if (v + 1 < y) Q.insert({-(A[u] + B[v + 1] + C[w]), v1});
    if (w + 1 < z) Q.insert({-(A[u] + B[v] + C[w + 1]), w1});
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    // std::cout << std::fixed << std::setprecision(10);
    int a[3][3] = {0};
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            std::cin >> a[i][j];
        }
    }
    
    int n; std::cin >> n;
    for(int i=0; i<n; i++)
    {
        int temp;
        std::cin >> temp;
        for(int i=0; i<3; i++)
        {
            for(int j=0; j<3; j++)
            {
                if(temp==a[i][j]) a[i][j]=-1;
            }
        }
    }

    int bingo[8] = {1, 1, 1, 1, 1, 1, 1, 1};
    for(int i=0; i<3; i++)
    {
        if(a[0][i]!=-1) bingo[0] = 0;
        if(a[1][i]!=-1) bingo[1] = 0;
        if(a[2][i]!=-1) bingo[2] = 0;
        if(a[i][0]!=-1) bingo[3] = 0;
        if(a[i][1]!=-1) bingo[4] = 0;
        if(a[i][2]!=-1) bingo[5] = 0;
        if(a[i][i]!=-1) bingo[6] = 0;
        if(a[2-i][i]!=-1) bingo[7] = 0;
    }

    int ans = 0;
    for(int i=0; i<8; i++)
    {
        ans += bingo[i];
    }
    std::cout << ((ans>=1) ? "Yes\n" : "No\n");


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int ans=10000,n,i,t,sum1=0,sum2=0,j=1,m,b;
    int a[105];
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);
    while(j<n)
    {
        sum1=0;
        sum2=0;
        for(i=1; i<=n; i++)
        {
            if(i<=j) sum1+=a[i];
            else sum2+=a[i];
        }
        b=sum1-sum2;
        m=abs(b);
        if(m<ans) ans=m;
        j++;
    }
    printf("%d\n",ans);
}


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

class UnionFind {
public:
vector<int> Parent;

UnionFind(int N) {
  Parent = vector<int>(N, -1);
}

int root(int A) {
  if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

int size(int A) {
  return -Parent[root(A)];
}

bool connect(int A, int B) {
  A = root(A);
  B = root(B);
  if (A == B) {
    return false;
  }
  if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  vector<int> vec(n);

  UnionFind uni(n);
  for (int i = 0; i < m; i++)
  {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    uni.connect(a,b);
    vec[a]++;
    vec[b]++;
  }
  for (int i = 0; i < k; i++)
  {
    int c,d;
    cin >> c >> d;
    c--;
    d--;
    if(uni.root(c) == uni.root(d)){
      vec[c]++;
      vec[d]++;
    }
  }

  for (int i = 0; i < n; i++)
  {
    int ans = 0;
    cout << uni.size(i) - 1 - vec[i] << " ";
  }
  cout << endl;  
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>

void ins_sort(std::vector<int> vec) {
    int n = vec.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if(vec[j] > vec[i]) {
                int tmp = vec[j];
                vec[j] = vec[i];
                vec[i] = tmp;
            }
        }
        for(int it = 0; it < n - 1; it++) {
            std::cout << vec[it] << " ";
        }
        std::cout << vec[n-1] << std::endl;
    }
}


int main(int argc, char const* argv[])
{
    int n = 0;
    std::cin >> n;
    std::vector<int> ary(n);
    for (auto& i: ary) {
        std::cin >> i;
    }
    ins_sort(ary);
    return 0;
}

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

int selectionSort(vector<int> &A, int N){
    int count = 0;
    for(int i = 0; i < N; i++){
        int tmp_min = A.at(i);
        int tmp_j = i;
        for(int j = i + 1; j < N; j++){
            if(tmp_min > A.at(j)){
                tmp_min = A.at(j);
                tmp_j = j;
            }
            //cout << tmp_min << endl;
            }
        if(i != tmp_j){
            count++;
        }
        swap(A.at(i), A.at(tmp_j));
    }
    return count;
}

int main(){
    int N, count;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    count = selectionSort(A, N);

    for(int i = 0; i < N; i++){
        if(i!=0){
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  vector<int> x(5);
  rep(i,5) cin >> x[i];
  rep(i,5) {
    if (x[i] == 0) cout << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

struct DList {
  int key;
  struct DList *prev, *next;
};

/* global variables */

/* subroutines */

void print_dlist(DList *root) {
  for (DList *dl = root->next; dl != root; dl = dl->next) {
    printf("%d", dl->key);
    if (dl->next != root) putchar(' ');
  }
  putchar('\n');
}

/* main */

int main() {
  DList head;
  head.key = -1;
  head.next = head.prev = &head;

  int n;
  int tmp = scanf("%d", &n);

  while (n--) {
    char c[16];
    tmp = scanf("%s", c);
    
    if (c[0] == 'i') {
      int x;
      tmp = scanf("%d", &x);

      DList *dl = new DList();
      dl->key = x;
      dl->prev = &head;
      dl->next = head.next;
      head.next = dl->next->prev = dl;
    }
    else if (c[0] == 'd' && c[6] == '\0') {
      int x;
      tmp = scanf("%d", &x);

      DList *dl;
      for (dl = head.next; dl != &head; dl = dl->next)
	if (dl->key == x) {
	  dl->prev->next = dl->next;
	  dl->next->prev = dl->prev;
	  break;
	}
    }
    else if (c[0] == 'd' && c[6] == 'F') {
      DList *dl = head.next;
      dl->prev->next = dl->next;
      dl->next->prev = dl->prev;
    }
    else if (c[0] == 'd' && c[6] == 'L') {
      DList *dl = head.prev;
      dl->prev->next = dl->next;
      dl->next->prev = dl->prev;
    }

    //print_dlist(&head);
  }

  print_dlist(&head);
  return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int x[80][111111];
ll diff[111111];

int main(){
	
	ll n;cin >> n;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	ll m,k;cin >> m >> k;
	vector<ll> a(m);
	REP(i,m){
		cin >> a[i];
	}
	
	REP(i,n)x[0][i] = i;
	REP(i,m)swap(x[0][a[i]],x[0][a[i]-1]);
	
	for(int i = 0;i < 69;i++){
		REP(j,n){
			x[i+1][j] = x[i][x[i][j]];
		}
	}
	
	for(int i = 1;i < n;i++){
		int tmp = i;
		for(ll j = 0;j < 60;j++){
			if(k & (1LL << j)){
				tmp = x[j][tmp];
			}
		}
		diff[i] = v[tmp] - v[tmp-1];
	}

	diff[0] = v[0];
	cout << v[0] << endl;
		
	for(int i = 1;i < n;i++){
		diff[i] += diff[i-1];
		cout << diff[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 35456
#include<stdio.h>
#include<math.h>

typedef struct {
  
  double x, y;
  
} Point;

void print(Point );
void kock(int , Point , Point );


  
int main(){
  
  int n;
  Point p1, p2;
  
  scanf("%d", &n);

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  
  print(p1);
  kock(n , p1, p2);
  print(p2);

  return 0;
}

void print(Point p){
  
  printf("%.8f %.8f\n", p.x, p.y);
  
}


void kock(int n, Point p1, Point p2){
  
  Point s, t, u;
  double theta;
  
  theta = 60.0 * (acos(-1) / 180.0);
  
  if ( n == 0 ) return;
  
  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  
  u.x = (t.x - s.x) * cos(theta) - (t.y - s.y ) * sin(theta) + s.x;
  u.y = (t.x - s.x) * sin(theta) + (t.y - s.y ) * cos(theta) + s.y;
  
  kock(n-1, p1, s);
  print(s);
  kock(n-1, s, u);
  print(u);
  kock(n-1, u, t);
  print(t);
  kock(n-1, t, p2);
}

Measured memory_bytes: 640
N, K = map(int, input().split())
A = list(map(lambda a: int(a) - 1, input().split()))
INF = 10**18

minDist = [INF] * N
minDist[0] = 0

now = 0
R = 0
while minDist[now] < INF:
    to = A[now]
    if minDist[to] < INF:
        R = minDist[now] + 1 - minDist[to]
        break
    minDist[to] = minDist[now] + 1
    now = to

if minDist.count(K) > 0:
    print(minDist.index(K) + 1)
    exit()

K -= minDist[now]
M = K % R
for _ in range(M):
    now = A[now]
print(now + 1)

Measured memory_bytes: 32380
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	string s, t; cin >> s >> t;
	vector<string> ss(s.size()), tt(t.size());
	for (int i = 0; i < s.size(); i++) {
		ss[i] = s[i];
	}
	for (int i = 0; i < t.size(); i++) {
		tt[i] = t[i];
	}
	ssort(ss);
	sort(tt.rbegin(), tt.rend());
	string as, at;
	for (int i = 0; i < ss.size(); i++) {
		as += ss[i];
	}
	for (int i = 0; i < tt.size(); i++) {
		at += tt[i];
	}
	if (as < at) cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Usize1;

struct State {
    c: Vec<i32>,
    s: Vec<Vec<i32>>,
    cur_seq: Vec<usize>,
    last: Vec<i32>,
    sat: i32,
}

impl State {
    fn init(&mut self) {
        self.last = vec![0; 26];
        self.sat = 0;

        for i in 0..self.cur_seq.len() {
            self.sat += self.s[i][self.cur_seq[i]];
            self.last[self.cur_seq[i]] = (i + 1) as i32;
            for j in 0..26 {
                self.sat -= self.c[j] * ((i + 1 - self.last[j] as usize) as i32);
            }
        }
    }

    fn change(&mut self, d: usize, q: usize) {
        self.sat -= self.s[d][self.cur_seq[d]];
        self.sat += self.s[d][q];

        self.last = vec![0; 26];
        for i in 0..self.cur_seq.len() {
            self.last[self.cur_seq[i]] = (i + 1) as i32;
            let j = self.cur_seq[d];
            self.sat += self.c[j] * ((i + 1 - self.last[j] as usize) as i32);
            self.sat += self.c[q] * ((i + 1 - self.last[q] as usize) as i32);
        }

        self.last = vec![0; 26];
        let p = self.cur_seq[d];
        self.cur_seq[d] = q;
        for i in 0..self.cur_seq.len() {
            self.last[self.cur_seq[i]] = (i + 1) as i32;

            self.sat -= self.c[p] * ((i + 1 - self.last[p] as usize) as i32);
            self.sat -= self.c[q] * ((i + 1 - self.last[q] as usize) as i32);
        }
    }

    fn score(&self) -> i32 {
        std::cmp::max(self.sat + 1000_000, 0)
    }
}

fn main() {
    input! {
        d: usize,
        c: [i32;26],
        s: [[i32;26]; d],
        t: [Usize1; d],
        m: usize,
        dq: [(Usize1, Usize1); m],
    }

    let mut state = State {
        c,
        s,
        cur_seq: t,
        last: vec![],
        sat: 0,
    };

    state.init();

    for (d, q) in dq {
        state.change(d, q);
        println!("{}", state.sat);
    }
}


Measured memory_bytes: 4120
import bisect
a,b,q=map(int,input().split())
INF = 12345678901234
s=[int(input())for _ in range(a)]
s.append(INF)
s.insert(0,-INF)
t=[int(input())for _ in range(b)]
t.append(INF)
t.insert(0,-INF)
for query in range(q):
    ans = INF
    x=int(input())
    idxs = bisect.bisect_left(s,x)
    idxt = bisect.bisect_left(t,x)
    ls = x - s[idxs-1]
    rs = s[idxs] - x
    lt = x - t[idxt-1]
    rt = t[idxt] - x
    
    ans = min( ans, max(ls,lt) )
    ans = min( ans, max(rt,rs) )    
    ans = min( ans, ls + rt + min(ls,rt) )
    ans = min( ans, lt + rs + min(lt,rs) )
    
    print(ans)

Measured memory_bytes: 12072
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n;
void solve(){
	string s,t;
	cin>>s>>t;
	cout<<t<<s;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 26;
	static int MOD = 998244353;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String str = in.nextString();
			int[] num = new int[4];
			for (int i = 0; i < 4; i++) {
				num[i] = Integer.parseInt(str.substring(i, i+1));
			}

			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 2; j++) {
					for (int k = 0; k < 2; k++) {
						int s = num[0];
						if (i == 0) {
							s += num[1];
						} else {
							s -= num[1];
						}
						if (j == 0) {
							s += num[2];
						} else {
							s -= num[2];
						}
						if (k == 0) {
							s += num[3];
						} else {
							s -= num[3];
						}
						if (s == 7) {
							StringBuffer sb = new StringBuffer();
							sb.append(num[0]);
							if (i == 0) {
								sb.append("+");
							} else {
								sb.append("-");
							}
							sb.append(num[1]);
							if (j == 0) {
								sb.append("+");
							} else {
								sb.append("-");
							}
							sb.append(num[2]);
							if (k == 0) {
								sb.append("+");
							} else {
								sb.append("-");
							}
							sb.append(num[3]);
							sb.append("=7");
							out.println(sb.toString());
							return;
						}
					}
				}
			}
		}
	}



	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    string S;
    cin >> S;

    int N = S.length();

    string S1 = S.substr(0, (N - 1) / 2);
    // cout << S1 << endl;
    string S2 = S.substr((N + 1) / 2);
    // cout << S2 << endl;

    for (int i = 1; i <= N; i++)
    {
        if (S[i - 1] != S[N - i])
        {
            cout << "No" << endl;
            return;
        }
    }

    int N2 = S1.length();
    for (int i = 1; i <= N2; i++)
    {
        if (S1[i - 1] != S1[N2 - i])
        {
            cout << "No" << endl;
            return;
        }
    }
    int N3 = S2.length();
    for (int i = 1; i <= N3; i++)
    {
        if (S2[i - 1] != S2[N3 - i])
        {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back 
#define For(i,a,b) for(int i=a;i<=b;i++)
#define ForR(i,a,b) for(int i=a;i>=b;i--)
#define Copy(a,b,s,t) For(i,s,t) a[i] = b[i];
#define maxn 100002
using namespace std;
int a[maxn],b[maxn],a2[maxn],b2[maxn];
bool findInArray(int *arr, int s, int t,int x){
	For(i,s,t){		
		if(arr[i]==x){
			return true;
		}
	}	
	return false;
}
vector<int> adj[maxn];
bool visit[maxn];
map<int, int> Map;
int RevMap[maxn];
void dfs(int u){
	for(int i=0;i<adj[u].size();i++){
		int v = adj[u][i];
		if(!visit[v]){
			visit[v] = true;
			dfs(v);
		}
	}
}
void  swap(int &x, int &y){
	int temp = x; x = y; y = temp;
}
main(){
	int N;
	cin >> N;
	int xorA = 0;
	For(i,1,N){
		scanf("%d",a+i);
		xorA ^= a[i];
	}
	For(i,1,N){
		scanf("%d",b+i);
	}	
		Copy(a2,a,1,N);
	Copy(b2,b,1,N);
	a[0] = xorA;
	sort(a,a+N+1);
	sort(b,b+N+1);
	For(i,1,N){
		if(i==1 || (i>1 && b[i]!=b[i-1])) {
			RevMap[i] = b[i];
			Map[b[i]] = i;	
		}		
	}

	int same = 0;	
	For(i,1,N){		
		if(b[i]==a[i-1]){
			same++;						
		}	else	{
			break;
		}
	}	
	ForR(i,N,1){
		if(b[i]==a[i]){
			same++;			
		}	else	{
			break;
		}
	}
	if(same < N){
		cout << "-1";
	}	else	{
		int j = N;
		int i = 1;
//		For(i,1,N){
//			cout << b2[i] << " ";
//		}
		while(i<=j){			
			if(a2[i]==b2[i]){				
				swap(a2[i],a2[j]);
				swap(b2[i],b2[j]);
				j--;
			}	else	{
				i++;
			}
		}
//		cout << j;
		N = j;
		int subtract = 0;
//		cout << xorA;
		if(findInArray(b2,1,N,xorA))		{			
			subtract = 1;
		}
		For(i,1,N){
//			cout << Map[b2[i]] << " " << Map[a2[i]];
			adj[Map[b2[i]]].pb(Map[a2[i]]);
			adj[Map[a2[i]]].pb(Map[b2[i]]);
		}
		int connection = 0;
		For(i,1,N){
			visit[i]=false;
		}
		For(i,1,N){
			if(visit[i]==false && adj[i].size()!=0)	{
				dfs(i);
				connection ++;
			}
		}
//		cout << connection;
		cout << N + connection - subtract;
	}
}

Measured memory_bytes: 15616
#include <stdio.h>
int main(){
  int l, r, d;
  scanf("%d%d%d",&l,&r,&d);
  int c=0;
  for(int i=l;i<=r;i++){
    if(i%d==0) c++;
  }
  printf("%d", c);
  return 0;
}

Measured memory_bytes: 2156
MOD = 10 ** 9 + 7


def prime_factorization(n):
    i = 2
    res = []
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            n /= i
            cnt += 1
        if cnt > 0:
            res.append(cnt)
        i += 1
    if n > 1:
        res.append(1)
    return res


def comb(a, b):
    b = min(b, a - b)
    if b < 0:
        return 0
    elif b == 0:
        return 1
    elif b == 1:
        return a
    else:
        return (((a % MOD) * pow(b, MOD - 2, MOD) % MOD) * comb(a - 1, b - 1)) % MOD


N, M = map(int, input().split())

ans = 1
for power in prime_factorization(M):
    ans *= comb(N - 1 + power, power)
    ans %= MOD

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

VI solve( VI as, VI bs )
{
	const int m = as.size();

	VVI dp( m + 1, VI( m * 100 * 10 + 1, 0 ) );
	dp[0][0] = 1;

	REP( i, 0, m )
	{
		REP( j, 0, dp[i].size() )
		{
			REP( k, 0, bs[i] + 1 )
			{
				if ( !dp[i][j] )
				{
					continue;
				}

				dp[ i + 1 ][ j + as[i] * k ] += dp[i][j];
			}
		}
	}

	return dp[m];
}

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

	while ( true )
	{
		int m;
		cin >> m;

		if ( !m )
		{
			break;
		}

		VI as( m ), bs( m );

		REP( i, 0, m )
		{
			cin >> as[i] >> bs[i];
		}

		VI res = solve( as, bs );

		int g;
		cin >> g;

		REP( i, 0, g )
		{
			int n;
			cin >> n;

			cout << res[n] << endl;
		}
	}

	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a.begin() + 1, a.begin() + 1 + n);
    long long ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>

int n, s, res;

void dfs(int prev, int sum, int deep);

int main(void)
{
	while (scanf("%d %d", &n, &s)){
		if (n == 0 && s == 0) break;
		
		res = 0;
		for (int i = 0; i < 10; i++){
			dfs(i, i, 1);
		}
		
		printf("%d\n", res);
	}
	
	return (0);
}

void dfs(int prev, int sum, int deep)
{
	if (sum == s && deep == n) {
		res++;
//		printf("%d %d\n", sum, deep);
		return;
	}
	if (s < sum || n < deep) return;
	
	for (int i = prev + 1; i < 10; i++){
		dfs(i, sum + i, deep + 1);
	}
	
	return;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; ++i )
int main(){
  int n,dp[8][1001],g,m;
  while(cin >> n , n){
    int a[n],b[n];
    fill_n(dp[0],8008,0);
    dp[0][0] = 1;
    rep(i,n) cin >> a[i] >> b[i];
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < 1001 ; j++ ){
        for(int k = 0 ; k <= b[i] ; k++){
          if( j + a[i] * k > 1000) break;
          dp[i+1][j + a[i] * k] += dp[i][j];
        }
      }
    }
    cin >> g;
    while(g--){
      cin >> m;
      cout << dp[n][m] << endl;
    }
  }
}

Measured memory_bytes: 1192
//
//  agc011pa.cpp
//  
//
//  Created by 楊承昊 on 2017/3/12.
//
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int N;
    while(cin>>N)
    {
        int C,K,sum=0;
        cin>>C>>K;
        int pass[100000+5]={0};
        for(int i=0;i<N;i++)
            cin>>pass[i];
        sort(pass,pass+N);
        for(int i=0;i<N;i++)
        {
            sum++;
            int tmp=pass[i],ps=1;
            while(tmp+K>=pass[++i]&&ps<C&&i<N)
            {
                ps++;
            }
            i--;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
;; C - Low Elements

(defun solve (ps)
  "all(ps[i] <= ps[j] for j in range(i))が真であるiの個数.
   言い換えると, ps[i] <= min(ps[j] for j in range(i))であるiの個数."
  (let ((mins (loop for m = (first ps) then (min m p)
                    for p in ps collect (min m p))))
    (count t (mapcar #'(lambda (p m) (<= p m)) ps mins))))

(let* ((n (read))
       (ps (loop repeat n collect (read))))
  (princ (solve ps)))


Measured memory_bytes: 61800
<?php
class Que{
  public $data=[];
  public $size=100000;
  public $head=0;
  public $tail=0;
  function init(){$this->head=$this->tail=0;}
  function isEmpty(){return $this->head==$this->tail;}
  function isFull(){return $this->head==($this->tail+1)%$this->size;}
  function push($x){
    if($this->isFull()) return false;
    $t=$this->tail;
    if(++$this->tail==$this->size) $this->tail=0;
    $this->data[$t]=$x;
  }
  function shift(){
    if($this->isEmpty()) return false;
    $h=$this->head;
    if(++$this->head==$this->size) $this->head=0;
    return $this->data[$h];
  }
}
$que=new Que();
list($N,$Q)=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$N;$i++) $que->push(explode(' ',trim(fgets(STDIN))));
$TIME=0;
while(!$que->isEmpty()){
  $task=$que->shift();
  if($task[1]<=$Q){
    echo $task[0],' ',$TIME+$task[1],PHP_EOL;
    $TIME+=$task[1];
  }
  else{
    $task[1]-=$Q;
    $que->push($task);
    $TIME+=$Q;
  }
}

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

int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> B(N,K);
  vector<bool> ans(N,true);
  for(int i=0; i<Q; i++){
    int A;
    cin>>A;
    B.at(A-1)++;
  }
  for(int i=0; i<N; i++){
    B.at(i)-=Q;
    if(B.at(i)<=0){
      ans.at(i)=false;
    }
  }
  for(int i=0; i<N; i++){
    if(ans.at(i)){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}
     

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

int p(int k){
	int ans = 1;
	for(int i = 0;i < k;i++)ans *= 10;
	return ans;
}

int main(){
	string str, x, y = "", z = "";
	int xn, yn = 0, zn = 0, f = 0;
	cin >> str;
	for(int i = 0;i < str.size();i++){
		if(str[i] == '.'){
			x = str.substr(0, i);
			xn = x.size();
		}
		if((i == str.size()-1 && !f) || (i+1 < str.size() && str[i+1] == '(')){
			y = str.substr(xn+1, i-xn);
			yn = y.size();
			f = 1;
		}
		if(str[i] == ')'){
			z = str.substr(xn+yn+2, i-xn-yn-2);
			zn = z.size();
		}
	}
	int a = p(zn+yn)-p(yn);
	int b = atoi(x.c_str())*p(yn+zn)+atoi(y.c_str())*p(zn)+atoi(z.c_str());
	b = b-b/p(zn);
	if(zn == 0){
		a = p(yn);
		b = atoi(x.c_str())*p(yn)+atoi(y.c_str());
	}
	int g = __gcd(a, b);
	a = a/g;b = b/g;
	/*printf("%d %d\n", a, b);
	printf("%s %s %s", x.c_str(), y.c_str(), z.c_str());
	printf("\n");*/
	printf("%d/%d\n", b, a);
	return 0;
}


Measured memory_bytes: 3260
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each do |e|
  h[e] += 1
end
sh = h.sort_by { |v| v.last }
if k >= sh.size
  puts 0
else
  puts sh[0..sh.size-k-1].reduce(0) { |sum, e| sum += e.last }
end


Measured memory_bytes: 41984
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	string n;
	cin >> n;

	lint sum = 0;
	for (int i = 0; i < n.size(); i++) {
		sum += n[i] - '0';
	}

	if (sum % 9 == 0) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}


Measured memory_bytes: 3780