akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define INF (int)2e9
#define MAX 10000

int a[MAX][MAX];

int prim(int n)
{
	int u, minv;
	int sum = 0;
	int d[MAX], p[MAX], color[MAX];

	for (int i = 0; i < n; ++i) {
		d[i] = INF;
		p[i] = -1;
		color[i] = 0;
	}

	d[0] = 0;

	while (1) {
		minv = INF;
		u = -1;
		for (int i = 0; i < n; ++i) {
			if (color[i] != 2 && minv > d[i]) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) {
			break;
		}
		color[u] = 2;

		for (int i = 0; i < n; ++i) {
			if (color[i] != 2 && a[u][i] != INF) {
				if (d[i] > a[u][i]) {
					d[i] = a[u][i];
					p[i] = u;
					color[i] = 1;
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (p[i] != -1) {
			sum += a[i][p[i]];
		}
	}
	return sum;
}

int main() {
	int n;
	int i, j;
	int v;

	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		for (j = 0; j < n; ++j) {
			scanf("%d", &v);
			a[i][j] = (v == -1) ? INF : v;
		}
	}
	printf("%d\n", prim(n));

	return 0;
}


Measured memory_bytes: 2148
h, w = map(int, input().split())

a = [input() for i in range(h)]

row = [False]*h
col = [False]*w

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(a[i][j], end='')
        print()



Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
string ans="";
string abcd;
void dfs(int pos,int sum,string s){
    if(pos==4){
        if(sum==7&&ans==""){
            ans=s.substr(1);
            ans+="=7";
        }
        return;
    }
    dfs(pos+1,sum+(abcd[pos]-'0'),s+"+"+abcd[pos]);
    dfs(pos+1,sum-(abcd[pos]-'0'),s+"-"+abcd[pos]);
}
int main(void){
    cin>>abcd;
    dfs(0,0,"");
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define X first
#define Y second
#define sz(v) (int)v.size()

void solve();

main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ONPC
	freopen("in.txt", "r", stdin);
#endif
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

const int N = 2e5 + 5;
bool used[N];
int fenv[N], n;
string s;
map<char, vector<int>> sp;

void inc(int r, int add) {
	for ( ; r < N; r += r & -r) fenv[r] += add;
}

int get(int r) {
	int res = 0;
	for ( ; r; r -= r & -r) res += fenv[r];
	return res;
}

void solve() {
	cin >> s;
	n = sz(s);
	s = '#' + s;
	for (int i = 1; i <= n; ++i) {
		sp[s[i]].pb(i);
		inc(i, 1);
	}
	int cnt = 0;
	for (auto d : sp) {
		cnt += sz(d.Y) & 1;
	}
	if (cnt > (n & 1)) {
		cout << -1;
		return;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (used[i]) continue;
		int l = i, r = sp[s[i]].back();
		sp[s[i]].pop_back();
		if (l == r) ans += (get(n) - get(l)) / 2;
		else ans += get(n) - get(r);
		used[l] = used[r] = 1;
		inc(l, -1);
		inc(r, -1);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3276
#include <iostream>
#include <cstdio>

#define ll long long
#define Max 300005

using namespace std;

const ll mod=998244353;
ll n,a,b,now,ans,fact[Max],k;

inline ll pow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1)ans=ans*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ans;
}

inline ll C(ll m,ll n){
    return fact[n]*pow(fact[m],mod-2)%mod*pow(fact[n-m],mod-2)%mod;
}

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>a>>b>>k;
    fact[0]=1;
    for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%mod;
    for(int i=0;i<=n;i++){
        now=(k-a*i)/b;
        if((k-a*i)%b)continue;
        if(now>n||now<0)continue;
        ans=(ans+C(i,n)*C(now,n)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#import math
import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト
    n = int(input())
    b = list(map(int,input().split()))
    key=0
    for i in range(n):
        if b[i]<=i+1:
            True
        else:
            key=1
            break
    if key==1:
        print(-1)
    else:
        ans=[]
        while b!=[]:
            for i in range(len(b)):
                if b[len(b)-1-i]==len(b)-i:
                    ans.append(b.pop(len(b)-1-i))
                    break
        ans.reverse()
        for i in range(len(ans)):
            print(ans[i])

main()

Measured memory_bytes: 38768
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a[100][100]={},b[100]={},n,m,i,iii,ii,c[100]={};
    cin>>n>>m;
    for(i=0;i<n;i++){
        for(ii=0;ii<m;ii++){
            cin>>a[i][ii];
        }
    }
    for(i=0;i<m;i++){
        cin>>b[i];
    }
    for(i=0;i<n;i++){
            for(iii=0;iii<m;iii++){
                c[i]=c[i]+a[i][iii]*b[iii];
            }
        cout<<c[i]<<endl;
        
    }

return 0;}

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

int main()
{
    string s;
    cin >> s;
    int c0 = 0;
    int c1 = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] == '1') {
                c0++;
            } else {
                c1++;
            }
        } else if (i % 2 == 1) {
            if (s[i] == '0') {
                c0++;
            } else {
                c1++;
            }
        }
    }
    cout << min(c0, c1) << endl;

    return 0;
}

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

