akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long long key;
	int id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200002] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

void add_BIT(int BIT[], int n, int i, int k)
{
	while (i <= n) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{	
	int i, Q, q[200001];
	long long a[200001], b[200001];
	scanf("%d", &Q);
	for (i = 1; i <= Q; i++) {
		scanf("%d", &(q[i]));
		if (q[i] == 1) scanf("%lld %lld", &(a[i]), &(b[i]));
		else a[i] = 1 << 30;
	}
	
	int p[200001];
	data d[200002];
	for (i = 1; i <= Q; i++) {
		d[i].key = a[i];
		d[i].id = i;
	}
	merge_sort(&(d[1]), Q);
	for (i = 1; i <= Q; i++) p[d[i].id] = i;
	
	int k, l, r, m, BIT[200001] = {}, argmin = p[1];
	long long min = b[1];
	add_BIT(BIT, Q, p[1], 1);
	for (i = 2, k = 1; i <= Q; i++) {
		if (q[i] == 2) {
			printf("%d %lld\n", d[argmin].key, min);
			continue;
		}
		
		k++;
		add_BIT(BIT, Q, p[i], 1);
		if (p[i] == argmin) {
			min += b[i];
			continue;
		}
		
		l = argmin;
		r = argmin;
		if (p[i] < argmin) l = 0;
		else r = Q - 1;
		while (l < r) {
			m = (l + r) / 2;
			if (sum_BIT(BIT, m) <= (k - 1) / 2) l = m + 1;
			else r = m;
		}
		if (l >= argmin) min += llabs(d[l].key - a[i]) + b[i];
		else min += llabs(d[argmin].key - d[l].key) + llabs(d[l].key - a[i]) + b[i];
		argmin = l;
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 14696
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

ll N,C;
ll d[35][35];
ll c[505][505];
ll t[3][30];
int main(){FIN
    cin>>N>>C;
    ll ans = inf;
    REP(i,C) REP(j,C) cin>>d[i][j];
    REP(i,N) REP(j,N) {
        cin>>c[i][j];
        t[(i+j)%3][c[i][j]-1]++;
    }
    REP(i,C){
        REP(j,C){
            if (i!=j) REP(k,C){
                if(i!=k && j!=k){
                    ll tt=0;
                    REP(l,C) tt += d[l][i] * t[0][l];
                    REP(l,C) tt += d[l][j] * t[1][l];
                    REP(l,C) tt += d[l][k] * t[2][l];
                    ans = min(ans, tt);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	string S[3];
	for (auto i = 0; i < 3; ++i)
	{
		cin >> S[i];
	}

	auto current = 0;
	int index[3] = { 0, 0, 0 };
	for (auto i = 0; i < 300; ++i)
	{
		if (index[current] >= S[current].length())
		{
			break;
		}
		auto next = (int)(S[current][index[current]] - 'a');
		++index[current];
		current = next;
	}

	string result[] = { "A", "B", "C" };
	cout << result[current] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    int n;
    cin >> n;
    int number = n;
    int sum    = 0;
    while (n > 0) {
        int digit = n % 10;
        sum += digit;
        n /= 10;
    }

    if (number % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 760
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

koma_dist = []

for i in range(m - 1):
    koma_dist.append(x[i + 1] - x[i])

if n<m:
    print(sum(sorted(koma_dist)[:m-n]))
else:
    print(0)


Measured memory_bytes: 13968
sd = input()
t = input()

n = len(sd)
m = len(t)
#s = []

for i in range(n - m, -1, -1):
    t_kamo = sd[i : i + m]
    for j in range(m + 1):
        if j == m:
            print((sd[: i] + t + sd[i + len(t):]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != t[j]:
            break
print('UNRESTORABLE')

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long S = -200L;
        long L = 200L;
        long a = 0L;
        long b = 0L;

        for(long i = S;i <= L;i++){
            for(long j = S;j <= L;j++){
                long A = i*i*i*i*i;
                long B = j*j*j*j*j;
                if(x == A-B){
                    a = i;
                    b = j;
                    break;
                }
            }
        }

        System.out.println(a+" "+b);
    }
}

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

#define mod 1000000007LL
#define maxn 1000005
#define INF 1000000000
#define pb push_back
#define mp make_pair

using namespace std ;

template <class T>  inline void add(T &x,T y){ x = ((x+y)%mod) ; }

int main()
{
    int i , j , k , l , m , n;

    int mn = 100000000 ;

    scanf("%d",&n) ;

    for(i=1 ; i<n ; i++)
    {
        k = i ; l = n-i ;

        int sum = 0 ;

        while(k!=0)
        {
            sum += k%10 ;
            k /= 10 ;
        }
        while(l!=0)
        {
            sum += l%10 ;
            l /= 10 ;
        }
        mn = min(sum,mn) ;
    }

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

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>

int main() {
	FILE *fp = stdin;
	double s=0.0;
	int i,n,p;
	fscanf(fp, "%d", &n);
	for (i = 0; i < n; i++)
		fscanf(fp, "%d", &p),s += (double)p;
	s =s/(double)n;
	fprintf(stdout,"%d\n",(int)s);
	return 0;
}

Measured memory_bytes: 596
import scala.io.StdIn

object Main extends App {
  val counts = StdIn.readInt()
  val cards = StdIn.readLine().split(" ").map(_.toInt).sortWith(_ > _)

  val alicesScore = Iterator.from(0, 2).takeWhile(_ < cards.length).map(cards(_)).sum
  val bobsScore = Iterator.from(1, 2).takeWhile(_ < cards.length).map(cards(_)).sum

  val ans = alicesScore - bobsScore
  println(ans)
}


Measured memory_bytes: 25416
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> v;
int main() {
    cin >> N;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    cout << v[v.size()-1]-v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

int n, k;
int dp[100005];

int main() {
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  cin >> n >> k;
  int a[n];
  for (int i=0; i<n; i++) cin >> a[i];
  for (int i=a[0]; i<=k; i++) {
    for (int j=0; a[j]<=i && j<n; j++) {
      if (dp[i - a[j]] == 0) dp[i] = 1;
    }
  }
  if (dp[k] == 1) cout << "First" << endl;
  else cout << "Second" << endl;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int H,W;cin>>H>>W;
    rep(i,H)rep(j,W){
        string s;
        cin>>s;
        if(s=="snuke"){
            cout<<(char)(j+'A')<<i+1<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

int main() {
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    cout << H * W - (H / A) * (W / B) * A * B << endl;
    return 0;
}



Measured memory_bytes: 3076
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説通り実装したソースコード<br/>
 * http://baitop.hatenadiary.jp/entry/2018/06/26/224712 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int l = scanner.nextInt();
			UnionFindTree road = new UnionFindTree(n);
			IntStream.range(0, k).forEach(i -> road.unite(scanner.nextInt() - 1, scanner.nextInt() - 1));
			UnionFindTree railway = new UnionFindTree(n);
			IntStream.range(0, l).forEach(i -> railway.unite(scanner.nextInt() - 1, scanner.nextInt() - 1));
			Map<List<Integer>, Integer> map = new HashMap<>();
			@SuppressWarnings("unchecked")
			List<Integer>[] keys = new List[n];
			IntStream.range(0, n).forEach(i -> {
				keys[i] = Arrays.asList(road.root(i), railway.root(i));
				map.put(keys[i], map.getOrDefault(keys[i], 0) + 1);
			});
			System.out.println(
					IntStream.range(0, n).mapToObj(i -> map.get(keys[i]).toString()).collect(Collectors.joining(" ")));
		}
	}

	/**
	 * Union Find Treeの実装<br/>
	 * http://baitop.hatenadiary.jp/entry/2018/06/26/224712 を参考に作成
	 */
	private static class UnionFindTree {
		int[] parent;
		int[] rank;
		int[] sizes;

		UnionFindTree(int n) {
			parent = new int[n];
			rank = new int[n];
			sizes = new int[n];
			Arrays.fill(rank, 0);
			IntStream.range(0, n).forEach(i -> {
				parent[i] = i;
				sizes[i] = 1;
			});
		}

		int root(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				return parent[x] = root(parent[x]);
			}
		}

		void unite(int x, int y) {
			x = root(x);
			y = root(y);

			if (x == y) {
				return;
			} else if (rank[x] < rank[y]) {
				parent[x] = y;
				sizes[y] += sizes[x];
			} else {
				parent[y] = x;
				sizes[x] += sizes[y];
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}

		@SuppressWarnings("unused")
		boolean isSame(int x, int y) {
			return root(x) == root(y);
		}

		@SuppressWarnings("unused")
		int size(int x) {
			return sizes[parent[x]];
		}
	}
}


Measured memory_bytes: 137472
n = int(input())
aList = []
bList = []
for i in range(n):
  a, b = map(int, input().split())
  aList.append(a)
  bList.append(b)

aList.sort()
bList.sort()

if n % 2 == 0:
  middle = n // 2
  print(bList[middle] + bList[middle-1] - aList[middle] - aList[middle-1] + 1)
else:
  middle = (n-1) // 2
  print(bList[middle] - aList[middle] + 1)


Measured memory_bytes: 25456
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  unsigned int N, D;
  std::cin >> N >> D;

  std::vector<std::vector<int>> data(N);
  for (unsigned int i = 0; i < N; ++i) {
    std::vector<int> x_array;
    for (unsigned int j = 0; j < D; ++j) {
      int x;
      std::cin >> x;
      x_array.push_back(x);
    }
    data.at(i) = x_array;
  }

  unsigned int counter = 0;
  for (unsigned int i = 0; i < N - 1; ++i) {
    const std::vector<int>& y = data.at(i);
    for (unsigned int j = i + 1; j < N; ++j) {
      const std::vector<int>& z = data.at(j);
      unsigned int sum = 0.0;
      for (unsigned int k = 0; k < D; ++k) {
        sum += std::pow(y.at(k) - z.at(k), 2);
      }
      const double sqrt = std::sqrt(static_cast<double>(sum));
      const unsigned int sqrt_int = static_cast<unsigned int>(sqrt);
      const unsigned int sqrt_int_square = std::pow(sqrt_int, 2);
      if (sqrt_int_square == sum) {
        counter += 1;
      }
    }
  }

  std::cout << counter << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
#include<stack>
#include<math.h>
#include <utility>
#include <tuple>
 
#define rep(i,f,n) for(int (i)=(f);i<(n);i++)
#define LL long long int
 
 /* 
 greater<int>() 
 sortの第三因数に入れて降順 
sqrt(double) √を求める 
pair<int,int> x=make_pair(a,b)
x.first
tuple
get<番目>(変数名)
 */
using namespace std;
 
LL lcm(LL n, LL m)
{
	LL u;
	LL ansl = 0;
	for(u=m; u>=m; u++){
		if(u%n == 0){
			if(u%m == 0){
				ansl = u;
				break;
			}
		}
	}
	return ansl;
}
 
int main(void){

    int n;
    cin >>n;
    int m=n-1;
    vector<int>b(n);

    LL ans=0;
    rep(i,0,m){
        scanf("%d",&b[i]);
    }
    ans+=b[0]+b[m-1];
    rep(i,1,m){
        ans+=min(b[i],b[i-1]);
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void print(vector<vector<long long int>> &dp)
{
    for(long long int i=0;i<dp.size();i++)
    {
        for(long long int j=0;j<dp[0].size();j++)
        {
            cout<<dp[i][j]<<"   ";
        }
        cout<<endl;
    }
    
}
bool comp(pair<long long int,long long int> A,pair<long long int,long long int> B)
{
    return A.first<B.first;
}
int main() 
{
    string s,t;cin>>s>>t;
    vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1,0));
    for(int i=1;i<=s.size();i++)
    {
        for(int j=1;j<=t.size();j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    string sol;
    int i=s.size();int j=t.size();
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            sol=s[i-1]+sol;
            i--;j--;
        }
        else
        {
            if(dp[i][j]==dp[i][j-1])
            {
                j--;
            }
            else
            {
                i--;
            }
        }
    }
    cout<<sol;
}

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

using namespace std;

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

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

#endif


void Main() {
    ll N, K; cin >> N >> K;
    vector<ll> h(N);
    ll ans = 0;
    rep(i, N){
        cin >> h.at(i);
        if (h.at(i) >= K){ans++;}
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 1024
class BIT: #0-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth
#        self.element = [0]*(n+1)
    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def query(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
        # self.element[i] += x
    #def get(self,i): return element[i]        
    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x
    

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = map(int,read().split())
b = [0]+[k-i for i in a]


from itertools import accumulate
sa = sorted(set(accumulate(b)))

zaatu = {ai:i for i,ai in enumerate(sa)}

v = 0
bit = BIT(n+1)

ans = 0
for i,ai in enumerate(a):
    ai -= k
    bit.add(zaatu[-v],1)    
    v += ai
    idx = zaatu[-v]
    
    res = i+1
    if idx: res -= bit.get_sum(idx-1)
    ans += res




print(ans)







Measured memory_bytes: 62444
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int k,x;
    cin >> k >> x;

    for (int i = x - k + 1; i <= x + k - 1; ++i)
        cout << i << " \n"[i == x + k - 1];

}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))

hoge = {}

for i in range(m):
    p, y = list(map(int, input().split()))
    if hoge.get(p) == None:
        hoge[p] = [[y, i]]
    else:
        hoge[p].append([y, i])

ID = []

for ken, citylist in hoge.items():
    scitylist = sorted(citylist)
    for j, city in enumerate(scitylist):
       num_padded = '%06d' % (j+1)
       ken_padded = '%06d' % ken
       ID.append([str(ken_padded)+str(num_padded), city[1]])
    
ID_s = sorted(ID, key=lambda x:x[1])

for cityid in ID_s:
    print(cityid[0])

Measured memory_bytes: 58772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,k,l,sum=0;
    double av;
    double am;
    cin>>n>>m;
    int ar[n];

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        sum=sum+ar[i];
    }
//    cout<<sum<<endl;
    am=(1*1.0/(4*m*1.0));
    av=am*sum;
//    cout<<av<<endl;
//    cout<<am<<endl;
    int c=0;
    int flag=0;

    for(i=0;i<n;i++)
    {
        if(ar[i]>=av)
            c++;
        if(c==m)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MAX = 1e5 + 5;
int MOD = 1e9 + 7;
////////////////////////////////

int dp[2097153];

int32_t main(){
    jai_shree_ram
    int n;
    cin >> n;
    int a[n+1][n+1];
    rep(i,1,n,1) rep(j,1,n,1) cin >> a[i][j];
    dp[0] = 1;
    for(int mask = 0; mask <= ((1<<n)-1); mask++){
        int sb = __builtin_popcount(mask);
        rep(b,1,n,1){
            if(a[sb+1][b] and !( mask & ( 1<<(b-1) ) ) ) {
                int mk1 = mask|(1<<(b-1));
                dp[mk1] += dp[mask];
                dp[mk1] %= MOD;
            }
        }
    }

    cout << dp[(1<<n) - 1] << endl;
    return 0; 
}

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

using namespace std;

//State
//dp[a][b][c]: The expceted number of operations so to empty all plates when started with
// "a" number of 1 sushi plates, "b" number of 2 sushi plates, "c" number of 3 sushi plates

//Initialization
//dp[0][0][0] = 0

//Transitions
//dp[a][b][c] =  ((N-(a+b+c))/N)*dp[a][b][c] + (a/N)*dp[a-1][b][c] + (b/N)*dp[a+1][b-1][c] + (c/N)*dp[a][b+1][c-1] + 1
//dp[a][b][c] = N/(a+b+c) + (a/(a+b+c))*dp[a-1][b][c] + (b/(a+b+c))*dp[a+1][b-1][c] + (c/(a+b+c))*dp[a][b+1][c-1]

//Order of evaluation
//Outer Loop: c, Middle Loop: b, Inner Loop: a

//Answer: dp[n1][n2][n3]

//Time complexity: O(n1*n2*n3)

int main(){
    int N;
	cin >> N;
	int A[N+1];
	int ones = 0;
	int twos = 0;
	int threes = 0;
	
	for(int i=1; i<=N; i++){
		cin >> A[i];
		if(A[i] == 1) ones = ones+1;
		if(A[i] == 2) twos = twos+1;
		if(A[i] == 3) threes = threes+1;
	}
	
    //double dp[ones+twos+threes+1][twos+threes+1][threes+1] = {0};
    double dp[305][305][305] = {0};
    dp[0][0][0] = 0;
	for(int c=0; c<=threes; c++){
		for(int b=0; b<=twos+threes; b++){
			for(int a=0; a<= ones+twos+threes; a++){
				if(a!=0||b!=0||c!=0){
					dp[a][b][c] = (double) N/(a+b+c);
					if(a>0){
						dp[a][b][c] += (((double) a)/(a+b+c))*dp[a-1][b][c];
					}
					if(b>0){
						dp[a][b][c] += (((double) b)/(a+b+c))*dp[a+1][b-1][c];
					}
					if(c>0){
						dp[a][b][c] += (((double) c)/(a+b+c))*dp[a][b+1][c-1];
					}
				}
			}
		}
	}

	//cout << dp[ones][twos][threes] << endl;
	//printf("%0.10lf\n", dp[ones][twos][threes]);
	cout << fixed << setprecision(15) << dp[ones][twos][threes] << endl;

}

Measured memory_bytes: 225420
import copy

# 回転方法の全列挙
def turn(box):
    turnlist = []
    for j in range(4):
        for i in range(4):
            turnlist.append(box)
            box = [box[0], box[3], box[1], box[4], box[2], box[5]]
        box = [box[3], box[1], box[0], box[5], box[4], box[2]]
    box = [box[1], box[5], box[2], box[3], box[0], box[4]]
    for j in range(2):
        for i in range(4):
            turnlist.append(box)
            box = [box[0], box[3], box[1], box[4], box[2], box[5]]
        box = [box[0], box[3], box[1], box[4], box[2], box[5]]
        box = [box[5], box[4], box[2], box[3], box[1], box[0]]

    return turnlist

# 回転した先がどれだけ一致しているかどうかの確認
def solve():
    ans = float('inf')
    if n == 1:
        return 0

    for d1 in turn(color[0]):
        if n > 2:
            for d2 in turn(color[1]):
                if n > 3:
                    for d3 in turn(color[2]):
                        tmp = 0
                        for num in range(6):
                            tmp += fourcheck([d1[num], d2[num], d3[num], color[3][num]])
                        ans = min(ans, tmp)
                else:
                    tmp = 0
                    for num in range(6):
                        tmp += threecheck(d1[num], d2[num], color[2][num])
                    ans = min(ans, tmp)
        else:
            tmp = 0
            for num in range(6):
                if color[1][num] != d1[num]:
                    tmp += 1
            ans = min(tmp, ans)
    return ans

# 3つの時のチェック
def threecheck(a, b, c):
    if a == b and b == c:
        return 0
    if a == b or b == c or c == a:
        return 1
    return 2

# 4つの時のチェック
def fourcheck(dlist):
    tdict = {}
    for check in dlist:
        if check not in tdict:
            tdict[check] = 0
        tdict[check] += 1

    if max(tdict.values()) == 4:
        return 0
    if max(tdict.values()) == 3:
        return 1
    if max(tdict.values()) == 2:
        return 2
    return 3

while True:
    n = int(input())
    if n == 0:
        break

    color = [input().split() for i in range(n)]
    colordict = dict()

    tmp = 0
    for i in range(n):
        for j in range(6):
            if color[i][j] not in colordict.keys():
                colordict[color[i][j]] = tmp
                tmp += 1
            color[i][j] = colordict[color[i][j]]
    print(solve())



Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int x,y;
    cin>>x>>y;
    if(k>=n)
    {
        cout<<n*x<<endl;
    }
    else
    {
        int ans=k*x;
        n=n-k;
        ans+=n*y;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N, M;
  cin >> N >> M;
  vector <int> X(M);
  rep(i,M) cin >> X[i];
  sort(all(X));
  if (N >= M) cout << 0 << endl;
  else{
    vector <int> sa(M - 1);
    rep(i,M - 1) sa[i] = X[i + 1] - X[i];
    sort(sa.rbegin(), sa.rend());  //降順
    int sum = 0;
    rep(i,N - 1) sum += sa[i];
    int ans = X[M - 1] - X[0] - sum;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3896
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        boolean lowercase = !s.equals(s.toLowerCase());
        boolean uppercase = !s.equals(s.toUpperCase());
        if (!lowercase) {
            System.out.println("a");
        }
        if (!uppercase) {
            System.out.println("A");
        }
    }
}

Measured memory_bytes: 35652
#include <iostream>

using namespace std;

int main(void)
{
    int N, K, X, Y;

    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;

    if(N <= K){
        cout << N*X << endl;
    }
    else{
        cout << K*X+(N-K)*Y << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// 配列のAi番目にiを格納
		String[] array = new String[N];
		for (int i = 0; i < N; i++) {
			int Ai = sc.nextInt();
			array[Ai-1] = Integer.toString(i+1);
		}
		
		// 結果の出力
		System.out.println(String.join(" ", array));
		
		sc.close();
	}
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define mp make_pair
#define pb push_back

#define forn(i, n) for (int (i) = 0; (i) < n; ++(i))
#define ford(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i))

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pll;

vector<ll> t;
const ll inf = 1e18;
int n;

ll get(int l, int r)
{
    ll ans = inf;
    for (l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
        if (l & 1) {
            ans = min(ans, t[l]);
        }
        if (!(r & 1)) {
            ans = min(ans, t[r]);
        }
    }
    return ans;
}

int main()
{

    //ifstream cin("input.txt");

    //ios_base::sync_with_stdio(false);

    ll x;
    cin >> n >> x;

    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    t.resize(2 * n);
    for (int i = 0; i < n; ++i) {
        t[i + n] = a[i];
    }
    for (int i = n - 1; i; --i) {
        t[i] = min(t[i * 2], t[i * 2 + 1]);
    }

    ll ans = inf;
    for (int k = 0; k <= n; ++k) {
        ll curr = ll(k) * x;
        for (int i = 0; i < n; ++i) {
            int lf = i - k;
            if (lf >= 0) {
                curr += get(lf, i);
            } else {
                ll val = get(0, i);
                lf = n - (k - i);
                val = min(val, get(lf, n - 1));
                curr += val;
            }
        }
        ans = min(ans, curr);
    }
    cout << ans << "\n";

}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func()
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx++
		return cur
	}
	this.initWordIdx = func() {
		idx = 0
	}
	return &this
}

func (me *ReaderEx) ScanAndSplit() (isScanned bool) {
	isScanned = me.baseScanner.Scan()

	me.words = strings.Fields(me.baseScanner.Text())
	me.initWordIdx()
	return
}

func (me *ReaderEx) Scan() (ok bool) {
	ok = me.baseScanner.Scan()
	return
}
func (me *ReaderEx) getString() string {
	return me.baseScanner.Text()
}

func (me *ReaderEx) getInt() int {
	n, err := strconv.Atoi(me.baseScanner.Text())
	defer func() {
		if err != nil {
			panic(err)
		}
	}()

	return n
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, fa)
		}
	}
	if n > 1 {
		facts = append(facts, factType{prime: n, count: 1})
	}
	return facts
}

func solve(stdin io.Reader, stdout io.Writer) {
	r := NewScannerEx(stdin)
	r.Scan()
	s := r.getString()
	r.Scan()
	k := r.getInt()
	//a := 5000000000000000
	var v rune
	for _, v = range s {
		//w := pow(int(v)-'0', a, 0)
		var w int
		switch v {
		case '1':
			w = 1
		default:
			w = k
			break
		}

		k -= w
		if k <= 0 {
			break
		}
	}
	fmt.Fprintln(stdout, string(v))
}



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

int main() {
  long long n,a,b,c,d,k;
  cin>>n>>a>>b>>c>>d;
  k=b-a;
  bool ans=false;
  long long t=n-1;
  for(int i=0;i<n;i++){
    if(d*t-c*(n-t-1)<k)break;
    else if(c*t-d*(n-t-1)<=k){
      ans=true;
      break;
    }
    else t--;
  }
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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

int a[200005], b[200005];

int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d%d", &a[i], &b[i]);
    vector<int> A, B;
    for(int i=1;i<=n;i++){
        A.emplace_back(a[i]);
        B.emplace_back(b[i]);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if(n%2 == 0){
        int ans1 = (A[n/2-1]+A[n/2]), ans2 = (B[n/2-1]+B[n/2]);
        printf("%d\n", ans2-ans1+1);
    }
    else{
        printf("%d\n", B[n/2]-A[n/2]+1);
    }
}

Measured memory_bytes: 6668
#include <stdio.h>

int main(void){
int r,i,j,c;
int data[101][101]={};
int b[101]={};
int d[101]={};
long f=0;
scanf("%d %d",&r,&c);

for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
scanf("%d",&data[i][j]);
f+=data[i][j];
b[i]+=data[i][j];
d[j]+=data[i][j];
}

}


for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
printf("%d ",data[i][j]);
}
printf("%d",b[i]);
printf("\n");
}
for(j=1;j<=c;j++){
printf("%d ",d[j]);
}
printf("%d\n",f);






return 0;
}

Measured memory_bytes: 652
N = 101
prime = [True]*(N+1)
count = [0]*(N+1)
prime[0] = prime[1] = False

for i in range(N+1):
    if prime[i]:
        for j in range(2*i, N+1, i):
            prime[j] = False
a = int(input())
for i in range(1,a+1):
    cur = i
    for j in range(2,i+1):
        if prime[j]: 
            while cur%j==0:
                count[j]+=1
                cur//=j
            
s=r=0
for i in range(1,a+1):
    if count[i]>=4:
        s+=1
        r+=1
    elif count[i]>=2:r+=1
def num(m): # e の要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m-1, count)))

#if s>=2and r-2>=1:print(combinations_count(s,2)*(r-2))
#else:print(0)
print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064
from collections import deque

def isCLKWISE(ph):
    a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
    b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
    crs = a[0]*b[1] - a[1]*b[0]
    if crs < 0 : return False
    else : return True
     
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
 
n = int(input())
P = deque([])
for i in range(n):
    P.append([int(x) for x in input().split()])
     
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
    print(r[0],r[1])

Measured memory_bytes: 33920
#include <iostream>
#include <iomanip>
#include <queue>

using namespace std;

#define N 50

bool S[N+2][N+2] = {false};
int D[N+2][N+2] = {0};

class V;
queue<V*> Q;

class V {
  int h, w, d;

public:
  V(int h, int w, int d)
    : h(h), w(w), d(d)
  {
    //cout << h << ',' << w << ',' << d << endl;
    D[h][w] = d;
  }
  
  void next()
  {
    if (S[h-1][w] && D[h-1][w] == 0)
      Q.push(new V(h-1,w,d+1));
    if (S[h][w-1] && D[h][w-1] == 0)
      Q.push(new V(h,w-1,d+1));
    if (S[h+1][w] && D[h+1][w] == 0)
      Q.push(new V(h+1,w,d+1));
    if (S[h][w+1] && D[h][w+1] == 0)
      Q.push(new V(h,w+1,d+1));
  }

  bool is_goal(int H, int W)
  {
    return (h==H && w==W);
  }
};

void print_D(int H, int W)
{
  for (int h=1; h<=H; ++h) {
    for (int w=1; w<=W; ++w) {
      cout << setw(2) << D[h][w] << ' ';
    }
    cout << endl;
  }
}

int main()
{
  int H, W;
  cin >> H >> W;

  //print_D(H,W);
  
  int num_white = 0;
  
  for (int h=1; h<=H; ++h) {
    for (int w=1; w<=W; ++w) {
      char s;
      cin >> s;
      S[h][w] = (s=='.');
      if (s=='.')
	++num_white;
    }
  }
  
  Q.push(new V(1,1,1));
  V* v = NULL;
  bool ok = false;
  while(!Q.empty()) {
    v = Q.front();
    if (v->is_goal(H,W)) {
      ok = true;
      break;
    }
    v->next();
    Q.pop();
    delete v;
  }

  //print_D(H,W);
  
  int score = (ok) ? num_white - D[H][W] : -1;

  std::cout << score << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
vi b;

void solve() {

	cin >> N;
	b.resize(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> b[i];
	}

	vi  a;

	while (b.size() > 1) {
		int i;
		for (i = b.size() - 1; i > 0; i--) {
			if (i == b[i]) {
				b.erase(b.begin() + i);
				a.eb(i);
				break;
			}
		}
		if (i == 0) {
			cout << -1 << endl;
			return;
		}
	}

	for (int i = a.size() - 1; i >= 0; i--){
		cout << a[i] << endl;
	}

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

dp = [[0] * 4 for _ in range(2)]
dp[0][1] = 1
dp[1][0] = 1
dp[1][1] = int(N[0]) - 1

for n in N[1:] :
  n = int(n)
  ndp = [[0] * 4 for _ in range(2)]
  
  if n == 0 :
    ndp[0] = dp[0]
  else :
    ndp[0][1] = dp[0][0]
    ndp[0][2] = dp[0][1]
    ndp[0][3] = dp[0][2]

  ndp[1][0] = dp[1][0]
  ndp[1][1] = dp[1][1] + dp[1][0] * 9
  ndp[1][2] = dp[1][2] + dp[1][1] * 9
  ndp[1][3] = dp[1][3] + dp[1][2] * 9
    
  if n != 0 :
    ndp[1][0] += dp[0][0]
    ndp[1][1] += dp[0][0] * (n - 1) + dp[0][1]
    ndp[1][2] += dp[0][1] * (n - 1) + dp[0][2]
    ndp[1][3] += dp[0][2] * (n - 1) + dp[0][3]
  
  dp = ndp
  
print(dp[0][K] + dp[1][K])

Measured memory_bytes: 38384
import sys
s=sys.stdin
while 1:
 n=int(s.readline())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=s.readline().strip().split()
  d[k]=v
 a=''
 for _ in[0]*int(s.readline()):
  e=s.readline().strip()
  a+=d[e]if e in d else e
 print(a)


Measured memory_bytes: 6476
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_A
 */
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

vector<int>
countingsort(const vector<int> a, const int k)
{
    vector<int> C(k + 1);
    for (auto& it : a) { C[it]++; }

    for (int i = 0; i < k; i++) { C[i + 1] += C[i]; }

    vector<int> B(a.size());
    for (auto it = a.crbegin(); it != a.crend(); it++) {
        B[--C[*it]] = *it;
    }
    return B;
}

int
main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    vector<int> A(n);
    int k = 0;
    for (int i = 0; i < n; i++) {
        cin >> A[i]; cin.ignore();
        if (A[i] > k) { k = A[i]; }
    }

    printv(countingsort(A, k));

    return 0;
}

Measured memory_bytes: 45392
#include<iostream>
using namespace std;
 
int n;
int pass;
 
int main(){
  cin>>n;
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      for(int k=1; k<=n; k++){
        pass++;
      }
    }
  }
  cout<<pass;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    N=int(sys.stdin.readline())
    A=list(map(int,sys.stdin.readline().split()))
    B=[0]*N

    money=1000
    kabu=0
    for i in range(N-1):
        if A[i]<A[i+1]:
            kabu+=money//A[i]
            money%=A[i]

        elif A[i]>A[i+1]:
            money+=kabu*A[i]
            kabu=0

    money+=kabu*A[-1]
    print(money)
    
main()

Measured memory_bytes: 9120
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

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

    for i in 1..=1000 {
        let k = k * i;
        if a <= k && k <= b {
            echo!("OK");
            return;
        }
    }
    echo!("NG");
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;  //long longでゴリ押しします

vector<vector<ll>> alpha(26, vector<ll>());  //各alphabetの位置
string s, t;
bool able = true;
ll res = 0;

ll binary_search(ll n, ll l, ll r, ll val){  //valより大きいa
  if(l == r) return l;

  ll c = (r-l)/2 + l;
  if(alpha[n][c] <= val) return binary_search(n, c+1, r, val);
  else if(alpha[n][c] > val) return binary_search(n, l, c, val);

}

ll search_next(ll rda, ll t_pre){  //alpha[rda]内で最もpreと近い番号を返す
  ll len = alpha[rda].size(), num;
  if(len == 0) return -1;  //そもそも作れない
  if(alpha[rda][len-1] <= t_pre) return alpha[rda][0];  //preが大きい ->次の文字列最初出現文字
  num = binary_search(rda, 0, len-1, t_pre);

  return alpha[rda][num];
}
  

int main(){
  cin >> s >> t;

  ll Rda;  //aとの相対距離
  for(int i = 0; i < s.size(); i++){
    Rda = s[i] - 'a';
    alpha[Rda].push_back(i);
  }

  ll tRda, next;  //nextは次の文字の位置
  ll prev = -1;  //前回の文字位置 初期は-1
  for(int i = 0; i < t.size(); i++){
    tRda = t[i] - 'a';
    ll next = search_next(tRda, prev);
    if(next < 0){ able = false; break; }  //存在しない
    else {
      if(next > prev) res += next - prev;
      else res += (s.size() - prev) + next;
      prev = next;
    }
  }

  if(able) cout << res << endl;
  else cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 1724
package main

import (
	"fmt"
)

func main() {
	var m, n int
	fmt.Scanf("%d %d", &n, &m)

	A := make([]int, n)
	sum := 0.0
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		A[i] = a
		sum += float64(a)
	}

	var t float64 = sum / (4.0 * float64(m))

	cnt := 0
	for i := 0; i < n; i++ {
		a := A[i]
		if float64(a) >= t {
			cnt++
		}
	}
	var ans string
	if cnt >= m {
		ans = "Yes"
	} else {
		ans = "No"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){
	ll K;
	cin >> K;

	if(K%2 == 0 || K%5 == 0){
		cout << "-1" << endl;
		return 0;
	}

	ll amari = 7;
	ll ans = 1;
	vector<ll> rest;
	while(true){
		if(amari%K == 0){
			cout << ans << endl;
			return 0;
		}
		amari = amari % K;
		// for(ll i=0; i<(ll)rest.size(); i++){
		// 	if(rest[i] == amari){
		// 		cout << "-1" << endl;
		// 		return 0;
		// 	}
		// }
		// rest.push_back(amari);
		amari = amari * 10 + 7;
		// cout << amari << endl;
		ans++;
	}

	// ll ans = 1;
	// ll num = 7;
	// ll INF = 100100100100100100;
	// while(true){
	// 	if(num % K==0){
	// 		break;
	// 	}
	// 	ans++;
	// 	num = num*10 + 7;
	// 	cout << " num: " << num << endl;
	// 	if(num >= INF){
	// 		cout << "-1" << endl;
	// 		return 0;
	// 	}

	// }
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations

N = int(input())
c = ["".join(sorted(str(input()))) for x in range(N)]
cs = Counter(c)

ans=0
for i in cs.values():
    if i!=1:
        ans += (i * (i-1))/2

print(int(ans))

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

int main(void){
   int N,K;
   cin>>N>>K;
   vector<int> p(N);
   for(int i=0;i<N;i++){
      cin>>p[i];
   }
   sort(p.begin(),p.end());
   int ans=0;
   for(int i=0;i<K;i++){
      ans+=p[i];
   }
   cout<<ans<<endl;
   return 0;
}


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

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

int main(){
    int n;
    ll ans;
    cin >> n >> ans;
    for(int i = 1; i < n; i++){
        ll t;
        cin >> t;
        ll g = gcd(ans, t);
        ans = (ans / g) * (t / g) * g;

    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#D
N,M = map(int,input().split())
P = list(map(int,input().split()))
XY = [list(map(int,input().split())) for i in range(M)]

#UnionFind
class UF:
    def __init__(self,n):
        self.n = n
        self.root = [-1]*n #root[x]<0 ならxが根かつその値が木の要素数
        self.rank = [0]*n #木の深さ
    def __del__(self):
        pass
        
    def find(self,x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
            
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x]+=1
                
    def same(self,x,y):
        return self.find(x) == self.find(y) #bool
    
    def count(self,x):
        return -self.root[self.find(x)]
    
uf = UF(N)
for xy in XY:
    x,y = xy
    uf.unite(x-1,y-1)
    
ans = 0
for i,p in enumerate(P):
    if uf.same(p-1,i):
        ans+=1
        
print(ans)


Measured memory_bytes: 34588
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		int n = sc.nextInt();
		String[] s = new String[n];
		Map<String, Integer> map = new HashMap<String, Integer>();
		long result = 0;
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
			char ch[] = s[i].toCharArray();
			Arrays.sort(ch);
			String sch = new String(ch);
			if (map.containsKey(sch)) {
				map.replace(sch, map.get(sch) + 1);
				result += map.get(sch);
			} else {
				map.put(sch, 0);
			}
		}

		System.out.println(result);

		sc.close();
	}
}

Measured memory_bytes: 58056