akhauriyash/Code-Regression huggingface dataset:
use std::collections::BinaryHeap;
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: isize = iter.next().unwrap().parse().unwrap();

    let mut a: BinaryHeap<usize> = BinaryHeap::new();

    for _ in 0..n {
        a.push(iter.next().unwrap().parse().unwrap());
    }

    for _ in 0..m {
        let max = a.pop().unwrap();
        a.push(max / 2);
        // println!("{:?}", t);
    }

    let mut sum = 0;
    for a in &a {
        sum += *a;
    }

    println!("{}", sum);
}


Measured memory_bytes: 8444
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)

		for a % 2 == 0 {
			ans++
			a /= 2
		}
	}

	fmt.Println(ans)
}


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

int n, m, hsh[100001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	int pen = 0, ac = 0;
	for(int i = 0; i < m; i++){
		int p;
		string s;
		cin >> p >> s;
		if(s == "AC" && hsh[p] != -1) ac++, pen += hsh[p], hsh[p] = -1;
		else if(hsh[p] != -1) hsh[p]++; 
	}
	cout << ac << " " << pen << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int n;

void dfs(string s, char mx) {
    if (s.length() == n) {
        printf("%s\n", s.c_str());
    }
    else {
        for (char c = 'a'; c <= mx; c++) {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main()
{
    cin >> n;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int len = Convert.ToInt32( Console.ReadLine() );

            List<long> numbers = new List<long>(len);

            String[] inputs = Console.ReadLine().Split(' ');

            for (int i = 0; i < len; i++) numbers.Add(Convert.ToInt64(inputs[i]));

            numbers.Sort();

            long sum = 0;
            foreach (var num in numbers) sum += num;

            Console.WriteLine(numbers[0] + " " + numbers[len - 1] + " " + sum);
        }
    }
}

Measured memory_bytes: 20172
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

int n,m;
cin>>n>>m;
vi v(n);
i64 tot=0;
forn(i,n)
{
  cin>>v[i];
  tot+=v[i];
}
i64 req=(tot+4*m-1)/(4*m),cl=0;

forn(i,n)
{
  if(v[i]>=req)cl++;
}
if(cl>=m)cout<<"Yes";
else cout<<"No";


    return 0;
  }


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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	list<int> lst;
	string s;
	int n, num;
	list<int>::iterator it, en = lst.end();

	cin >> n;
	while (n--) {
		cin >> s;
		if (s == "insert") {
			cin >> num;
			lst.push_front(num);
		}
		else if (s == "delete") {
			cin >> num;
			for (it = lst.begin(); it != en; it++) {
				if (*it == num) {
					lst.erase(it);
					break;
				}
			}
		}
		else if (s == "deleteFirst") {
			lst.pop_front();
		}
		else {
			lst.pop_back();
		}
	}

	en--;
	for (it = lst.begin(); it != en; it++) {
		cout << *it << " ";
	}
	cout << *en << endl;

	return 0;
}

Measured memory_bytes: 32476
main = do
    n <- (read :: String -> Int) <$> getLine
    as <- map read . words <$> getLine
    print $ go as
    return ()

go :: [Int] -> Int
go []  = 0
go [x] = 0
go (x:y:other)
    | x == y    = 1 + go other
    | otherwise = 0 + go (y:other)

