akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

int main() {
  vi results;
  int t;
  cin >> t;
  for (int dataset = 0 ; dataset < t ; ++dataset) {
    int gx, gy;
    cin >> gx >> gy;
    int p;
    cin >> p;
    vvi pattern(gy+1, vi(gx+1, 0));
    pattern[0][0] = 1;
    vv< vi > matatabi(gy+1, vvi(gx+1, vi(2, 0))); // 0:vertical, 1:horizontal
    for (int i = 0 ; i < p ; i++) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2) {
        matatabi[max(y1,y2)][x1][0] = 1;
      } else {
        matatabi[y1][max(x1,x2)][1] = 1;
      }
    }
    for (int ix = 1 ; ix <= gx ; ix++) {
      if (matatabi[0][ix][1] == 0) {
        pattern[0][ix] = 1;
        continue;
      } else {
        for (int ixx = ix ; ixx <= gx ; ixx++) {
          pattern[0][ixx] = -1;
        }
        break;
      }
    }
    for (int iy = 1 ; iy <= gy ; iy++) {
      if (matatabi[iy][0][0] == 0) {
        pattern[iy][0] = 1;
        continue;
      } else {
        for (int iyy = iy ; iyy <= gy ; iyy++) {
          pattern[iyy][0] = -1;
        }
        break;
      }
    }
    
//    for (int iy = 0 ; iy <= gy ; iy++) {
//      cout << pattern[0][iy];
//    }
//    cout << endl;
    
    for (int iy = 1 ; iy <= gy ; iy++) {
      for (int ix = 1 ; ix <= gx ; ix++) {
        int tmp = 0;
        if (matatabi[iy][ix][0] == 0 && pattern[iy-1][ix] >= 0) {
          tmp += pattern[iy-1][ix];
        }
        if (matatabi[iy][ix][1] == 0 && pattern[iy][ix-1] >= 0) {
          tmp += pattern[iy][ix-1];
        }
        if (tmp == 0) {
          tmp = -1;
        }
        pattern[iy][ix] = tmp;
      }
    }
    results.pb(pattern[gy][gx]);
  }

  for (auto result : results) {
    if (result >= 0) {
      printf("%d\n", result);
    } else {
      printf("Miserable Hokusai!\n");
    }
  }

  return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include<math.h>
#include <numeric> 
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<vector>
using namespace std;
#define ll long long
#define f(i,m,n) for(ll i=m;i<n;i++)
#define fo(j,n,m) for(ll j=n;i>=m;i--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main()
{
    ll max=0;
    ll k=0;
string s;
cin>>s;
f(i,0,s.size())
{
    if(s[i]=='R')
    {
        while(s[i]=='R')
        {
            k++;
            i++;
        }
        if(k>max)
        max=k;
        k=0;
    }
}
cout<<max;
  
    return 0;
}
    
    


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

std::vector<int> data[26];
std::vector<bool> charUsed;
int unusableData[26];

struct BIT_t {
	int arr[200001], n;

	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += arr[i];
			i -= i & -i;
		}
		return s;
	}

	void incAt(int i) {
		while (i <= n) {
			++arr[i];
			i += i & -i;
		}
	}
} BIT;