int main() {
int N;
cin >> N;
long long  ans = 1, devi = 1000000007;
for (int i = 1; i <= N; i++) {
ans = (ans * i)%devi;
}
cout << ans << endl;
return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int[] a = in.ni(n);
        int x = 0;
        for (int i = 0; i < n; i++) x ^= a[i];
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(x^a[i]).append(" ");
        }
        out.println(sb.toString());
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 55324
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
	int H, i, A[MAX+1]; //1-オリジンのため +1 する
	
	cin >> H;
	for ( i = 1; i <= H; i++ ) cin >> A[i];
	
	for ( i = 1; i <= H; i++ ) {
		cout << "node " << i << ": key = " << A[i] << ", ";
		if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
		if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
		if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
#include<unordered_map>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define DivHim() cout<<">>>>>>>>>>>>>>>"<<endl
#define DivHer() cout<<"<<<<<<<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!!!!!!"<<endl

template<typename T> bool GetMin(T &a,T b)
{
	return ((a<=b)?false:(a=b,true));
}

template<typename T> bool GetMax(T &a,T b)
{
	return ((a>=b)?false:(a=b,true));
}

/*
	 -<Unlimited Blade Works>-
 */

#define int long long

const int N=1e5+10;

int n,d[N],id[N],sz[N],fa[N],dp[N];
unordered_map<int,int> re;

bool Cmp(int x,int y)
{
	return d[x]>d[y];
}

signed main()
{
	scanf("%lld",&n);
	if(n==2)
	{
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",d+i);
		re[d[i]]=i;
	}
	for(int i=1;i<=n;++i)
	{
		id[i]=i;
		sz[i]=1;
	}
	sort(id+1,id+n+1,Cmp);
	for(int i=1,u,v,x;i<n;++i)
	{
		re[d[u=id[i]]]=0;
		if((x=sz[u]+sz[u]-n)>=0||!(v=re[d[u]+x]))
		{
			puts("-1");
			return 0;
		}
		sz[fa[u]=v]+=sz[u];
		dp[fa[u]]+=dp[u]+sz[u];
	}
	if(dp[id[n]]!=d[id[n]])
	{
		puts("-1");
		return 0;
	}
	for(int i=1;i<=n;++i)
		if(fa[i])
			printf("%lld %lld\n",fa[i],i);
	return 0;
}

Measured memory_bytes: 9508
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

struct Factorizer {
   vector<bool> isprime;
   Factorizer(int n) {
      n++;
      isprime.resize(n, true);
      isprime[0] = isprime[1] = false;
      for (int i = 2; i < n; i++) if (isprime[i]) {
         for (int j = 2; i*j < n; j++) {
            isprime[i*j] = false;
         }
      }
   }
   map<int,int> operator()(int m) {
      map<int,int> res;
      for (int i = 2; i < isprime.size(); i++) if (isprime[i]) {
         while (m % i == 0) { res[i]++; m /= i; }
      }
      if (m != 1) res[m]++;
      return res;
   }
};

signed main()
{
   int n, P; cin >> n >> P;

   Factorizer fact(sqrt(P));
   map<int,int> cnt = fact(P);

   int ans = 1;
   for (auto it = cnt.begin(); it != cnt.end(); ++it) {
      for (int i = 0; i < it->second / n; i++) {
         ans *= it->first;
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,K;
    string S;
    cin >> N >> K >> S;
    vector<int> vec;
    if(S[0] != '1'){
        vec.push_back(0);
    }
    int cnt = 0;
    bool one = S[0] == '1';
    rep(i,0,N){
        if(one ^ S[i] == '1'){
            one = !one;
            vec.push_back(cnt);
            cnt = 1;
        }else{
            cnt++;
        }
    }
    vec.push_back(cnt);
    if(S.back() != '1')vec.push_back(0);
    /*
    rep(i,0,vec.size()){
        cout << (i+1) % 2 << " " << vec[i] << endl;
    }
    */
    if(K > vec.size() || K > (vec.size() - 1) / 2){
        cout << N << endl;
        return 0;
    }
    vector<int> accum(vec.size() + 1);
    int maxi = 0;
    rep(i,0,vec.size()){
        accum[i+1] = accum[i] + vec[i];
    }
    rep(i,0,vec.size()){
        if(i % 2)continue;
        int idx = i + K * 2 + 1;
        if(idx > vec.size())break;
        maxi = max(maxi, accum[idx] - accum[i]);
    }
    cout << maxi << endl;
}

Measured memory_bytes: 1272
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;





	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
System.out.println(a+b/2);		



	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Calc();
        }

        void Calc()
        {
            // read
            string[] tmpStr = Console.ReadLine().Split(' ');
            int a = int.Parse(tmpStr[0]);
            int b = int.Parse(tmpStr[1]);

            int n = b - a - 1;

            int x = getHeight(n) - a;

            Console.WriteLine(x);

        }

        int getHeight(int n)
        {
            if(n == 1)
            {
                return 1;
            }
            else
            {
                return getHeight(n - 1) + n;
            }
        }


    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll minv = min({a, b, c, d, e});
  cout << 5 + (n + minv - 1) / minv - 1 << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h> 
using namespace std;
 
int main() {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 0) {
		cout << "Even" << endl;
 
	}
	else {
		cout << "Odd" << endl;
	}
		
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define MAX 20000000
#define NIL INT_MIN

void maxHeepify(int, int);
void buildMaxHeep(int);
void swap(int, int);
void insert(int);
int extract(void);
void heepIncreasekey(int, int);
int H[MAX + 1];
int n;

int main()
{
    int i;
    int key;
    int cnt = 0;
    char order[10];

    while (1)
    {

        scanf("%s", order);
        if (order[0] == 'i')
        { //挿入
            scanf("%d", &key);
            insert(key);
            //cnt++;
            //printf("111111\n");
        }
        else if (order[1] == 'x')
        { //取出し
            //cnt--;
            // printf("222222222\n");
            printf("%d\n", extract());
        }

        if (order[2] == 'd')
            break; //終了
    }

    for (i = 1; i <= cnt; i++)
    {
        //printf("%d",H[i]);
    }
    //printf("\n");

    return 0;
}

void maxHeepify(int i, int n)
{
    int l, r;
    int largest;

    l = i * 2;
    r = i * 2 + 1;
    //左の子、自分、右の子で値が最大のノードを選ぶ

    if (l <= n && H[l] > H[i])
        largest = l;
    else
        largest = i;

    if (r <= n && H[r] > H[largest])
        largest = r;

    if (largest != i)
    {
        swap(i, largest);
        maxHeepify(largest, n);
    }
}
/*
void buildMaxHeep(int n){
  int i;

  for(i=n/2 ; i >= 1 ; i--){
    maxHeepify(i,n);
  }
  
}
*/
void swap(int a, int b)
{

    int tmp;
    tmp = H[a];
    H[a] = H[b];
    H[b] = tmp;
}

int extract(void)
{
    int maxv;
    maxv = H[1];
    H[1] = H[n];
    n--;
    maxHeepify(1, n);
    return maxv;
}

void insert(int key)
{
    n++;
    H[n] = NIL;
    heepIncreasekey(n, key);
}

void heepIncreasekey(int i, int key)
{

    if (key < H[i])
        return;
    H[i] = key;
    while (i > 1 && H[i / 2] < H[i])
    {
        swap(i, i / 2);
        i = i / 2;
    }
}



Measured memory_bytes: 5772
#include<iostream>
using namespace std;
long N,P,cnt[10101],T[2<<17],ans,mod,i;
string s;
int main(){
	cin>>N>>P>>s;
	if(P==2||P==5){
		for(i=0;i<N;i++){
			if((s[i]-'0')%P==0){
				ans+=i+1;
			}
		}
	}else{
		T[N-1]=1;
		for(i=N-1;i--;)T[i]=T[i+1]*10%P;
		cnt[0]=1;
		for(i=0;i<N;i++){
			mod=(mod+(s[i]-'0')*T[i])%P;
			ans+=cnt[mod]++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3=(-y2+y1)+x2;
  int y3=(x2-x1)+y2;
  cout<<x3<<' '<<y3<<' ';
  int x4=(-y3+y2)+x3;
  int y4=(x3-x2)+y3;
  cout<<x4<<' '<<y4<<' '<< endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    cout << (n > 999 ? "ABD" : "ABC") << endl;   
}

Measured memory_bytes: 256
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val list = List.fill(3)(sc.nextInt)
  val a, b = sc.nextInt

  val ans = if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) "Possible" else "Impossible"

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 25796
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
3
1 2 1
'''

test_data2 = '''\
2 3 0
4 5 6
7 8 9
-1 2 -5
'''

test_data3 = '''\
9
1 1 1 2 2 1 2 3 2
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        n=int(f.readline())
        b=list(map(int,f.readline().split()))
        # End Input code ---------------------------------------
else:
    for i in range(1):
        # Start Input code ---------------------------------------
        n=int(input())
        b=list(map(int,input().split()))
        # End Input code ---------------------------------------
#print('n,m,x,y=',n,m,x,y)
ans=[]
#print(b)
cnt=0
while cnt<100 and len(b)>0:
    m=len(b)
    cnt+=1
    flg=False
    for i in range(m):
        #print('i,i+1,m-1-i,b[m-1-i]',i,i+1,m-1-i,b[m-1-i],b)
        if b[m-1-i]==m-i:
            ans.append(b.pop(m-1-i))
            
            flg=True
            break
    if flg==False:
        break
if len(ans)==n:
    for i in range(n):
        print(ans[-i-1])
else:
    print(-1)


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import itertools
import numpy as np

h, w, k = (int(each) for each in input().split())
c = []
for _ in range(h):
    c.append(list(input()))

result = 0

n_c = np.array(c)

for y in itertools.product([0,1], repeat = h):
    for x in itertools.product([0,1], repeat = w):
        # print(y, x)
        n_c2 = np.array(c)
        for i, y2 in enumerate(y):
            if y2 == 1:
                n_c2[i] = 'R'
        for i, x2 in enumerate(x):
            if x2 == 1:
                n_c2[:,i] = 'R'
        # print(n_c2)
        m = np.count_nonzero(n_c2 == '#')
        if k == m:
            result += 1

print(result)


Measured memory_bytes: 27000
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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!{
        n: i64,
        x: i64,
    }

    fn burger(n: i64, x: i64) -> i64 {
        if x <= 0 {
            return 0;
        }

        if n <= 0 {
            return 1;
        }

        let mut length = 1;
        for _ in 0..(n+2) {
            length *= 2;
        }
        length -= 3;

        if x <= length / 2 {
            burger(n-1, x-1)
        } else {
            {
                let mut p_prev = 1;
                for _ in 0..(n) {
                    p_prev *= 2;
                }
                p_prev -= 1;

                burger(n-1, x-(length/2+1)) + 1 + p_prev
            }
        }
    }

    println!("{}", burger(n, x));
}


Measured memory_bytes: 4352
import numpy as np
import math

N,A,B = map(int, input().split())
h = np.zeros(N)

for i in range(N) :
    h[i] = int(input())

ans = 0
mn = 0
mx = np.ceil(h.max()/B)
now = mx//2
while (mx-mn) > 1 :
    tmp = h-B*now
    if now >= sum(np.ceil(tmp[tmp>0]/(A-B))) :
        mx = now
    else :
        mn = now

    now = (mx+mn)//2

print(int(mx))

Measured memory_bytes: 15688
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  ll N;
  cin >> N;

  vector<int> ans(0);

  if (N == 0) {
    cout << '0' << endl;
    return 0;
  }

  while (N != 0) {
    // cout << N << endl;
    if (abs(N) % 2 == 1) {
      // cout << N << " " << '1' << endl;
      N -= 1;
      ans.push_back(1);
    } else {
      // cout << N << " " << '0' << endl;
      ans.push_back(0);
    }
    N = N / -2;
  }

  reverse(ans.begin(), ans.end());
  for (auto x : ans) {
    cout << x;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>

using namespace std;

bool flag = false;

int main() {
	long long N;
	cin >> N;
	if (N == 0) {
		cout << 0 << endl;
		exit(0);
	}

	stack<int> s;
	long long base = 1;

	while (N != 0) {
		s.push((N % (base * 2) == 0 ? 0 : 1));
		N = (N % (base * 2) == 0 ? N : N - base);
		base *= -2;
	}

	cout << endl;

	while (!s.empty()) {
		cout << s.top();
		s.pop();
	}

	cout << endl;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<int>> v;
  for (int i = 0; i < n + n; ++i) {
    int x, y, t = (i >= n);
    scanf("%d %d", &x, &y);
    v.push_back({x, y, t});
  }
  sort(v.begin(), v.end());
  int ans = 0;
  set<int> ys;
  for (int i = 0; i < n + n; ++i) {
    if (v[i].back() == 0) {
      ys.insert(v[i][1]);
    } else {
      if (!ys.empty() && ys.lower_bound(v[i][1]) != ys.begin()) {
        ys.erase(prev(ys.lower_bound(v[i][1])));
        ++ans;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n, k, a[101];
    const lli mod = 1000000007;
    vector<vector<lli>> dp(101, vector<lli>(100001, 0));

    cin >> n >> k;
    for (int i=0; i<n; i++) cin >> a[i+1];

    dp[0][0] = 1;

    for (int i=1; i<=n; i++) {
        lli sum[100002] = { 0 };
        for (int j=0; j<=k; j++) {
            sum[j+1] = (sum[j] + dp[i-1][j]) % mod;
        }
        for (int j=0; j<=k; j++) {
            int lo = max(0, j-a[i]), hi = j+1;
            dp[i][j] = (mod + sum[hi] - sum[lo]) % mod;
        }
    }

    cout << dp[n][k] << endl;

    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[] = {-1,0,1,0,-1,-1,1,1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};

int main(){
  int n; cin>>n;
  int dp[10101010];
  rep(i,10101010){
    if(i==0||i==1) dp[i]=1;
    else dp[i]=dp[i-1]+dp[i-2];
  }
  cout<<dp[n]<<endl;
}



Measured memory_bytes: 42580
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int S = 7;
int dp[100010][S][S][S];

int main(void){
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    chmin(a, 2);
    chmin(b, 2);
    chmin(c, 2);
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    REP(i,n+1) REP(x,S) REP(y,S) REP(z,S) dp[i][x][y][z] = -1;
    dp[0][a][b][c] = 0;
    REP(i,n) REP(x,S) REP(y,S) REP(z,S){
        if (dp[i][x][y][z] == -1) continue;
        if (s[i] == "AB"){
            if (y > 0) dp[i + 1][x + 1][y - 1][z] = 0;
            if (x > 0) dp[i + 1][x - 1][y + 1][z] = 1;
        }else if (s[i] == "AC"){
            if (z > 0) dp[i + 1][x + 1][y][z - 1] = 0;
            if (x > 0) dp[i + 1][x - 1][y][z + 1] = 2;
        }else{
            if (z > 0) dp[i + 1][x][y + 1][z - 1] = 1;
            if (y > 0) dp[i + 1][x][y - 1][z + 1] = 2;
        }
    }
    REP(x,S) REP(y,S) REP(z,S){
        if (dp[n][x][y][z] == -1) continue;
        VI ans(n);
        FORR(i,n-1,0){
            ans[i] = dp[i + 1][x][y][z];
            if (s[i] == "AB"){
                if (ans[i] == 0){
                    x--;
                    y++;
                }else{
                    x++;
                    y--;
                }
            }else if (s[i] == "AC"){
                if (ans[i] == 0){
                    x--;
                    z++;
                }else{
                    x++;
                    z--;
                }
            }else{
                if (ans[i] == 1){
                    y--;
                    z++;
                }else{
                    y++;
                    z--;
                }
            }
        }
        cout << "Yes" << endl;
        REP(i,n){
            cout << "ABC"[ans[i]] << endl;
        }
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {

  stack<char> s;
  string ans = "";
  ll n; cin >> n;
  string st; cin >> st;
  for(ll i = 0; i < n; ++i){
    if(s.size() != 0 && s.top() == '(' && st[i] == ')'){
        s.pop();
    }else{
        s.push(st[i]);
    }
  }
  ll o = 0, z = 0;
  while(s.size()){
    if(s.top() == ')')z++;
    else o++;
    s.pop();
  }
  for(ll i = 0; i < z; ++i){
    ans.insert(0, "(");
  }
  ans += st;
  for(ll i = 0; i < o; ++i){
    ans += ")";
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3580
while (1):
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        exit()
    else:
        tile = str()
        for i in range(h):
            for ii in range(w):
                if i % 2 == 0 and ii % 2 == 0:
                    tile += '#'
                elif i % 2 == 0 and ii % 2 != 0:
                    tile += '.'
                elif i % 2 != 0 and ii % 2 == 0:
                    tile += '.'
                elif i % 2 != 0 and ii % 2 != 0:
                    tile += '#'
            tile += '\n'
        print(tile)



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 15;
int e[SIZE][SIZE];
int gg[1<<SIZE];
int dp[1<<SIZE][SIZE];
VI d[1<<SIZE];
template <class T>
void maa(T& x,T y){
    if(x<y)x=y;
}
template <class T>
void mii(T& x,T y){

    if(x>y)x=y;
}
int main(){
    MS1(dp);
    int sum=0;
    DRII(N,M);
    REP(i,1<<N){
        REP(j,N)
            if((i>>j)&1)d[i].PB(j);
    }
    REP(i,M){
        DRIII(x,y,v);
        sum+=v;
        x--;y--;
        e[x][y]=e[y][x]=v;
        int ee=(1<<x)|(1<<y);
        REP(j,1<<N){
            if((j&ee)==ee)gg[j]+=v;
        }
    }
    for(int i=1;i<(1<<N);i+=2){
        dp[i][0]=gg[i];
        if(i!=1){
            for(int j=(i-2)&i;;j=(j-2)&i){
                for(auto x: d[j]){
                    if(dp[j][x]==-1)continue;
                    for(auto y: d[i-j]){
                        if(!e[x][y])continue;
                        maa(dp[i][y],dp[j][x]+e[x][y]+gg[i-j]);
                    }
                }
                if(j==1)break;
            }
        }
    }
    printf("%d\n",sum-dp[(1<<N)-1][N-1]);
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main{
     public static void main(String [] args){
      Scanner input = new Scanner(System.in);
       
      int a = input.nextInt();
      int b = input.nextInt();
      int c = input.nextInt();
     
      if(a==5 && b==5 && c==7)
          System.out.println("YES");
      else if(a==7 && b==5 && c==5)
          System.out.println("YES");
      else if(a==5 && b==7 && c==5)
          System.out.println("YES");
      else
          System.out.println("NO");

     }
}


Measured memory_bytes: 26920
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

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

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


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


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

    string s;  
    cin >> s;
    string t = s;
    reverse(t.begin(),t.end());

    int n = s.size(),x = (n - 1) / 2,y = (n + 3) / 2;

    if (s != t){
        cout << "No" << endl;
        return 0;
    }

    string g = "",G;
    for (int i = 0;i < x;i++){
        g = g + s[i];
    }
    G = g;
    reverse(g.begin(),g.end());
    if (g != G){
        cout << "No" << endl;
        return 0;
    }

    string h = "",H;
    for (int i = y - 1;i < s.size();i++){
        h = h + s[i];
    }
    H = h;
    reverse(h.begin(),h.end());

    if (h == H) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	vector<string>v(H);
	rep(i, 0, H)cin >> v[i];
	vector<int>dx = { 1,1,0,-1,-1,-1,0,1 }, dy = { 0,1,1,1,0,-1,-1,-1 };
	auto inrange=[&](int i, int j) { return i >= 0 && i < H && j >= 0 && j < W; };
	rep(i, 0, H)rep(j, 0, W) {
		if (v[i][j] == '.') {
			int a(0);
			rep(k, 0, 8) {
				int x = i + dx[k], y = j + dy[k];
				if (!inrange(x, y))continue;
				if (v[x][y] == '#')a++;
			}
			v[i][j] = '0' + a;
		}
	}
	rep(i, 0, H)cout << v[i] << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		String s = n();
		char[] sc = s.toCharArray();
		int n = s.length();

		String s1 = "";
		String s2 = "";

		int now1 = 0;
		int now2 = 1;

		for (int i = 0; i < n; i++) {
			s1 += now1 % 2;
			s2 += now2 % 2;
			now1++;
			now2++;
		}

		char[] sc1 = s1.toCharArray();
		char[] sc2 = s2.toCharArray();

		int count1 = 0;
		int count2 = 0;

		for (int i = 0; i < n; i++) {
			if (sc[i] != sc1[i]) {
				count1++;
			}
			if (sc[i] != sc2[i]) {
				count2++;
			}
		}
		out(min(count1, count2));

	}

	/*
	 * 以下メソッド集
	 */

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 59332
#import <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    int A[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    for (int i = 0; i < N; i++) {
        printf("%d", A[i]);
        if (i < N - 1) {
            printf(" ");
        }
    }
    printf("\n");

    for (int i = 1; i < N; i++) {
        int v = A[i];
        int j = i - 1;

        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            A[j--] = v;
        }

        for (int i = 0; i < N; i++) {
            printf("%d", A[i]);
            if (i < N - 1) {
                printf(" ");
            }
        }

        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(b+c-a,0);
  return 0;
}


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

cnt = 0
for i in range(1, len(p)-1):
    if p[i-1] >= p[i] and p[i] > p[i+1]:
        cnt += 1
    elif p[i] > p[i-1] and p[i+1] >= p[i]:
        cnt += 1
        
print(cnt)

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main(){
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string moji;
  cin >> moji;
  vector<bool> dp(n, false);
  
  ll mx_nr = 0, mx_ns = 0, mx_np = 0;
  for (int i = 0; i < n; i++)  {
    if (moji.at(i) == 'r') mx_np++;
    else if (moji.at(i) == 's')  mx_nr++;
    else mx_ns++;
  }
  //cout << "mx_np: " << mx_np << ", mx_nr: " << mx_nr << ", mx_ns: " << mx_ns << endl;
  
  ll nr = mx_nr, ns = mx_ns, np = mx_np, tmp = 0;
  for (int i = 0; i < n - k; i++) {
    if (!dp.at(i)) {
      tmp = 0;
      if (moji.at(i) == moji.at(i + k)) {
        int j = i;
        while (moji.at(j) == moji.at(i)) {
          tmp++;
          dp.at(j) = true;
          j = j + k; 
          if (j > n - 1) break;
        }
        if (moji.at(i) == 'r') np = np - tmp / 2;
        else if (moji.at(i) == 's') nr = nr - tmp / 2;
        else ns = ns - tmp / 2;
      }
    } else continue;
  }
  
  ull ans;
  //cout << "np: " << np << ", nr: " << nr << ", ns: " << ns << endl;
  ans = np * p + nr * r + ns * s;
  cout << ans;
  return 0;
}


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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6+1;
const ld pi = acos(-1);
int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

template <class T1, class T2>
ostream &operator<<(ostream &out, map<T1, T2> &A) {
    for (auto x : A) cout << x.ff << " # " << x.ss << endl;
    return out;
}


int32_t main() {
    IOS
    int n;  cin>>n;
    puts(n >= 30 ? "Yes" : "No");
    return 0;
}

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

int main(){
vector<string>tt;
vector<int>t;
int a,b;
cin>>a>>b;
string c,d;
cin>>c>>d;
for(int e=0;e<a-1;e++){
	string f,g;
	cin>>f>>g;
	int i=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48);
	cin>>f>>g;
	int j=(f[0]-48)*600+(f[1]-48)*60+(f[3]-48)*10+(f[4]-48);
	if(j-i>=b){tt.push_back(g);t.push_back(j-i);}
}
cin>>c>>d;
cout<<tt.size()<<endl;
for(int x=0;x<t.size();x++){
	cout<<tt[x]<<" "<<t[x]<<endl;
}
}

Measured memory_bytes: 3180
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

const int nmax = 40, abmax = 10, inf = 1000000;
int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax*abmax + 1][nmax*abmax + 1];

int main() {

	int n, ma, mb;
	cin >> n >> ma >> mb;

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

	for (int i = 0; i <= n; i++) {
		for (int ca = 0; ca <= nmax*abmax; ++ca) {
			for (int cb = 0; cb <= nmax*abmax; ++cb) {
				dp[i][ca][cb] = inf;
			}
		}
	}

	dp[0][0][0] = 0;


	//iを使ってi+1の状態を計算する。
	for (int i = 0; i < n; i++) {
		for (int ca = 0; ca <= nmax*abmax; ++ca) {
			for (int cb = 0; cb <= nmax*abmax; ++cb) {
				//iの段階で到達できないならi+1を加えることはできない。
				if (dp[i][ca][cb] == inf)continue;

				//i+1を加えない。
				dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);

				//i+1を加える。当然Aの重さはa[i]増え、Bの重さはb[i]増える。
				//もともとdpテーブルに書いてあったコストと
				//[i][ca][cb]のコストにc[i]を足した
				//のうち小さい方をdpテーブルにメモする。
				dp[i + 1][ca+a[i]][cb+b[i]] = min(dp[i + 1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
			}
		}
	}
	
	//最小値の更新なので、最大値で初期化。
	int ans = inf;

	//全てのアイテムを使える状態でのdpテーブルをca,cbで順番にみていく。
	//重さの比が指定されたものになってる要素だけに着目し、
	//最小値が更新できるなら更新する。
	for (int ca = 1; ca <= nmax*abmax; ++ca) {
		for (int cb = 1; cb <= nmax*abmax; ++cb) {
			if (ca*mb == cb*ma)ans = min(ans, dp[n][ca][cb]);
		}
	}

	//一度も更新が行われなかったので、作成不能。
	//-1を出力するために代入しておく。
	if (ans == inf)ans = -1;

	cout << ans << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) { cin >> v[i]; }
  int count = 1;
  rep(i, n) {
    if (v[i] == count) {
      count++;
    }
  }
  if(count == 1){
    cout << -1 << endl;
    return 0;
  }
  
  cout << n - count + 1 << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template< class T > void prArray(T a,char ch = ' '){
  for(int i=0;i<(int)a.size();i++,cout<<ch){
    if(i) cout<<ch;
    cout<<a[i];
  }
  cout<<endl;
}



signed main(){
  int n,k;
  cin>>n>>k;
  map <int,int> m;
  for(int i=0,a;i<n;i++) cin>>a,m[a]++;
  
  typedef pair<int,int> P;
  vector<int> a;
  for(P p:m) a.push_back(p.second);
  sort(a.begin(),a.end());
  
  int ans = 0;
  for(int i=0;i<(int)a.size()-k;i++)ans += a[i];
  cout<<ans<<endl;

    
  return 0;
}


Measured memory_bytes: 14964