Measured memory_bytes: 892
#include<stdio.h>
int main(){
  int n,x,i,k,j,count;
  while(scanf("%d %d",&n,&x)){
    count=0;
    if(n==0 && x==0)break;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	for(k=j+1;k<=n;k++){
	  if(i+j+k==x)count++;
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>

int main() {
    uint32_t N, T;
    std::cin >> N >> T;
    std::vector<uint32_t> ts(N);
    for (auto& t: ts) {
        std::cin >> t;
    }

    //----//
    uint32_t total = 0;
    for (auto i = 0; i < ts.size(); i++) {
        auto t_i = ts[i];
        if (i + 1 >= ts.size()) {
            total += T;
        } else {
            auto t_i1 = ts[i + 1];
            total += std::min(T, t_i1 - t_i);
        }
    }

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

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

int main(){
	int n;
	string s;
	cin >> n >> s;
	if(n%2==1){
		cout << "No";
		return 0;
	}
	string fi=s.substr(0, n/2), se=s.substr(n/2);
	if(fi==se) cout << "Yes";
	else cout << "No";
	return 0;
}

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

typedef long long lint;

int M[1000100],n,S[1000100],m;
lint sumA=0,sumB=0;

int main(){
	cin>>n;
	for(int i=0;i<n;i++) S[i]=3;
	for(int i=0;i<n;i++){
		char ch;
		cin>>ch;
		if(ch=='D') S[i]=2;
		if(ch=='M') S[i]=1;
		if(ch=='C') S[i]=0;
	}
	for(int i=0;i<n;i++){
		if(S[i]==1) M[i]++;
		if(i!=0) M[i]+=M[i-1];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		int k;
		lint sumA=0,ans=0;
		cin>>k;
		queue <int> Q;
		for(int j=0;j<n;j++){
			if(S[j]==0){
				while(Q.front()+k<j+1&&Q.size()>0){
					sumA-=M[Q.front()];
					Q.pop();
				}
				ans+=Q.size()*M[j]-sumA;
			}
			if(S[j]==2){
				Q.push(j);
				sumA+=M[j];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 12216
a=[input() for i in range(2)]

a_num=a[1]
a_num=a_num.split()
a_list=[int(n) for n in a_num]

a_mul=1

if 0 in a_list:
	print(0)

else:
	for i in a_list:
		a_mul*=i

		if a_mul>10**18:
			a_mul=-1
			break

	print(a_mul)



Measured memory_bytes: 23432
m = 9
l = []
r = []
for i in range(5):
  a = int(input())
  if a % 10 != 0:
    m = 10 - a % 10
    b = a + m
    l.append(b)
    r.append(m)
  else:
    l.append(a)
    r.append(0)
r.sort()
print(sum(l) - r[-1])
      


Measured memory_bytes: 2940
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
      cin >> a[i];
      sum += a[i];
    }
    double avg = (double)sum / n;
    int ans = 0;
    rep(i, n) { ans += (a[i] <= avg); }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3164
#include <stdio.h>
     
    int main(void) {
    	int a, b, c;
    	scanf("%d %d %d", &a, &b, &c);
    	int max = a;
    	if(b > max) max = b;
    	if(c > max) max = c;
    	printf("%d\n", a+b+c-max);
    	return 0;
    }

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

int main() {
  long long N;
  cin >> N;

  long long ans = 0;
  bool flug = true;
  vector<char> vec;
  
  for(int i=0;flug==true;i++){
    long long db1 = pow(2,i);
    long long db2 = pow(2,i+1) ;
    //cout << abs(N)%db2 << " " << db1 << endl;
    if(abs(N)%db2==abs(db1)) {
      vec.push_back('1');
      if(i%2==0) N -= db1;
      else N += db1;
    }
    else vec.push_back('0');
    if(abs(N)<db2){
      flug = false;
    }
    if(ans<0) cout << i << endl;
  }

  for(long long i=vec.size()-1;i>=0;i--){
    cout << vec.at(i);
  }
  cout << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const double EPS = 1e-10;
typedef complex<double> P;

double D(P a, P b) {
  return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}
double toRad(double agl){return agl*M_PI/180.0;}
P rotate(P a, double r){return P(a.real()*cos(r)-a.imag()*sin(r),a.real()*sin(r)+a.imag()*cos(r));}

void Main() {
  int n;
  while(R n && n) {
    P a[n];
    rep(i,n) {
      double x,y;
      cin >> x >> y;
      a[i]=P(x,y);
    }
    int ans=1;
    rep(i,n) {
      REP(j,i+1,n) {
        if(D(a[i],a[j])>2) continue;
        int cnt=0;
        P q=P((a[i].real()+a[j].real())/2,(a[i].imag()+a[j].imag())/2);
        P p=a[i]-q;
        double r=sqrt(1.0-D(q,a[i])*D(q,a[i]));
        if(r) p*=r/D(q,a[i]);
        p=rotate(p,toRad(90));
        p+=q;
        rep(k,n) if(D(p,a[k])<=1+EPS) cnt++;
        ans=max(ans,cnt);
        cnt=0;
        p-=q;
        p=rotate(p,toRad(180));
        p+=q;
        rep(k,n) if(D(p,a[k])<=1+EPS) cnt++;
        ans=max(ans,cnt);
      }
    }
    pr(ans);
  }
}

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


Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

string s[100000];

int main()
{
	int n;
	ll M[5];
	ll ans=0;
	ll temp;
	int bit=0;
	int cnt=0;
	
	cin>>n;
	for(int i=0;i<5;i++)
	{
		M[i]=0;
	}
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		switch(s[i][0])
		{
			case 'M':
			M[0]++;
			break;
			case 'A':
			M[1]++;
			break;
			case 'R':
			M[2]++;
			break;
			case 'C':
			M[3]++;
			break;
			case 'H':
			M[4]++;
			break;
		}
	}
	for(bit=0;bit<33;bit++)
	{
		cnt=0;
		temp=1;
		for(int i=0;i<5;i++)
		{
			int t = bit&(int)pow(2,i);
			if(t>0)
			{
				temp*=M[i];
				cnt++;
			}
		}
		if(cnt==3)
		{
			ans+=temp;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6400
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	double w, h, x , y;
	int ans;
	
	cin >> w >> h >> x >> y;
	double res = h * w / 2;
	
	if((x * 2 == w) && (y * 2 == h)) ans = 1;
	else ans = 0;
	
	printf("%.10f%s%d\n", res, " ", ans);







	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<(n);i++)
//#define end(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
    
    int n,a,b;
    cin>>n>>a>>b;
    int dif=b-a+1;
    if(dif%2==1)cout<<"Alice"<<endl;
    else cout<<"Borys"<<endl;
    
    
	return 0;
}


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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;

    vector<vi> A(n, vi(m)), B(n, vi(m));

    for (int i = 0; i < n; ++i){
        string s; cin >> s;

        for (int j = 0; j < m; ++j){
            if (j == 0) A[i][j] = 1;
            else if (j + 1 == m) B[i][j] = 1;
            else if (0 < j && j + 1 < m){
                if (i & 1) A[i][j] = 1;
                else B[i][j] = 1;
            }

            if (s[j] == '#')
                A[i][j] = B[i][j] = 1;
        }
    }

    for (int k = 0; k < 2; ++k){
        for (int i = 0; i < n; ++i){
            for (int j = 0; j < m; ++j)
                cout << (A[i][j] ? "#" : ".");
            cout << endl;
        }
        cout << endl;
        A.swap(B);
    }

    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  string s;
  cin>>s;
  
  Ans(s[0]=='7'||s[1]=='7'||s[2]=='7');
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
#define M 1000000007
using namespace std;

ll n,m,k;
ll ans;

ll pow2(ll a, ll p)
{
    if (p==0) return 1;
    ll half = pow2(a,p/2);
    ll ans = (half*half)%M;
    if (p%2 == 1) ans = (ans*a)%M;
    return ans;
}

ll C(ll n, ll c)
{
    if (c==0) return 1;
    ll up = 1;
    for (ll i=1; i<=n; ++i)
        up=(up*i)%M;

    ll down = 1;
    for (ll i=1; i<=c; ++i)
        down = (down*i)%M;
    for (ll i=1; i<=n-c; ++i)
        down = (down*i)%M;

    ll down_rev = pow2(down, M-2)%M;
    return (up*down_rev)%M;
}

ll count_x(ll n, ll m, ll k)
{
    ll ans = 0;

    ll outer_loop = 0; 
    for (ll i=0; i<=m-1; ++i)
    {
        outer_loop += i*(m-i);
        outer_loop %= M;
    }
    outer_loop*=((n*n)%M);
    outer_loop%=M;

    ll inner_loop = C(n*m-2, k-2);
    //cout<< n*m-2<<' '<<k-2<<' '<<inner_loop<<endl;

    ans = (inner_loop * outer_loop)%M;
    return ans;
}

int main()
{
    cin >> n >> m >> k;
    ans = (count_x(n,m,k) + count_x(m,n,k))%M;
    cout<<ans<<endl;
        
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long l,r;
  	long long ans=2*1e+9;
	cin>>l>>r;
  //l=l%2019;
  //r=r%2019;
  if(r-l>=2019){cout<<"0"<<"\n";return 0;}
  for(long long i=l;i<r;i++){
  	for(long long j=l+1;j<=r;j++){
  	if(i<j&&ans>(i*j)%2019)ans=(i*j)%2019;
  	}
  }
  cout<<ans<<"\n";
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

class UnionFind {
public:
  UnionFind(int n) {
    r.resize(n, 0);
    s.resize(n, 1);
    p.resize(n);
    for (int i = 0; i < n; ++i) {
      p[i] = i;
    }
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) {
      return ;
    }
    if (r[a] > r[b]) {
      p[b] = a;
      s[a] = s[a] + s[b];
    } else {
      p[a] = b;
      s[b] = s[a] + s[b];
      if(r[a] == r[b]) r[b]++;
    }
    return ;
  }
  int find(int a) {
    return (a == p[a]) ? a : p[a] = find(p[a]);
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
  int size(int n) {
    assert(n < s.size());
    return s[find(n)];
  }
private:
  vector<int> r, p, s;
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, m;
  while (cin >> n >> m) {
    vector<pair<int, int>> v(m);
    cin >> v;
    reverse(v.begin(), v.end());

    UnionFind uf(n + 1);

    vector<lli> u;
    lli x = (n - 1) * n / 2;
    each (e, v) {
      u.push_back(x);
      if (uf.same(e.first, e.second)) {
        continue;
      }
      
      x += (uf.size(e.first) - 1LL) * uf.size(e.first) / 2;
      x += (uf.size(e.second) - 1LL) * uf.size(e.second) / 2;

      uf.unite(e.first, e.second);

      x -= (uf.size(e.first) - 1LL) * uf.size(e.first) / 2;
    }
    reverse(u.begin(), u.end());
    each (i, u) cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define rep(i ,a, n) for (long long int i=a;i<=n;i++)
#define pb  push_back
#define mp make_pair
#define fp first
#define sp second
#define be(v) v.begin(),v.end()
typedef long long ll;
typedef vector<ll> vi ;
typedef vector<pair<ll , ll > >  vpi ;
const int ma1=1e5+5;
string no="NO",yes="YES";
#define MOD 1000000007
int max_char=26;


int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;

    while(t--)
    {
         ll n,m;
         cin>>n>>m;
         ll a[n+1];
         for(int i=1;i<=n;i++)
            cin>>a[i];
         ll dp[100005]={0};
         for(int i=0;i<=m;i++)
         {
             bool flag=0;
             for(int j=1;j<=n;j++)
             {
                 if(i-a[j]>=0 && !dp[i-a[j]])
                    flag=1;
             }
             dp[i]=flag;
         }
         if(dp[m])
         {
             cout<<"First";
         }
         else cout<<"Second";
    }
    return 0;
}
















Measured memory_bytes: 4444
#!usr/bin/env python3
from collections import defaultdict
import math
import bisect
import random
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return list(input())
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
a,b = LI()
if b % a == 0:
    print(a+b)
else:
    print(b-a)
"""

#B
"""
n,m = LI()
lis = [0 for i in range(m)]
for i in range(n):
    k = LI()
    for j in k[1:]:
        lis[j-1] += 1
ans = 0
for i in lis:
    if i == n:ans += 1
print(ans)
"""

#C
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = II()
a = LI()
ans = a[0]
for i in range(1,n):
    ans = gcd(ans,a[i])
print(ans)
"""

#D
n,m = LI()
a = LI()
f = [0,2,5,5,4,5,6,3,7,6]
for i in range(m):
    a[i] = [a[i],f[a[i]]]
a.sort(key = lambda x:x[1])
dp = [[] for i in range(n+10)]
for i in a:
    dp[i[1]] = [i[0]]
for i in range(n+1):
    for j in a:
        if i-j[1] >= 0 and len(dp[i-j[1]]) > 0:
            if len(dp[i]) < len(dp[i-j[1]])+1:
                dp[i] = dp[i-j[1]]+[j[0]]
                dp[i].sort()
                dp[i] = dp[i][::-1]
            else:
                if len(dp[i]) == len(dp[i-j[1]])+1:
                    d = sorted(dp[i-j[1]]+[j[0]])
                    d = d[::-1]
                    k = [dp[i],d]
                    k.sort()
                    if k[1] == d:
                        dp[i] = d
ans = 0
k = 1
l = len(dp[n])
for i in range(l):
    ans += k*dp[n][l-i-1]
    k *= 10
print(ans)

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

int main(){
    int n;
    cin >> n;
    vector<string> word(n);
    bool ans = true;
    for (int i = 0;i < n;i++){
        cin >> word.at(i);
    }

    for (int i = 0;i < n - 1;i++){
        if (word.at(i).back() != word.at(i+1).front()){
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 0;i < n;i++){
        for (int j = i + 1;j < n;j++){
            if (word.at(i) == word.at(j)){
                cout << "No" << endl;
                return 0;
            }
        }
    }
        cout << "Yes" << endl;
        return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, raw_input().split())
x = map(int, raw_input().split())
y = [x[i+1] - x[i] for i in range(n-1)]

ans = 0
for i in y:
    if i*a < b:
        ans += i*a
    else:
        ans += b
print ans


Measured memory_bytes: 12604
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,len;
	char s[20];
	scanf("%s",s);
    len=strlen(s);
	for(i=len-1;i>=0;i--){
	    printf("%c",s[i]);
	}
	    printf("\n");
	return 0;
}



Measured memory_bytes: 2520
#pragma warning(disable:4996)

#include<iostream>
#include<algorithm>
//#include<unordered_map>
#include<fstream>
#include<iomanip>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#define INF 0x3f3f3f3f
#define inf 0x7FFFFFFF
#define MOD 2147493647
#define moD 1000000003
#define pii pair<int,int>
#define eps 1e-7
#define equals(a,b) (fabs(a-b)<eps)
#define bug puts("bug")
#define re  register
#define fi first
#define se second
const int maxn = 2e5 + 5;
const double Inf = 10000.0;
const double PI = acos(-1.0);
typedef  long long ll;
using namespace std;

ll a[maxn];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lld", a + i);
	sort(a, a + n, greater<ll>{});
	ll ans = 0;
	if (n & 1) {
		ans += a[0];
		for (int i = 1; i <= n / 2; i++) {
			ans += 2ll * a[i];
		}
		ans -= a[n / 2];
	}
	else {
		ans += a[0];
		for (int i = 1; i <= n / 2 - 1; i++) {
			if (i == n / 2) ans += a[i];
			else ans += 2ll * a[i];
		}
	}
	printf("%lld", ans);
}

Measured memory_bytes: 5260
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

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

    BigDecimal bigA = BigDecimal.valueOf(a);
    BigDecimal bigB = BigDecimal.valueOf(b);
    BigDecimal bigX = BigDecimal.valueOf(x);
    BigDecimal result = bigB.divide(bigX, 0, RoundingMode.FLOOR).subtract(bigA.divide(bigX, 0, RoundingMode.CEILING))
        .add(BigDecimal.ONE);
    System.out.println(result.longValue());
  }
}

Measured memory_bytes: 23380
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!int;
    const hs = readln.split.to!(int[]);
    N.iota.filter!(i => reduce!max(0, hs[0..i]) <= hs[i]).walkLength.writeln;
}



Measured memory_bytes: 256
#include <iostream>

int get_digit (long num) {
  int digit = 0;
  while (num != 0) {
    num /= 10;
    ++digit;
  }
  return digit;
}

int main() {
  long n;
  std::cin >> n;

  int ans = 11;
  for (long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ans = std::min(ans, std::max(get_digit(n / i), get_digit(i)));
    }
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
string N;long K,dp[111][2][4],i,j,k,l,r,c,M;
int main(){
	cin>>N>>K;
	M=N.size();
	dp[0][0][0]=1;
	for(i=0;i<N.size();i++){
		for(j=0;j<2;j++){
			r=j?9:N[i]-'0';
			for(k=0;k<=K;k++){
				for(l=0;l<=r;l++){
					c=k+!!l;
					if(c<=K)dp[i+1][j||l<r][c]+=dp[i][j][k];
				}
			}
		}
	}
	cout<<dp[M][0][K]+dp[M][1][K]<<endl;
}


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

public class Main {
	
	public static void main(String[] args) {
		String[] strs = read(1);
		
		int n = Integer.parseInt(strs[0]);
		
		int count = 0;
		
		for (int i = 1; i <= n; i += 2) {
			int tmp = 0;
			for (int j = 1; j <= i; j++) {
				if (i % j == 0) {
					tmp++;
				}
			}
			
			if (tmp == 8) {
				count++;
			}
		}
		
		System.out.println(count);
	}
	
	private static String[] read(int len) {
		List<String> strList = new ArrayList<>();
		
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			for (int i = 0; i < len; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
		
		return strList.toArray(new String[0]);
	}
}


Measured memory_bytes: 21972
S = input()
x = len(S)-1
ans = 0
for i in range(1 << x):
    insert = []
    for j in range(x):
        if i >> j & 1:
            insert.append(j)
    st = []
    for k, s in enumerate(S):
        st.append(s)
        if k in insert:
            st.append('+')
    ans += eval(''.join(st))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int main(){
	int H;
	int A;
	int cnt = 0;
	cin >> H >> A;
	for (int i = 0; H > 0; i++){
		H -= A;
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
ans=0
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
    ans+=(a+b)*min(x,y)
    if x>=y:
        ans+=a*(x-y)
    else:
        ans+=b*(y-x)
else:
    ans+=2*c*min(x,y)
    if x>=y:
        if a>=c*2:
            ans+=c*2*(x-y)
        else:
            ans+=a*(x-y)
    else:
        if b>=c*2:
            ans+=c*2*(y-x)
        else:
            ans+=b*(y-x)
print(ans)


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



int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int m=(n+1)/2;
  ll ans=a[0];
  for(int i=1; i<m; i++){
    ans += a[i] * 2;
  }
  if(n%2==1) ans -= a[m-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4008
#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    return *(int *)v1-*(int *)v2;
}
int main(void){
    int num,i,o,t,line[50],line1[25],sum=0,sign;
    for(;sign=0,scanf("%d",&num),num;){
        for(i=0,t=0;i<num*2;i++){
            scanf("%d",&line[i]);
            if(i%2)
                line1[t++]=line[i];
        }
        qsort(line1,t,4,c);
        for(sum=0,i=0;i<num;i++){
            for(o=1;o<num*2;o+=2){
                if(line1[i]==line[o]){
                    sum+=line[o-1];
                    line[o]=-1;
                    break;
                }
            }
            if(line1[i]<sum){
                sign=1;
                break;
            }
        }
        printf("%s\n",sign==1?"No":"Yes");
    }
    return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

unsigned int bits_count( unsigned int v )
{
  v = (v & 0x55555555) + (v >>  1 & 0x55555555);
  v = (v & 0x33333333) + (v >>  2 & 0x33333333);
  v = (v & 0x0f0f0f0f) + (v >>  4 & 0x0f0f0f0f);
  v = (v & 0x00ff00ff) + (v >>  8 & 0x00ff00ff);
  v = (v & 0x0000ffff) + (v >> 16 & 0x0000ffff);
  return v;
}

int main(){
    int X, Y, A, B, C, tmp;
    cin >> X >> Y >> A >> B >> C;

    ll ans=0;
    vector<ll> p(A), q(B), r(C);

    REP(i, A){
        cin >> tmp;
        p.push_back(tmp);
    }
    REP(i, B){
        cin >> tmp;
        q.push_back(tmp);
    }
    REP(i, C){
        cin >> tmp;
        r.push_back(tmp);
    }

    sort(p.begin(), p.end(), std::greater<ll>());
    sort(q.begin(), q.end(), std::greater<ll>());

    p.erase(p.begin()+X, p.end());
    q.erase(q.begin()+Y, q.end());

    p.reserve(p.size() + q.size());
    copy(q.begin(), q.end(), std::back_inserter(p));

    p.reserve(p.size() + r.size());
    copy(r.begin(), r.end(), std::back_inserter(p));

    sort(p.begin(), p.end(), std::greater<ll>());

    REP(i, X+Y) ans +=p[i];

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 7888
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 21;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s)
{
	int cnt = CountBit(s);
	if (x == sx && y == sy && cnt == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (cnt < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, cnt))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]));
	}
	if (cnt < MAX && !(cnt >= 18 && sum == 0)) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		printf("%d\n", DFS(sx, sy, 0));
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second

int main(){
    FAST
    int n, m, k; cin >> n >> m >> k;
    map<pair<int, int>, bool> has;
    pair<int, int> rows[n];
    pair<int, int> cols[m];
    for(int i = 0; i < n; i++){
        rows[i] = {0, i};
    }
    for(int j = 0; j < m; j++){
        cols[j] = {0, j};
    }
    for(int i = 0; i < k; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        has[{a, b}] = 1;
        rows[a].first++;
        cols[b].first++;
    }
    sort(rows, rows + n);
    sort(cols, cols + m);
    vector<int> vec1;
    int a = rows[n - 1].first;
    for(int i = n - 1; i >= 0; i--){
        if(rows[i].first == a){
            vec1.pb(rows[i].second);
        }
        else break;
    }
    vector<int> vec2;
    a = cols[m - 1].first;
    for(int i = m - 1; i >= 0; i--){
        if(cols[i].first == a){
            vec2.pb(cols[i].second);
        }
        else break;
    }

    int mx = rows[n - 1].first + cols[m - 1].first - 1;
    bool yes = 0;
   // cout << mx << endl;
    for(int i = 0; i < vec1.size(); i++){
        for(int j = 0; j < vec2.size(); j++){
            if(!has[{vec1[i], vec2[j]}]){
                mx++;
                i = vec1.size();
                break;
            }
        }
    }
    cout << mx;
    return 0;
}


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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 100100;

int n,a[N],dp[N];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    dp[n+1] = 2e9;

    for(int i=n-1;i>=1;i--)
        dp[i] = min( abs(a[i]-a[i+1]) + dp[i+1] , abs(a[i]-a[i+2]) + dp[i+2] );

    printf("%d\n",dp[1]);
}


Measured memory_bytes: 4544
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll n_nodes;
vvl tree;
ll mod_n = 1000000007;
// Speichern, wie viele Möglichkeiten es gibt, falls Knoten schwarz und wie viele für weiß
vl dp_white;
vl dp_black;

ll rec(ll curr_node, ll father, bool black){
    if(black && dp_black[curr_node] != -1) return dp_black[curr_node];
    if(!black && dp_white[curr_node] != -1) return dp_white[curr_node];
    ll res_white = 1;
    ll res_black = 1;
    for(auto neigh : tree[curr_node]){
        if(neigh == father) continue;
        if(!black){
            res_white *= (rec(neigh, curr_node, true) + rec(neigh, curr_node, false)) % mod_n;
            res_white = res_white % mod_n;
            TR(curr_node); TR(neigh); TR(res_white);
        }else {
            res_black *= rec(neigh, curr_node, false);
            res_black = res_black % mod_n;
            TR(curr_node); TR(neigh); TR(res_black);
        }
    }
    if(black) {
        dp_black[curr_node] = res_black;
        return res_black;
    }
    dp_white[curr_node] = res_white;
    return res_white;
}

int main() {

    cin >> n_nodes;
    tree.assign(n_nodes, vl());
    dp_black.assign(n_nodes, -1);
    dp_white.assign(n_nodes, -1);
    FOR(i, 0, n_nodes-1){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--; tmp2--;
        tree[tmp1].pb(tmp2);
        tree[tmp2].pb(tmp1);
    }
    cerr << rec(0, -1, true) << endl;
    cerr << rec(0, -1, false) << endl;
    cout << ((rec(0, -1, true) + rec(0, -1, false))% mod_n) << endl;

    return 0;
}



Measured memory_bytes: 19072
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int num[1005][105];
int main()
{
	int n,m;
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(!n) return 0;
		int val[105]={};
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				scanf("%d",&num[i][j]);
				val[j]+=num[i][j];
			}
		}
		bool f=false;
		for(int i=n;i>=0;i--)
		{
			for(int j=0;j<m;j++)
			{
				if(val[j]==i&&!f) { cout << j+1; f=true;}
				else if(val[j]==i){ cout << " " << j+1;}
			}
		}
		puts("");
	}
}

Measured memory_bytes: 1616
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,p;
	long long ans=0;
	string s;
	cin>>n>>p>>s;
	if(p==2){
	    rep(i,n){
	        if((s[i]-'0')%2==0)ans+=(i+1);
	    }
	}
	else if(p==5){
	    rep(i,n){
	        if((s[i]-'0')%5==0)ans+=(i+1);
	    }
	}
	else{
	    vector<int> mod(p);
	    mod.at(0)++;
	    int rate=1,a=0;
	    for(int i=n-1;i>=0;i--){
	        a+=((s[i]-'0')*rate);
	        a%=p;
	        ans+=mod.at(a);
	        mod.at(a)++;
	        rate*=10;
	        rate%=p;
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int N;
int x[366],y[366],b[366],p[366];

signed main()
{
    cin >> N;

    rep(i,N)
    {
        cin >> x[i]>>y[i]>>b[i]>>p[i];
        int min=x[i]*b[i]+y[i]*p[i];

        if(b[i]>5&&p[i]>2)
        {
            if(min>((x[i]*b[i]+y[i]*p[i])*0.8))
            {
                min=(x[i]*b[i]+y[i]*p[i])*0.8;
            }
        }
        else if(b[i]>5)
        {
            if(min>((x[i]*b[i]+y[i]*2)*0.8))
            {
                min=(x[i]*b[i]+y[i]*2)*0.8;
            }
        }
        else if (p[i]>2)
        {
            if(min>((x[i]*5+y[i]*p[i])*0.8))
            {
                min=(x[i]*5+y[i]*p[i])*0.8;
            }
        }
        else 
        {
            if(min>((x[i]*5+y[i]*2)*0.8))
            {
                min=(x[i]*5+y[i]*2)*0.8;
            }
        }

        cout << min << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,l[200];
	cin>>n;
	for(int i=0;i<2*n;i++)
		cin>>l[i];
	sort(l,l+2*n);
	int ans=0;
	for(int i=0;i<n;i++)
		ans+=l[i*2];
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

int dp[1001][1001];

signed main() {
    int h, w;
    cin >> h >> w;

    int ix, iy;
    cin >> iy >> ix; --ix; --iy;

    int dx, dy;
    cin >> dy >> dx; --dx; --dy;

    vector<string> vm;

    rep(i, h) {
        string s;
        cin >> s;

        vm.push_back(s);
    }

    rep(i, w) {
        rep(j, h) {
            if(vm[j][i] == '.') {
                dp[i][j] = INT_MAX;
            } else {
                dp[i][j] = -1;
            }
        }
    }

    dp[dx][dy] = 0;

    vector<pair<int, int>> vd({{1,0}, {0,1}, {-1,0}, {0, -1}});

    queue<pair<int, int>> q;
    queue<pair<int, int>> q2;
    q.push(make_pair(dx, dy));

    while (!q.empty() || !q2.empty()) {
        auto pos = q.front(); q.pop();
        if (dp[pos.first][pos.second] == -1) continue;
        
    // dev(dp, w + 1, h + 1);

        int res = dp[pos.first][pos.second];
        for (auto p: vd) {
            int x = pos.first + p.first;
            int y = pos.second + p.second;

            if (x >= 0 && x < w && y >= 0 && y < h && dp[x][y] >= 0 && dp[x][y] != INT_MAX) chmin(res, dp[x][y]);
            if (x >= 0 && x < w && y >= 0 && y < h && (dp[x][y] == INT_MAX || dp[x][y] > dp[pos.first][pos.second])) { 
                q.push(make_pair(x, y));
                dp[x][y] = dp[pos.first][pos.second];
            }
        }

        chmin(dp[pos.first][pos.second], res);

        for (int i = max(0ll, pos.first - 2); i <= min(w - 1, pos.first + 2); ++i) {
            for (int j = max(0ll, pos.second - 2); j <= min(h - 1, pos.second + 2); ++j) {
                if (dp[i][j] > res + 1) {
                    q2.push(make_pair(i, j));
                    dp[i][j] = res + 1;
                }
            }
        }

        if(q.empty()) {
            q = q2;
            q2 = {};
        }
    }

    // dev(dp, w + 1, h + 1);

    if (dp[ix][iy] == INT_MAX) {
        cout << -1;
    } else {
        cout << dp[ix][iy];
    }

    return 0;
}


Measured memory_bytes: 12108
n = int(input())
if(n < 10):
  print(n)
elif(n < 100):
  print(9)
elif(n < 1000):
  print(9 + n - 99)
elif(n < 10000):
  print(909)
elif(n < 100000):
  print(909 + n- 9999)
else:
  print(90909)


Measured memory_bytes: 2940
#include<cstdio>
using namespace std;



int main()
{
    int N;
    scanf("%d",&N);
    int a[N];
    int a1=0,a2=0,a4=0;

    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            a4++;
        if(a[i]%4!=0&&a[i]%2==0)
            a2++;
        if(a[i]%2!=0)
            a1++;
    }
    if(a2==0){
        if(a4>0&&a1<=a4+1)
            printf("Yes");
        else
            printf("No");
    }
    else{
        if(a4>=a1)
            printf("Yes");
        else
            printf("No");
    }
    return 0;
}



Measured memory_bytes: 512