int main() {
	std::string str, ans;
	int k;
	std::cin >> str >> k;
	charUsed.resize(str.size());
	ans.reserve(str.size());
	BIT.n = str.size();

	for (auto&& e : data)
		e.reserve(200000);

	for (int i = 0; i < str.size(); ++i)
		data[str[i] - 'a'].push_back(i);

	for (auto&& e : data)
		std::sort(e.begin(), e.end());

	for (int i = 0; i < str.size(); ++i) {
		if (charUsed[i])
			continue;

		const int cur = str[i] - 'a';
		[&]() {
			for (int j = 0; j < cur; ++j) {
				if (unusableData[j] >= data[j].size() || k <= 0)
					continue;

				const auto it = std::lower_bound(data[j].begin() + unusableData[j], data[j].end(), i);

				if (it == data[j].end()) {
					unusableData[j] = data[j].size();
					continue;
				}

				const int next = *it, tmp = next - i - (BIT.sum(next + 1) - BIT.sum(i + 1));
				if (tmp <= k) {
					unusableData[j] = it - data[j].begin() + 1;

					k -= tmp;
					BIT.incAt(next + 1);

					--i;
					charUsed[next] = true;
					ans += 'a' + j;

					return;
				}
			}

			ans += 'a' + cur;
		}();
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 4644
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())


# リストに入れる
w = [int(i) for i in input().split()] 

p=0
q=0
for i in range(n):
    p += w[i]
r = abs(p-q)
for i in range(n):
    p -= w[i]
    q += w[i]
    r = min(r,abs(p-q))


print(r)

Measured memory_bytes: 21704
def solve(string):
    n, x, y = map(int, string.split())
    ans = [0] * (n - 1)
    for s in range(1, n + 1):
        d = [abs(i - s) for i in range(1, n + 1)]
        if d[x - 1] < d[y - 1]:
            p = y - 1
            d[p] = min(d[p], d[x - 1] + 1)
        else:
            p = x - 1
            d[p] = min(d[p], d[y - 1] + 1)
        for i in range(p + 1, n):
            d[i] = min(d[i], d[i - 1] + 1)
        for i in range(p - 1, -1, -1):
            d[i] = min(d[i], d[i + 1] + 1)
        for _d in d[s:]:
            ans[_d - 1] += 1
    return "\n".join(map(str, ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/

    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if( ( abs(a - b) <= d && abs(c - b) <= d ) || ( abs(a - c) <= d ) ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    cout << max(a * b, max(a + b, a - b) ) << endl;

    return 0; 
}


Measured memory_bytes: 3564
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long 
ll a[5],c,k;
int main()
{
	scanf("%lld%lld%lld%lld",&a[1],&a[2],&a[3],&k);
	c+=min(k,a[1]); k-=min(a[1],k);
	k-=min(a[2],k);
	c-=min(a[3],k); k-=min(a[3],k);
	printf("%lld",c);
}

Measured memory_bytes: 1736
#include<cstdio>
typedef long long ll;
int N;
char A[42][42];
ll f[42][42][42],g[42][42][42][42];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N*2;i++)scanf("%s",A[i]);
	for(int l=N*2;l--;){
		for(int m=l+1;m<N*2;m++)
			for(int r=m+1;r<=N*2;r++){
				if(m-l==1||r-m==1)f[l][m][r]=m-l==1&&r-m==1;
				else for(int i=l+1;i<m;i++)
					for(int j=i+1;j<=m;j++)f[l][m][r]+=f[l][i][j]*g[i][j-1][m][r];
			}
		for(int k=l;k<N*2;k++)
			for(int m=k+1;m<N*2;m++)
				for(int r=m+1;r<=N*2;r++)
					for(int i=m+1;i<r;i++)if(A[l][i]=='1')
						for(int j=m+1;j<=i;j++)g[l][k][m][r]+=f[j-1][i][r]*f[k][m][j];
	} 
	ll ans=0;
	for(int i=1;i<N*2;i++)if(A[0][i]=='1')ans+=f[0][i][N*2];
	printf("%lld\n",ans);
}

Measured memory_bytes: 24192
# AtCoder Beginner Contest 079 - C
s = input()
op = []
oplist = []
cnt = len(s) - 1

for i in range(2**cnt):
    op = ['+'] * cnt
    for j in range(cnt):
        if (i >> j) & 1:
            op[cnt - 1 - j] = '-'
    oplist.append(op)

for i in range(2**cnt):
    ans = int(s[0:1])
    for j in range(cnt):
        if oplist[i][j] == '+':
            ans += int(s[j+1:j+2])
        else:
            ans -= int(s[j+1:j+2])
    if ans == 7:
        print(s[0], end='')
        for k in range(cnt):
            print(oplist[i][k] + s[k+1:k+2], end='')
        print('=7')
        break

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

int main() {
    int n,m;
    cin>>n;
    string cardn[n];
    for (int i = 0; i < n; ++i) {
        cin>>cardn[i];
    }
    cin>>m;
    string cardm[m];
    for (int j = 0; j < m; ++j) {
        cin>>cardm[j];
    }
    int mon=0,mco=0;
    for (int k = 0; k < n; ++k) {
        string invest=cardn[k];
        int countn=0,countm=0;
        for (int i = 0; i < n; ++i) {
            if(cardn[i]==invest)countn++;
        }
        for (int j = 0; j < m; ++j) {
            if(cardm[j]==invest)countm++;
        }
        if(mon<countn-countm)mon=countn-countm;
        //cout<<countn<<" "<<countm<<" "<<k<<" "<<cardn[k]<<endl;
    }
    cout<<mon<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define ld long double

int main() {
    ll n;
    cin >> n;
    ld num;
    cin >> num;
    if(n==1) cout << num << endl;
    else {
        n -= 1;
        ld num2;
        while(n--) {
            cin >> num2;
            num = (num*num2)/(num+num2);
        }
        cout << num << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int x, y, size;
    int paper[10][10] = {0};
    int dx[] = { 0, 0,-1, 1,-1,-1, 1, 1, 0, 0,-2, 2};
	int dy[] = {-1, 1, 0, 0,-1, 1,-1, 1,-2, 2, 0, 0};
    int movex, movey;
    
    while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
        paper[x][y]++;
        for (int i = 0; i < (size * 4); i++){
            movex = dx[i] + x;
            movey = dy[i] + y;
            if ((0 <= movex) && (movex <= 10) && (0 <= movey) && (movey <= 10)){
                paper[movex][movey]++;
            }
        }
    }
    int ans_white = 0;
    int ans_max = 0;
    for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++){
            if (paper[i][j] == 0) ans_white++;
            if (ans_max < paper[i][j]) ans_max = paper[i][j];
        }
    }
    
    printf("%d\n%d\n", ans_white, ans_max);
    
    return (0);
}

Measured memory_bytes: 0
# coding: utf-8
a=int(input())
b=int(input())
la=len(str(a))
lb=len(str(b))

if la>lb:
    print('GREATER')
elif la<lb:
    print('LESS')
else:
    Flg=True
    for i in range(la):
        if int(str(a)[i])>int(str(b)[i]):
            print('GREATER')
            Flg=False
            break
        elif int(str(a)[i])<int(str(b)[i]):
            print('LESS')
            Flg=False
            break
    if Flg:
        print('EQUAL')

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	string S;
	cin >> S;
	int N = S.length();

	string ans = "Yes";
	rep(i, N) {
		if (S[i] != S[N - 1 - i]) {
			ans = "No";
			break;
		}
	}
	rep(i, N / 2) {
		if (S[i] != S[i + N / 2 + 1]) {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

bool check(LL num1, LL num2, LL x, LL y)
{
    bool a1 = (1LL << x) & num1;
    bool a2 = (1LL << y) & num2;
    return a1|a2;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc,p;
    LL h, w;
    cin >> h >> w >> k;
    string s[h];
    LL b_init = 0, w_init = 0;
    for (i = 0; i < h; i++)
    {
        cin >> s[i];
        for (j = 0; j < w; j++)
        {
            if (s[i][j] == '.')
            {
                w_init++;
            }
            else
            {
                b_init++;
            }
        }
    }
    LL ans=0;
    //set<pair<int, int>> grid;

    LL lim1 = POW(2, h);
    LL lim2 = POW(2, w);
    //debug(lim1);
   // debug(lim2);

    for (i = 0; i < lim1; i++)
    {
        for (j = 0; j < lim2; j++)
        {
            //grid.clear();
            LL cnt=0;
           // debug(i);
           // debug(j);
            for(t=0;t<h;t++)
            {
                for(p=0;p<w;p++)
                {
                    bool tr=false;
                    if(s[t][p]=='#')
                    {
                        
                        if(check(i,j,t,p))
                        {
                            tr=true;
                            cnt++;
                        }
                    }
                    /*if(tr)
                    {
                        cout<<"Y"<<" ";
                    }
                    else
                    {
                        cout<<"N"<<" ";
                    }*/
                    
                }
                //cout<<endl;
            }

            if(b_init-cnt==k)
            {
                ans++;
            }
            //part;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(k, n) FOR((k), 0, (n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD = 1000000007;

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

    ll n;
    cin >> n;
    VLL r(n);
    REP(i, n) { cin >> r[i]; }

    ll ans = -1000000000;
    ll minp = r[0];
    REP(i, n - 1) {
        if (r[i] <= minp) {
            minp = r[i];
            FOR(j, i + 1, n) {
                if (r[j] - r[i] > ans) {
                    ans = r[j] - r[i];
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

string a;
int b=0;

int main () {
  cin >> a;
  for(int i=0; i<a.length(); i++){
    if (a[i] == '+') {
      b=b+1;
    } else if (a[i] == '-') {
      b=b-1;
    }
  }
  cout << b << endl;
}

Measured memory_bytes: 3604
a, b, c, k = gets.chomp.split(' ').map{|s| s.to_i}

sum = 0

if a > 0
  if a >= k
    puts k
    return
  else
    sum += a
    k -= a
  end
end

if b > 0
  if b >= k
    puts sum
    return
  else
    k -= b
  end
end

puts sum - k

Measured memory_bytes: 14316
#include <iostream>
#include <math.h>
#include <vector>
typedef long long ll;
using namespace std;

ll gcd(ll n1, ll n2){
    return n2 == 0 ? n1 : gcd(n2, n1 % n2);
}

ll lcm(ll n1,ll n2){
    return n1 / gcd(n1, n2) * n2;
}

int main(){
    ll N, M;
    cin >> N >> M;
    ll sum = 1;
    bool ch = false;
    vector<ll> A(N);
    for (int i = 0; i < N;i++)
        cin >> A[i];

    int cnt = 0;
    for (int i = 0; i < N; i++){
        int tmp = 0;
        int a = A[i];
        A[i] /= 2;
        while(a % 2 == 0){
            a /= 2;
            tmp++;
        }
        if(i != 0 && tmp != cnt){
            ch = true;
        }
        cnt = tmp;
    }
    if(ch){
        cout << 0 << endl;
        return 0;
    }

    for (int i = 0; i < N;i++)
        sum = lcm(sum,A[i]);

    ll ans = M / sum;
    ans = ans / 2 + ans % 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main(void){
  string org;
  cin >> org;
  string target;
  int n=0;
  string refStr[4] = {"dream","dreamer","erase","eraser"};
  int refNumOfChar[4] = {5,7,5,6};
  for(n=0;n<org.length();n++){
    string fiveOfOrg = org.substr(n,5);
    string sixOfOrg = org.substr(n,6);
    string sevenOfOrg = org.substr(n,7);
    if( (refStr[0] == fiveOfOrg ) && (refStr[1]!=sevenOfOrg) ){
      target = target + refStr[0];
      n = n + 4;
    }
    if(refStr[1] == sevenOfOrg){//これが成り立つならば常にrefStr[0]==fiveOfOrg\\
が成り立っている                                                                
      if(org.substr(n,10)=="dreamerase"){
        target = target + refStr[0];
        n = n + 4;
      } else {
        target = target + refStr[1];
        n = n + 6;
      }
    }
    if( (refStr[2] == fiveOfOrg) && (refStr[3] != sixOfOrg) ){
      target = target + refStr[2];
      n = n + 4;
    }
    if(refStr[3] == sixOfOrg){
      if(org.substr(n,10)=="eraseraser"){
      target = target + refStr[2];
      n = n + 4;
      } else{
        target = target + refStr[3];
        n = n + 5;
      }
    }
  }
  if(org!=target){
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 764
def main():
    h, w = map(int, input().split())
    str_list = []
    for _ in range(h):
        str_list.append(list(input().split()))

    for i in range(h):
        for j in range(w):
            if str_list[i][0][j] != '.':
                break
        else:
            for _ in range(w):
                str_list[i][0] = '!' * w
                
    delete_index_list = []

    for i in range(w):
        for j in range(h):
            if str_list[j][0][i] != '.' and str_list[j][0][i] != '!':
                break
        else:
            delete_index_list.append(i)

    for i in range(h):
        for j in range(w):
            if j in delete_index_list:
                continue
            if str_list[i][0][j] != '!':
                print(str_list[i][0][j], end='')
            else:
                break
        else:
            print()


if __name__ == '__main__':
    main()

Measured memory_bytes: 43096
#include <cstdio>

#define NMAX 200000
#define INF 2000000000

int main()
{
    int maxEl = -INF;
    int otherMax = -INF;

    int maxOcc = 0;

    int n;
    int nbs[NMAX];

    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &nbs[i]);
        if (nbs[i] == maxEl)
        {
            maxOcc++;
        }
        
        if (nbs[i] > maxEl)
        {
            otherMax = maxEl;
            maxEl = nbs[i];
            maxOcc = 1;
        }
        else if (nbs[i] > otherMax)
        {
            otherMax = nbs[i];
        }
    }

    for (int i = 0; i < n; ++i)
    {
        if (nbs[i] == maxEl)
        {
            if (maxOcc == 1)
            {
                printf("%d\n", otherMax);
            }
            else
            {
                printf("%d\n", maxEl);
            }
        }
        else
        {
            printf("%d\n", maxEl);
        }
    }

    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << 1;
  } else if (a==b||b==c||c==a) {
    cout << 2;
  } else {
    cout << 3;
  }
  return 0;
}

Measured memory_bytes: 256
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import queue
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.dist = [INF] * N
		self.dist[s] = 0
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		self.prev = [None] * N
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.prev[i] = v
					self.Q.put(i)
					self.visit[i] = "Yes"

#処理内容
def main():
	N, M = getlist()
	G = Graph()
	for i in range(M):
		A, B = getlist()
		A -= 1; B -= 1
		G.add_edge(A, B)
		G.add_edge(B, A)

	BF = BFS(G, 0, N)
	print("Yes")
	prev = BF.prev
	for i in range(1, N):
		print(prev[i] + 1)

if __name__ == '__main__':
	main()

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

int main(){
	int n,m,l;
	long A[100][100],B[100][100],C[100][100]={};
	cin >> n >> m >> l;

	for(int i=0; i<n; ++i){
		for(int j=0; j<m; ++j){
			cin >> A[i][j];
		}
	}


	for(int i=0; i<m; ++i){
		for(int j=0; j<l; ++j){
			cin >> B[i][j];
		}
	}


	for(int i=0; i<n; ++i){  
		for(int j=0; j<l; ++j){
			for(int k=0; k<m; ++k){
				C[i][j] += A[i][k]*B[k][j];
			}
		}
	}


	for(int i=0;i<n;i++){
        for(int k=0;k<l-1;k++){
            cout << C[i][k] << " ";
        }
		cout << C[i][l-1] << "\n";
    }


	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++) {
    int p = s.at(i)-'A';
    p += n;
    p %= 26;
    char c = 'A'+p;
    cout << c;
  }
  cout << endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  set<int> mochi;
  int N;
  cin >> N;
  rep(i,N){
    int x;
    cin >> x;
    mochi.insert(x);
  }
  cout << mochi.size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rint register int
#define ivoid inline void
#define iint inline int
#define endll '\n'
#define ll long long
using namespace std;
const int N=1e6+5;
const int M=3e3+5;
const int inf=0x3f3f3f3f;
int n,k,top,bot;

iint rad()
{
	int x=0,f=1;char c;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
struct Water{int v;double t;}sta[N],now;
int sumv;
double sumq;

signed main()
{
//	freopen("1.in","r",stdin);
//	freopen("water.out","w",stdout);
	n=rad();k=rad();
	for(rint i=1;i<=n;i++){
		now.t=rad();now.v=rad();
		while(sumv+now.v>k){
			int out=min(sumv+now.v-k,sta[bot].v);
			sta[bot].v-=out;
			sumv-=out;
			sumq-=out*sta[bot].t;
			if(!sta[bot].v)bot++;
		}
		sta[++top]=now;
		sumv+=now.v,sumq+=1ll*now.v*now.t;
		while(bot<top&&sta[top].t<sta[top-1].t){
			sta[top-1].t=(sta[top].t*sta[top].v+sta[top-1].t*sta[top-1].v)/(sta[top].v+sta[top-1].v);
			sta[top-1].v=sta[top-1].v+sta[top].v;
			top--;
		}
		printf("%.8lf\n",(double)sumq/k);
	}
}

Measured memory_bytes: 17664
#include "bits/stdc++.h"

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b)-1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

ll pow(ll x, ll y) {
  ll ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}

ll inverse(ll x) { return pow(x, mod - 2); }

int main() {
  ll N;
  cin >> N;
  vi X(N), L(N);
  rep(i, 0, N) cin >> X[i] >> L[i];
  vector<pii> v(N);
  rep(i, 0, N) {
    v[i].first = X[i] + L[i];
    v[i].second = X[i] - L[i];
  }
  sort(all(v));
  ll p = -(1ll << 60);
  ll ans = 0;
  rep(i, 0, N) {
    if (p <= v[i].second) {
      p = v[i].first;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
using System;
using System.Linq;

class program{
  
  static void Main()
  {
    var input=Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
    var alice = input[0];
    var bob = input[1];
    
    if(alice==bob)
      Console.WriteLine("Draw");
    else if(alice==1)
      Console.WriteLine("Alice");
    else if(bob==1)
      Console.WriteLine("Bob");
    else if(alice>bob)
      Console.WriteLine("Alice");
    else
      Console.WriteLine("Bob");
  }
}
      
      

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
    int i, j=0, n, p[200][200];
    while(cin >> n && n){
        for(i=0; i<n; i++) cin >> p[j][i];
        sort(p[j], p[j]+n);
        cout << accumulate(p[j]+1, p[j]+n-1, 0) / (n-2) << endl;
        j++;
    }
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;
bool graph[8][8];
 
const int NUMBER_OF_SAMPLES = 100000000;
int main(){
  string s,t;
  cin >> s >> t ;
  int n=s.size();
  for(int i=0;i<n;i++){
      if(s.at(i)!=t.at(i))cnt++;
  }
  cout << cnt <<endl;
}


Measured memory_bytes: 3916
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    int a, b, c;
    cin>>a>>b>>c;
    if((a+b+c)<=21)
        cout<<"win"<<endl;
    else
        cout<<"bust"<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxn 101000

int main()
{
	int len,i;char s[110];
	scanf("%s",s+1);
	len=strlen(s+1);
	for (i=1;i<=len;i++)
	{
		if (s[i]=='1') s[i]='9';
		else if (s[i]=='9') s[i]='1';
	}
	printf("%s\n",s+1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define int long long int
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int k;
    cin>>k;
    int n=s.length();
    int i=0,cnt=0,c=1;
    for(i=0;i<n&&s[i]==s[n-1];i++)cnt++;
    vector<int>data;
    for(i=1;i<n;i++){
        if(s[i]==s[i-1])c++;
        else{
            data.pb(c);
            c=1;
        }
    }
    data.pb(c);
    if(data.size()==1){
        cout<<k*c/2;
        return 0;
    }
    if(k==1){
        int u=0;
        for(int i=0;i<data.size();i++)u+=data[i]/2;
        cout<<u;
        return 0;
    }
    int x=0;
    for(int i=1;i<data.size()-1;i++){
        x+=data[i]/2;
    }
    if(s[0]==s[n-1])
    x+=(data.back()+data[0])/2;
    else x+=data.back()/2+data[0]/2;
    int a=0;
    for(int i=0;i<data.size()-1;i++){
        a+=data[i]/2;
    }
    if(s[0]==s[n-1])
    a+=(data.back()+data[0])/2;
    else a+=data.back()/2+data[0]/2;
    int b=0;
    for(int i=1;i<data.size();i++){
        b+=data[i]/2;
    }
    cout<<a+b+x*(k-2);
}


Measured memory_bytes: 256
from collections import deque

INF = 10 ** 20

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    edges[a].append(b)
    edges[b].append(a)

def dijkstra(start):
    dist = [INF] * n
    dist[start] = 0
    que = deque()
    que.append((0, start))
    while que:
        score, node = que.popleft()
        for to in edges[node]:
            if dist[to] > score + 1:
                dist[to] = score + 1
                que.append((score + 1, to))
    return dist

dist1 = dijkstra(0)
dist2 = dijkstra(n - 1)
black = 0
for i in range(n):
    if dist1[i] <= dist2[i]:black += 1
white = n - black
if white >= black:
    print("Snuke")
else:
    print("Fennec")


Measured memory_bytes: 29412
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
const int N = 1e5 ;

ll power(ll x, ll y, ll p)  {
	ll res = 1;

	x = x % p;
	if (x == 0) return 0;

	while (y > 0)	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

int gcd (int a, int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

// template for using function inside main
// std::function<void(int)> dfs = [&](int u) { };
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {
	int n, m ;
	cin >> n >> m ;
	vector<vector<int>> adj(n) ;
	vector<bool> visited(n) ;
	vector<int> dp(n) ;
	while (m--) {
		int u , v ;
		cin >> u >> v ;
		--u , --v ;
		adj[u].push_back(v) ;
		// ++deg[v] ;
	}
	// queue<int> q ;

	// for (int i = 0 ; i < n ; i++) {
	// 	if (deg[i] == 0) {
	// 		q.push(i) ;
	// 		vis[i] = true ;
	// 	}
	// }

	std::function<void(int)> dfs = [&](int u) {
		visited[u] = true ;
		dp[u] = 0 ;
		for (int v : adj[u]) {
			if (!visited[v]) dfs(v) ;
			dp[u] = max(dp[u] , 1 + dp[v]);
		}
	};

	for (int i = 0 ; i < n; i++) {
		if (!visited[i]) dfs(i) ;
	}
	int ans = *max_element(dp.begin(), dp.end()) ;
	cout << ans << "\n";
	// int ans = 0 ;
	// while (!q.empty()) {
	// 	int p = q.front() ;
	// 	q.pop() ;
	// 	for (int u : adj[p]) {
	// 		if (u == p) continue ;
	// 		if (!vis[u]) {
	// 			q.push(u) ;
	// 			ans++;
	// 		}

	// 	}
	// }
	// cout << ans << "\n";
	// }








	return 0 ;

}



Measured memory_bytes: 12368
n = gets.chomp.to_i
blist = gets.chomp.split.collect{ |item| item.to_i}
ans = 0
ans += blist[0]
0.upto(n-3) do |ni|
  ans += [blist[ni],blist[ni+1]].min
end
ans += blist[n-2]

puts ans


Measured memory_bytes: 1788
a,b = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(a)]
line = [input() for i in range(b)]

for i in range(a):
  ans = 0
  for j in range(b):
    ans = ans + mat[i][j] * int(line[j])
  print(ans)


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
   
    int n,k,ans=0,a;
    cin>>n>>k;
    rep(i,n){
        cin>>a;
        if(a>=k)ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const ll inf=1000000000007;

int main() {
  vector<int> a(5);
  rep(i,0,5) cin >> a[i];
  int tend= 10;
  rep(i,0,5) {
    int d = a[i]%10;
    if(d==0) d=10;
    tend= min(tend, d);
  }
//  cout << tend << endl;
  int ans=0;
  rep(i,0,5) ans= ans +(int)((a[i]-0.5)/10)*10 +10;
  ans-=10;
  ans+=tend;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#include<vector>
#include<algorithm>
#include<string>
using ll=long long;
using P =pair<int,int>;


int main(){
  ll n,k;
  cin >> n >> k;
  ll x=n%k;
  if(x==0)cout << 0;
  else cout << min(x,k-x);
}
  




Measured memory_bytes: 256
n = int(input())
p,d = [],[]
for _ in range(n):
	x,y = (int(i) for i in input().split())
	p.append((x,y))
a = sum(p[0])%2
def f(i,j):
	s,s2,ans = bin((i+j+2**31-1)//2)[::-1][:-2],bin((i-j+2**31-1)//2)[::-1][:-2],""
	s,s2 = s+(31-len(s))*"0",s2+(31-len(s2))*"0"
	for i in range(31):
		if s[i]==s2[i]=="0": ans+="L"
		elif s[i]==s2[i]=="1": ans+="R"
		elif int(s[i]): ans+="U"
		else: ans+="D"
	return ans
if any(a!=sum(p[i])%2 for i in range(n)): print(-1)
else:
	if a-1: d.append("1")
	print(32-a)
	for i in range(31): d.append(str(2**i))
	print(" ".join(d))
	if a:
		for i,j in p: print(f(i,j))
	else:
		for i,j in p: print("R"+f(i-1,j))

Measured memory_bytes: 3316
char*p,*q,s[201],g;main(d,h,l){for(;g=~scanf("%s",p=q=s);*q=0,puts(g?s:"NA"))for(;g**p;*q++=d=h<0|h>5|l<0|l>4?g=0:d<26?97+d:".?! "[d-26])h=*p++-49,l=*p++-49,d=h*5+l;}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<bitset> 
using namespace std;
int main(){
    long N,K;
    cin >> N >> K;
    vector<long> A(N);
    int bit[40] = {};
    for(int i=0;i<N;++i){
        cin >> A[i];
        bitset<40> B(A[i]);
        for(int j=0;j<40;++j){
            bit[j] += !B.test(j);
        }
    }
  
    long X = 0;
    for(int i=39;i>=0;--i){
        if(2*bit[i] > N && (X | (1L << i)) <= K) X |= (1L << i);
    }
    long ans = 0;
    for(int i=0;i<N;++i) ans += X ^ A[i];
    cout << ans << endl;
}

Measured memory_bytes: 1024
N = int(input())
H = [int(i) for i in input().split()]
dif = []
for i in range(1,N):
    tmp = H[i]-H[i-1]
    dif.append(tmp)
cnt = 1
pre = 0
Max = 0
for i in range(1,len(dif)):
    if pre >= dif[i]:
        cnt += 1
        Max = max(Max,cnt)
    else:
        cnt = 0
print(Max)

Measured memory_bytes: 14252
import re

def main():
    s = input()
    k = int(input())
    n = len(s)
    a = set()
    for i in range(n):
        for j in range(i + 1, min(n + 1, i + 1 + k)):
            a.add(s[i:j])
    print(sorted(list(a))[k - 1])

if __name__ == '__main__':
    main()

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


int main()
{
	//freopen("main.inp", "r", stdin);
	//freopen("main.out", "w", stdout);
	int n; cin >> n;
	float x = 1.0 * n / 3;
	x *= (x * x);
	cout << setprecision(12) << fixed << x;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    var (n, a, b) = readLine()!!.split(" ").map { it.toInt() }

    var cnt = 0
    for (i in 1..n) {
        val sum = digitSum(i)
        if (sum in a..b) cnt += i
    }
    print(cnt)
}

fun digitSum(num: Int): Int{
    var sum = 0
    var num = num

    while (num != 0){
        sum += num%10
        num /= 10
    }
    return sum
}

Measured memory_bytes: 36124
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Node
{
    internal int key;
    internal Node left, right, parent;
    public Node(int key) {
        this.key = key;
    }
}

class A
{
    static Node root;
    public static void Main() {
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++) {
            String[] input = Console.ReadLine().Split(' ');
            if (input[0] == "insert") {
                Insert(int.Parse(input[1]));
            } else {
                StringBuilder output = new StringBuilder();
                Inorder(root, output);
                Console.WriteLine(output);
                output = new StringBuilder();
                Preorder(root, output);
                Console.WriteLine(output);
            }
        }
        
       
    }
    static void Insert(int key) {
        Node x = root;
        Node y = null;
        Node z = new Node(key);
        while (x != null) {
            y = x;
            x = z.key < x.key ? x.left : x.right;
        }
        z.parent = y;
        if (y == null) {
            root = z;
        }else if (z.key < y.key) {
            y.left = z;
        } else {
            y.right = z;
        }
    }
    static void Preorder(Node nodes, StringBuilder output) {
        if (nodes == null) {
            return;
        }
        output.Append(" " + nodes.key);
        Preorder(nodes.left, output);
        Preorder(nodes.right, output);
    }

    static void Inorder(Node nodes, StringBuilder output) {
        if (nodes == null) {
            return;
        }
        Inorder(nodes.left, output);
        output.Append(" " + nodes.key);
        Inorder(nodes.right, output);
    }

    /*static void Postorder(Node[] nodes, int num, StringBuilder output) {
        if (num == -1) {
            return;
        }
        Postorder(nodes, nodes[num].left, output);
        Postorder(nodes, nodes[num].right, output);
        output.Append(" " + num);
    }*/
}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " ";
    if(a+b > n){
        cout << (a + b) - n << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int w,n,i,temp,a,b;
	int x[31];
	
	for(i=0;i<=30;i++)
		x[i]=i;
	scanf("%d",&w);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		temp=x[a];
		x[a]=x[b];
		x[b]=temp;
	}
	for(i=1;i<=w;i++)
		printf("%d\n",x[i]);
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 596
# -*- coding utf-8 -*-
import heapq

MOD = 10 ** 9 + 7

N, M = map(int, input().split())
AN = map(int, input().split())
hq = []
for an in AN:
    heapq.heappush(hq, -an)

for i in range(M):
    val = heapq.heappop(hq)
    heapq.heappush(hq, -(-val//2))

ans = - sum(hq)

print(ans)


Measured memory_bytes: 14180
main = do
  li <- getLine
  let n = read li
  li <- getLine
  let as = map read $ words li
  li <- getLine
  let bs = map read $ words li
  li <- getLine
  let cs = map read $ words li
  let ans = compute n as bs cs
  print ans

compute :: Int -> [Int] -> [Int] -> [Int] -> Int
compute n as bs cs = (sum bs +) $
  sum $ map ((cs !!).pred.fst) $ filter (\(a,a1) -> succ a == a1) $ zip as (tail as)


Measured memory_bytes: 764
use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let ab = (0..n)
        .map(|_| (read::<usize>(), read::<usize>()))
        .collect::<Vec<_>>();
    let mut t = vec![vec![]; m + 1];

    for (a, b) in ab {
        if a > m {
            continue;
        }
        t[a].push(b);
    }
    for i in 1..m {
        t[i].sort()
    }
    let mut ans = 0;

    let mut x = BinaryHeap::new();
    for i in 1..m + 1 {
        for j in 0..t[i].len() {
            x.push(t[i][j]);
        }

        let v = x.pop();
        if v.is_none() {
            continue;
        } else {
            ans += v.unwrap();
        }
    }
    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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 string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> a) {
    long long mn = *min_element(a.begin(), a.end());
    long long mx = *max_element(a.begin(), a.end());
    long long d = mx - mn;
    if (d == 0) {
        long long x = a[0];
        if (x == N - 1) {
            cout << YES << endl;
            return;
        }
        if (x >= 1 && x <= N / 2) {
            cout << YES << endl;
            return;
        }
        cout << NO << endl;
    } else if (d == 1) {
        long long cmn = count(a.begin(), a.end(), mn);
        long long cmx = count(a.begin(), a.end(), mx);
        if ( (mx - cmn) >= 1 && (mx - cmn) * 2 <= cmx) {
            cout << YES << endl;
            return;
        }
        cout << NO << endl;
    } else {
        cout << NO << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
class UnionFind {
public:
	vector<int> Parent;
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	int root(int A) {
		if (Parent[A] < 0) {
			return A;
		}
		return Parent[A] = root(Parent[A]);
	}

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

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
		if (size(A) < size(B)) {
			swap(A, B);
		}

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}

};
int main()
{
	int n, m, q;
	cin >> n >> m;
	UnionFind uni(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		uni.connect(s, t);
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		if (uni.root(s) == uni.root(t)) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3148
import sys
import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n, m = read_ints()
    a = read_int_list()
    a = [x // 2 for x in a]
    lcm = 1
    for x in a:
        lcm *= x // math.gcd(lcm, x)
    for x in a:
        if lcm // x % 2 == 0:
            print(0)
            exit()
    print(math.ceil((m // lcm) / 2))

if __name__ == '__main__':
    Main()

Measured memory_bytes: 20264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    ll sum = 0;
    for (ll i=0; i<n; i++) {
        if ((i+1)%3==0 || (i+1)%5==0) continue;
        sum += (i+1);
    }
    
    
    
    
    cout << sum << endl;
    return 0;
}


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

int main() {
  int N,A,B;
  A=0,B=0;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0;2*i<N;i++){
    A=A+vec.at(2*i);
    if(2*i+1<N){
      B=B+vec.at(2*i+1);
    }
  }
  cout<<A-B<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  string S; cin >> S;
  int Len = S.size();
  vector<int> L(Len), R(Len);
  int r = 0;
  for (int i = 0; i < Len; ++i) {
    if (S[i] == 'R') r = i;
    R[i] = r;
  }
  int l = Len;
  for (int i = Len - 1; i >= 0; --i) {
    if (S[i] == 'L') l = i;
    L[i] = l;
  }
#if 0
  for (char c : S) cout << c << " ";
  cout << endl;
  cout << R << endl;
  cout << L << endl;
#endif

  vector<int> ans(Len, 0);
  for (int i = 0; i < Len; ++i) {
    if (S[i] == 'R') {
      if ((L[i] - R[i]) % 2 == 1) {
        ans[L[i]-1]++;
      } else {
        ans[L[i]]++;
      }
    } else {  // L
      if ((L[i] - R[i]) % 2 == 1) {
        ans[R[i]+1]++;
      } else {
        ans[R[i]]++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4552
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	int s1 = a;
	int s2 = b;
	int c = a - 1;
	int d = b - 1;
	while (c--)
	{
		b *= 10;
		s2 += b;
	}
	while (d--)
	{
		a *= 10;
		s1 += a;
	}
	printf("%d", s1 > s2 ? s1 : s2);
	return 0;
}

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

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];

void bfs(int s) {
queue<int> q;
q.push(s);
for(int i=0;i<n;i++) d[i] = INFTY;
d[s] = 0;
int u;
while(!q.empty()) {
  u = q.front();q.pop();
  for(int v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(d[v] != INFTY)continue;
    d[v] = d[u] +1;
    q.push(v);
  }
}
for(int i= 0;i<n;i++) {
  cout << i+1<<" "<<((d[i] == INFTY) ? (-1):d[i]) << endl;
}
}

int main() {
  int u,k,v;

  cin >> n;
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      M[i][j] = 0;
    }
  }

  for(int i=0;i<n;i++) {
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++) {
      cin >>v;v--;M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 3124