akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc077/tasks/arc084_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));

    int ans = 0;
    for (auto &x : B) {
        // 配列Aからxより小さい値を探す
        auto ia = lower_bound(ALL(A), x);
        int a = ia - A.begin();
        // 配列Cからxより大きい値を探す
        auto ic = lower_bound(ALL(C), x + 1);
        int c = C.end() - ic;
        ans += a * c;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5572
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> c(H);
	for (int i = 0; i < H; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < H; i++) {
		cout << c[i] << endl << c[i] << endl;
	}

	return 0;
}

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

const int N = 1e5+5, mod = 1e9+7;
string s;
long long n, memo[N][15];
long long solve(int idx = 0, int rm = 0){
  if(idx == n){
    return rm == 5;
  }
  long long& ret = memo[idx][rm];
  if(~ret) return ret;
  ret = 0;
  if(s[idx] == '?'){
    for(int i = 0; i < 10; ++i){
      ret += solve(idx + 1, (i + (rm * 10)) % 13);
      ret %= mod;
    }
  }else{
    ret = solve(idx + 1, (s[idx] - '0' + (rm * 10)) % 13);
  }
  return ret;
}
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
  cin >> s;
  n = s.size();
  memset(memo, -1, sizeof(memo));
  cout << solve() << '\n';
  return 0;
}


Measured memory_bytes: 18512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int imos[200005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
	}
	rep(_,k){
		bool change = false;
		memset(imos, 0, sizeof(imos));
		rep(i,n){
			int l = max(i-a[i], 0);
			int r = min(i+a[i], n-1);
			imos[l]++;
			imos[r+1]--;
		}
		rep(i,n){
			imos[i+1] += imos[i];
			if(a[i] != imos[i]) change = true;
			a[i] = imos[i];
		}
		if(!change) break;
	}
	rep(i,n) cout << a[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 4772
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	if(a<b){
	if(a<c&&c<b){
		printf("Yes");
	}else {
		printf("No");
	}
	}else{
		if(b<c&&c<a){
		printf("Yes");
	}else {
		printf("No");
	}
		
		
	}
	
	return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
        var S string
        fmt.Scan(&S)

        cnt := 0
        max := 0
        for i := 0; i < len(S); i++ {
                if S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T' {
                        cnt++
                } else {
                        if max < cnt {
                                max = cnt
                        }
                        cnt = 0
                }
        }
        if max < cnt {
                max = cnt
        }
        fmt.Println(max)
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
typedef long long ll;
const int maxn = 109;
int l;
int main(){
	scanf("%d",&l);
	double a,b,c;
	a = b = c = l/3.0;
	printf("%.12f\n",a*b*c);
	return 0;
}

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

int main(){
	ll h,w;
	cin >> h >> w;
	
	ll res = 1e18;
	// 最初縦に切る
	rep(i,w-1){
		ll a,b,c;
		a = h*(i+1);
		
		if(h%2==0 || (w-i-1)%2==0){
			b = h*(w-i-1)/2;
			c = h*(w-i-1)/2;
		}
		else{
			ll dmin = min(w-i-1,h);
			ll dmax = max(w-i-1,h);
			b = dmin * (dmax/2);
			if(dmax%2==0) c = b;
			else c = dmin * (dmax/2 + 1);
		}
		
		res = min(res, max({a,b,c}) - min({a,b,c}));
	}
	
	swap(h,w);
	// 最初横に切る
	rep(i,w-1){
		ll a,b,c;
		a = h*(i+1);
		
		if(h%2==0 || (w-i-1)%2==0){
			b = h*(w-i-1)/2;
			c = h*(w-i-1)/2;
		}
		else{
			ll dmin = min(w-i-1,h);
			ll dmax = max(w-i-1,h);
			b = dmin * (dmax/2);
			if(dmax%2==0) c = b;
			else c = dmin * (dmax/2 + 1);
		}
		
		res = min(res, max({a,b,c}) - min({a,b,c}));
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <pair <int, int>> vii;

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int n;
    cin >> n;
    vii v[25];
    for (int i = 0; i < n; ++i) {
        int z;
        cin >> z;
        while (z--) {
            int x, y;
            cin >> x >> y;
            v[i].emplace_back(x-1, y);
        }
    }
    int ans = 0;
    for (int p = 0; p < (1 << n); ++p) {
        bool f = false;
        for (int i = 0; i < n; ++i) {
            if (p & (1 << i)) { // hon
                for (pii s : v[i]) {
                    if ((((p & (1 << s.first)) > 0) ^ s.second) != 0) {
                        f = true;
                        break;
                    }
                }
            }
            if (f) break;
        }
        if (!f) ans = max(ans, __builtin_popcount(p));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
N,C = map(int,input().split())
T = [[0 for i in range(10**5+1)] for j in range(C)]

for i in range(N):
    s,t,c = map(int,input().split())
    T[c-1][s] += 1
    T[c-1][t] -= 1
for i in range(C):
    for j in range(10**5):
        T[i][j+1] += T[i][j]

ans = 0
for i in range(1,10**5+1):
    a = 0
    for j in range(C):
        if T[j][i] or T[j][i-1]:
            a += 1
    ans = max(ans,a)
print(ans)

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

int n, a, b, c, d;
char str[100010];

int main(){
	scanf("%d%d%d%s", &n, &a, &b, str);
	for(int i = 0; str[i]; i++){
		switch(str[i]){
		case 'a':
			if(c < a + b){
				c++;
				puts("Yes");
			}
			else puts("No");
			break;
		case 'b':
			d++;
			if(c < a + b && d <= b){
				c++;
				puts("Yes");
			}
			else puts("No");
			break;
		default:
			puts("No");
		}

	}
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 1e5;

int n;
int a[MaxN + 5];
bool vis[MaxN + 5];

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		int cnt = 0;
		for(int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
		}
		bool f = 0;
		while(true) {
			f = 0;
			for(int i = 1; i <= n; i++) {
				if(i == 1) {
					if(a[i] == i) {
						swap(a[i], a[i + 1]);
						f = 1;
						cnt++;
					}
				}
				else if(i == n) {
					if(a[i] == i) {
						swap(a[i], a[i - 1]);
						f = 1;
						cnt++;
					}
				}
				else {
					if(a[i] == i && a[i + 1] == i + 1) {
						swap(a[i], a[i + 1]);
						f = 1;
						cnt++;
					}
					if(a[i] == i) {
						f = 1;
						if(a[i - 1] != i) swap(a[i - 1], a[i]);
						else swap(a[i], a[i + 1]);
						cnt++;
					}
				}
			}
			if(f == 0) break;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

//r本再利用されない時、N本から再利用して売れる本数
int rec(int m,int n,int N,int r){
  if(N == 0) return 0;

  int k = N/m * n;//新たに作り出す本数
  r = N%m;//再利用されない本数
  int res = N + k;//売った本数
  
  while(1){
    k = k/m * n;//k本からk/m本再利用
    res += k;
    r += k%m;
    if(k < m){//k本で再利用できなくなったら
      k += r;
      res += rec(m,n,k,r);
    }
  }
}

int main(){
  int N;
  cin >> N;
  bool flag = false;
  int ans = 0;

  for(int X = 1;X <= 50000;X++){
    if((int)(X*1.08) == N){
      flag = true;
      ans = X;
      break;
    }
  }
  if(flag) cout << ans << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertion(int A[], int n)
{
  int j, i, v;
  for(i = 2 ; i <= n ; i++)
    {
      v = A[i];
      j = i - 1;
      while(j >= 0 && A[j] > v)
	{
	  A[j + 1] = A[j];
	  j--;
	}
      A[j + 1] = v;
      trace(A, n);
    }
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  /*

    your code

   */
  insertion(A, n);
  return 0;
}


Measured memory_bytes: 2140
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
         
            int r = scan.nextInt();
            int c = scan.nextInt();
            int [][]sheet;
            sheet = new int[(r+1)][(c+1)];
            int sheetr,sheetc;
 
            for(sheetr = 0; sheetr < r; sheetr++){
                for(sheetc = 0; sheetc < c; sheetc++){
                sheet[sheetr][sheetc] = scan.nextInt();
                }
            }
            for(sheetr = 0; sheetr < r; sheetr++){
                for(sheetc = 0; sheetc < c; sheetc++){                   
                sheet[sheetr][c] += sheet[sheetr][sheetc];
                }
            }
            for(sheetc = 0; sheetc <= c; sheetc++){
                for(sheetr = 0; sheetr < r; sheetr++){
                sheet[r][sheetc] += sheet[sheetr][sheetc];
                }
            }
            for(sheetr = 0; sheetr <= r; sheetr++){
                for(sheetc = 0; sheetc <= c; sheetc++){ 
                    if(sheetc < c){
                        System.out.print(sheet[sheetr][sheetc]+" ");
                    }
                    else if(sheetc == c){
                    System.out.print(sheet[sheetr][sheetc]);
                    }
                    if(sheetc == c){
                        System.out.print("\r\n");
                    }
                }
            }
    }
}

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

int main(void){
    int a,b=0,c=0,d=0;
    for(int i=0;i<10;i++){
        cin>>a;
        if(b<a){
            swap(b,a);
        }
        if(c<a){
            swap(c,a);
        }
        if(d<a){
            swap(d,a);
        }
    }
    cout<<b<<endl<<c<<endl<<d<<endl;
}


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

int nd[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string wk[7] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

int main(void){
  int m, d;
  while(cin >> m >> d && m && d){
    int sd = d;
    for(int i = 1; i < m; i++) sd += nd[i];
    cout << wk[sd % 7] << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
#include<math.h>
 
int main() {
    double x[2], y[2], l;
    scanf("%lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1]);
    l = hypotl(x[1] - x[0], y[1] - y[0]);
    printf("%f\n", l);
    return 0;
}


Measured memory_bytes: 2108
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  int size = s.size();
  REP(i,size){
    cout << "x";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,l;
  cin>>n>>l;
  string s[n];
  for(int i = 0; i < n; i++) cin>>s[i];
  sort(s,s+n);
  for(int i = 1; i < n; i++) s[0]+=s[i];
  cout<<s[0]<<endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int l = s.size();
  int ans = 1000;
  for(int i = 0; i < 26; i++){
    char now = 'a' + i;
    int cnt, tl = l;
    string test = s;
    for(int j = 0; j < 150; j++){
      bool ok = true;
      for(int k = 0; k < tl-1; k++){
        if(test.at(k) != now) ok = false;
        if(test.at(k+1) == now) test.at(k) = now;
      }
      if(tl > 0) if(test.at(tl-1) != now) ok = false;
      if(ok){
        cnt = j;
        break;
      }
      test.pop_back();
      tl = test.size();
    }
    ans = min(ans, cnt);
  }
  
  cout << ans << endl;
}

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

using namespace std;



int main() {

	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	int total = 0;
	int minn=1000;
	for (int i = 0; i < 5; i++) {
		if (a[i] % 10 != 0) {
			minn = min(minn, a[i] % 10);
			total += a[i] + (10 - a[i] % 10);
		}
		else {
			total += a[i];
		}
	}
	if (minn == 1000) {
		minn = 0;
		cout << total << endl;
	}
	else {
		cout << total - (10 - minn) << endl;
	}
}

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

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if (A >= K) {
        cout << A-K << " " << B << endl;
    }
    else {
        K -= A;
        A = 0;
        cout << A << " " << max(0LL, B-K) << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
S = [list(map(int, input())) for _ in range(N)]

lst = [0] * N
lst[0] = 1

stack = [0]
flag = True
while len(stack) != 0:
    tmp = stack.pop()
    for index, x in enumerate(S[tmp]):
        if x == 0:
            continue
        if lst[index] == 0:
            lst[index] = -lst[tmp]
            stack.append(index)
        else:
            if lst[tmp] == -lst[index]:
                pass
            else:
                flag = False
                break
    if not flag:
        print (-1)
        exit()

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

g = np.array(S)
anslst = floyd_warshall(g)
ans = int(np.max(anslst))

print (ans + 1)

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


int main(){
  int k;
  cin>> k;
  vector<uint64_t> L(87);
  L.at(0)=2;
  L.at(1)=1;
  for(int i=2 ; i<87 ; i++){
    L.at(i) = L.at(i-1)+L.at(i-2);
  }
  cout<<L.at(k)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 998244353;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i, n){
        char c = s[i];
        if(i % 2 == 0){
            if(c == 'p'){
                ans--;
            }
        } else {
            if(c == 'g'){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
char dice[8][5][5];
int i,j,res,f[3];
int MIN(int x,int y){ return x<y?x:y; }
int input()
{
    for(i=1;i<=6;i++)
        for(j=2;j>=0;j--)
        {
            scanf("%s",dice[i][j]);
            if(i==1&&j==2&&dice[i][j][0]=='#') return 0;
        }
    return 1;
}
void f1(int a,int b,int m)
{
    for(f[m]=i=0;i<3;i++) if(dice[a][b][i]=='*') f[m]=1;
}
void f3(int a,int b,int m)
{
    for(f[m]=i=0;i<3;i++) if(dice[a][i][b]=='*') f[m]=1;
}
void C(int x)
{
    if(f[1]&&f[2]) res=MIN(res,x);
}
int main()
{
    while(input())
    {
        res=9;

        f1(1,0,1),f1(3,0,2),C(0);
        f1(1,2,1),f1(3,2,2),C(2);
        f3(1,0,1),f3(3,2,2),C(1);
        f3(1,2,1),f3(3,0,2),C(1);

        f1(2,0,1),f1(4,0,2),C(3);
        f1(2,2,1),f1(4,2,2),C(3);
        f3(2,0,1),f3(4,2,2),C(2);
        f3(2,2,1),f3(4,0,2),C(2);

        f1(5,0,1),f1(6,2,2),C(1);
        f1(5,2,1),f1(6,0,2),C(1);
        f3(5,0,1);
        for(f[2]=i=0;i<3;i++) if(dice[6][2-i][0]=='*') f[2]=1;
        C(2);
        f3(5,2,1);
        for(f[2]=i=0;i<3;i++) if(dice[6][2-i][2]=='*') f[2]=1;
        C(2);

        printf("%d\n",res);
    }
}

Measured memory_bytes: 536
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	char a[200000];
	long long int ans[200000];
	ans[0]=1;
	scanf("%s", a);
	int n=strlen(a);
	int num[200000][26];
	for(int i=0; i<26; i++){
		for(int j=0; j<n; j++){
			if(j==0){
				if(a[0]!=(char)('a'+i)){
					num[0][i]=1;
				}else{
					num[0][i]=0;
				}
			}else{
				if(a[j]!=(char)('a'+i)){
					num[j][i]=num[j-1][i]+1;
				}else{
					num[j][i]=num[j-1][i];
				}
			}
		}
	}
	for(int i=1; i<n; i++){
		int j0;
		for(int j=0; j<26; j++){
			if(a[i]==(char)('a'+j)) j0=j;
		}
		ans[i]=ans[i-1]+num[i-1][j0];
	}
	printf("%lld\n", ans[n-1]);
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y) flag = true;
    }

    if (flag) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3556
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskC {
        static long modpow(long a , int b){
            a%=1000000007;
            long ans = 1;
            while (b>0){
                if ((b&1)>0) ans=ans*a%1000000007;
                b>>=1;
                a=a*a%1000000007;
            }
            return ans;
        }
        static long sol(long a){
            if (a==1) return 1;
            long ans = sol(a/2);
            return ans+ans+1;
        }
        public void solve(int testNumber, InputReader in, PrintWriter out){
            int h = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            int[] ans = new int[h+1];
            for (int i = 1; i <h+1 ; i++) {
                ans[i]=Integer.MAX_VALUE;
            }
            for (int i = 0; i <n; i++) {
                a[i]=in.nextInt();
                b[i]=in.nextInt();
                if (a[i] > h) a[i]=h;
                ans[a[i]]=Math.min(ans[a[i]] , b[i]);
            }
            int min = Integer.MAX_VALUE;
            for (int i = h; i >=1 ; i--){
                if (ans[i]<min)min=ans[i];
                ans[i]=min;
            }
            for (int i = 1; i <=h; i++) {
                for (int j = 0; j <n; j++){
                    if (i-a[j] >0)
                    ans[i]=Math.min(ans[i] , ans[i-a[j]]+b[j]);
                }
            }
            System.out.println(ans[h]);



        }




    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 23252
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;




int main(){
	int n, m, i, ans = 0;
	cin >> n >> m;
	vector<int>v(m);
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[i] = n  - a;
		if (v[i] < 0) v[i] = 0;
		ans += v[i];
	}
	sort(v.begin(), v.end());
	cout << ans - v[m-1] << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s;
cin >> s;
int n = SZ(s);
int k;
cin >> k;

rep(i,n) {
    if(s[i] == 'a') continue;
    int d = ('z' - s[i]) + 1;
    if(k >= d) {
        s[i] = 'a';
        k -= d;
    }
}
k %= 26;
rep(i,k) {
    if(s[n-1] == 'z') s[n-1] = 'a';
    else s[n-1]++;
}
cout << s << endl;
return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
typedef pair<double,int> Pdi;
int n;
int syaku[100010];
int main(int argc,char const* argv[])
{
  cin >> n;
  vector<Pdi> member(n);
  for(int i=0;i<n;i++)
    {
      double gpa;
      cin >> gpa;
      member[i]=make_pair(gpa,i);
    }
  sort(member.begin(),member.end());
  vi ans(n);
  for(int i=0;i<n;i++)
    {
      int id=member[i].second;
      int lb=lower_bound(member.begin(),member.end(),make_pair(member[i].first,-1))-member.begin();
      int ub=upper_bound(member.begin(),member.end(),make_pair(member[i].first,n+1))-member.begin();
      ans[id]=3*lb+(ub-lb-1);
    }
  for(int i=0;i<n;i++)
    {
      cout << ans[i] << endl;
    }
  return 0;
}



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

int A, B;
int a[5000], b[5000];

signed main()
{
	cin >> A >> B;
	rep(i,A) cin >> a[i];
	rep(i,B) cin >> b[i];

	int ans = 0;

	rep(i,B) {
		int ai = 0;
		int bi = i;
		int cnt = 0;

		while (ai < A) {
			if (a[ai] == b[bi]) {
				ai++;
				bi++;
				cnt++;
			} else {
				ai++;
			}
		}

		ans = max(ans, cnt);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1200
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int H1, M1, H2, M2, K;

int main()
{
	scanf("%d%d%d%d%d", &H1, &M1, &H2, &M2, &K);
	int a = H1 * 60 + M1;
	int b = H2 * 60 + M2;
	printf("%d\n", b - a - K);
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;

    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }

    int s[D][26];
    int t[D] = {};
    //各日について、s[i][j]が最大になるコンテストタイプで初期化
    rep(i, 0, D) {
        int mx = -1;
        rep(j, 0, 26) {
            cin >> s[i][j];
            if (mx < s[i][j]) {
                mx = s[i][j];
                t[i] = j;
            }
        }
    }

    //日程を乱数で初期化
    srand(time(NULL));
    /*rep(i, 0, D) {
        t[i] = rand() % 26;
    }*/

    ll mx_score = -1e18;
    int cnt = 150000;
    while (cnt--) {
        //d日目のコンテストをqに置き換えてスコアを計算し、改善しなければ元に戻す
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        //スコアを計算する
        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            //増加分
            score[i] += s[i][t[i]];

            last_day[t[i]] = i;

            //減少分
            ll decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        //cout << "score[D - 1]: " << score[D - 1] << endl;
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 3676
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)


Measured memory_bytes: 5592
package main

import "fmt"

func count(n int, k int) int {
	if n == k-1 {
		return 1
	}
	if n == k {
		return n+1
	}
	var min,max int
	min = k*(k-1)/2
	if n == k+1 {
		max = n*(n+1)/2 - 1
	} else {
		max = n*(n+1)/2 - (n-k)*(n-k+1)/2
	}
//fmt.Println(min,max)
	return max-min+1
}

func main(){
	var n,k,sum int
	fmt.Scan(&n,&k)
	for i:=k ; i<=n+1; i++ {
		sum += count(n,i)
//fmt.Println(sum)
	}
	fmt.Println(sum%1000000007)
}


Measured memory_bytes: 1752
#include <stdio.h>
int main(void){
    // Your code here!
int n;
scanf("%d",&n);
int i;
int p[n];
for (i=0;i<n;i++){
    scanf("%d",&p[i]);
    
}
int per[3];
 int ans=0;
for (i=1;i<n-1;i++){
    per[0]=p[i-1];
    per[1]=p[i];
    per[2]=p[i+1];
    if( (per[0]< per[1] &&per[1]< per[2])||(per[0]> per[1] &&per[1]> per[2])){
        ans++;
    }
}
printf("%d\n",ans);
    return (0);
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)


typedef long long ll;

int main() {
    ll n;
    ll mod =1000000007;
    cin>>n;
    vector<ll> cap(n);
    rep(i,n) cin>>cap[i];
    ll ans=1;
    ll a=0,b=0,c=0;
    rep(i,n){
        ll k=cap[i];
        if(a==k&& b==k&&c==k){ ans*=3; a++;}
        else if(b==k&&c==k){ans*=2; b++;}
        else if(a==k&&b==k){ans*=2; a++;}
        else if(a==k)a++;
        else if(b==k)b++;
        else if(c==k)c++;
        else ans=0;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}




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

int main() {
	ll X, K, D;
	cin >> X >> K >> D;

	X = abs(X);
	ll ans = 0;
	ll res = X / D;
	if(K - res < 0) ans = X - K * D;
	else if((K - res) % 2 == 0) ans = X % D;
	else ans = abs((X % D) - D);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	vector<int64> aa(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
	}
	sort(aa.begin(), aa.end());
	cout << aa[nn - 1] << ' ';
	if(aa[nn - 1] % 2 == 1)
	{
		aa[nn - 1]++;
	}
	auto ite = lower_bound(aa.begin(), aa.end(), (aa[nn - 1] / 2));
	int64 tmp = *ite;
	ite--;
	if(aa[nn - 1] / 2 - *ite > tmp - aa[nn - 1] / 2)
	{
		cout << tmp << endl;
	}
	else
	{
		cout << *ite << endl;
	}
		
	return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  while(1){
    s.pop_back();
    if(s.length()%2==0){
      int a = s.length()/2;
      int b=0;
      for(int i=0;i<a;++i){
        if(s[i]!=s[a+i]){
          b=1;
        }
      }
      if(b==0){
        cout<<s.length();
        return 0;
      }
    }

  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


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


int main(){
    int N;
    cin >> N;
    cout << N * N * N << endl;

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
OkashiList = []
KesuList = []
for _ in range(K):
        d = int(input())
        li = list(map(int,input().split()))
        OkashiList.append(li)
for i in OkashiList:
    for j in i:
        if j in KesuList:
            pass
        else:
            KesuList.append(j)
ans = N - len(KesuList)
print(ans)

Measured memory_bytes: 9124
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    double sum = 0;
    rep(i,n) {
        sum += 1/(double)a[i];
    }
    double ans = 1/sum;
    printf("%.6f\n",ans);
    return 0;
}

































    


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;
typedef long long ll;
const int mo = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
char str[210000];
void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    string head, tail;
    int sum=0;
    rep(i,n)
    {
        sum += s[i]=='('?1:-1;
        if(sum<0)
        {
            head+="(";
            sum++;
        }
    }
    while(sum)
    {
        tail+=")";
        sum--;
    }   
    cout<<head<<s<<tail<<endl;
    return ;
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

bool isPalindrome(string s)
{

    forn(i,0,s.sze/2)
    {
        if(s[i] != s[s.sze-i-1]) return false;
    }

    return true;
}


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

    string s;
    cin>>s;

    int n = s.sze;
    if(isPalindrome(s) && isPalindrome(s.substr(0,(n-1)/2)) && isPalindrome(s.substr((n+1)/2))) cout<<"Yes";
    else cout<<"No";







    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

struct pq {
    int first, second;
    pq(int x,int y) :first{x},second{y} {}
};

struct pq1 : pq {
    pq1(int x,int y) : pq(x,y) {}
    bool operator<(const pq1 &p) const{
        return second > p.second;
    }
};

struct pq2: pq{
    pq2(int x,int y) : pq(x,y) {}
    bool operator<(const pq2 &p) const{
        if (first == p.first) {
            return second < p.second;
        } else {
            return first < p.first;
        }
    }
};

int main(void)
{
    IOS
    int n,m;
    cin >> n >> m;
    priority_queue<pq1> v1;
    priority_queue<pq2> v2;
    REP(i,n) {
        int a,b;
        cin >> a >> b;
        pq1 p = pq1(b,a);
        v1.push(p);
    }

    int ans = 0;
    FOR(i,1,m+1) {
        while(!v1.empty() && v1.top().second <= i) {
            v2.push(pq2(v1.top().first,v1.top().second));
            v1.pop();
        }
        if (!v2.empty()) {
            ans += v2.top().first;
            v2.pop();
        }

    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
 
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;
 
const ll N    = 5e5+5;
const ll INF  = 1e9;
const ll mod  = 1e9+7;

ll a[N],leftMax[N],rightMax[N];

void solve()
{
    ll n,d;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    leftMax[0] = -INF;
    for(int i=1;i<=n;i++)
        leftMax[i] = max(leftMax[i-1],a[i]);
    rightMax[n+1] = -INF;
    for(int i=n;i>=1;i--)
        rightMax[i] = max(rightMax[i+1],a[i]);

    for(int i=1;i<=n;i++)
        cout<<max(leftMax[i-1],rightMax[i+1])<<endl;


}     
 
int main(){
    FAST
    int t= 1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
} 

Measured memory_bytes: 11392
#include <stdio.h>
#include <iostream>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 200005
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
char s[maxn];
char t[maxn];
int main()
{
    scanf("%s",s);
    scanf("%s",t);
    int len=strlen(s);
    int ans=0;
    for(int i=0;i<len;i++){
    	if(s[i]!=t[i]){
    		ans++;
    	}
    }
    printf("%d\n",ans);
    
    return 0;
}


Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
 
int n,k,result,a;
int t[1300005];
 
void update(int idx,int l,int r, int aim, int val){
    if (l == aim and aim == r){
        t[idx] = val;//这里是否可以直接赋值???
        return;
    }
    int mid = (l+r)>>1;
    if (aim <= mid){
        update(idx<<1,l,mid,aim,val);
    }
    else{
        update(idx<<1|1,mid+1,r,aim,val);
    }
    t[idx] = max(t[idx<<1],t[idx<<1|1]);
    return;
}
 
int query(int idx,int l,int r,int aiml,int aimr){
    if (aiml<=l and r<=aimr){
        return t[idx];
    }
    int mid = (l+r)>>1, ansl = 0, ansr = 0;
    if (aiml<=mid){
        ansl = query(idx<<1,l,mid,aiml,aimr);
    }
    if (mid<aimr){
        ansr = query(idx<<1|1,mid+1,r,aiml,aimr);
    }
    return max(ansl,ansr);
}
 
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        result = query(1,0,300000,max(0,a-k),min(300000,a+k))+1;
        update(1,0,300000,a,result);
    }
    cout<<query(1,0,300000,0,300000)<<endl;
    return 0;
}

Measured memory_bytes: 7820
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if(abs(a-b) <= d and abs(b-c) <= d) cout << "Yes" << endl;
	else if(abs(a-c) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a+b>=a-b && a+b>=a*b)
		printf("%d",a+b);
	else if(a-b>=a+b && a-b>=a*b)
		printf("%d",a-b);
	else
		printf("%d",a*b);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m1 = Integer.parseInt(sc.next());
		int d1 = Integer.parseInt(sc.next());
		int m2 = Integer.parseInt(sc.next());
		int d2 = Integer.parseInt(sc.next());
		if (m2 == m1 + 1 && d2 == 1) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  string s; cin>>s;
  string t=s; reverse(ALL(t));
  ll i=0,j=0;
  ll cnt=0;
  while(i<s.length() && j<s.length()) {
    if(s[i]==t[j]) {i++;j++;continue;}
    if(s[i]=='x') {cnt++; i++;continue;}
    if(t[j]=='x') {cnt++; j++;continue;}
    cout<<-1<<endl;
    return 0;
  }
  while(i<s.length()) {
    if(s[i]=='x') {cnt++; i++; continue;}
    else {cout<<-1<<endl; return 0;}
  }
  while(j<s.length()) {
    if(t[j]=='x') {cnt++; j++; continue;}
    else {cout<<-1<<endl; return 0;}
  }
  cout<<cnt/2<<endl;

}


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

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

    for(int i=0;i<n;i++){
        int in;
        cin>>in;
        v.emplace_back(in);
    }
    sort(v.begin(),v.end());

    int s=accumulate(v.begin(),v.begin()+k,0);
    cout<<s<<endl;

}


Measured memory_bytes: 3632
s = input()
if s[0]=='0' or s[-1]=='1':
    print(-1)
    exit()
for i in range(len(s)//2+len(s)%2):
    if s[i] != s[-i-2]:
        print(-1)
        exit()
par = len(s)
for i in range(len(s)-2,-1,-1):
    if s[i]=='1':
        print(i+1,par)
        par = i+1
    else:
        print(i+1,par)

Measured memory_bytes: 4636
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int h, w, n;
int x, y;
char as[300000], bs[300000];

int a[300000], b[300000];

int main()
{
	int i, j, k, l;
	cin>>h>>w>>n;
	cin>>x>>y;
	x--, y--;
	scanf("%s%s", as, bs);
	for(k=0;k<2;k++)
	{
		for(i=0;i<n;i++)
		{
			if(k == 0 && as[i] == 'L') a[i]=-1;
			else if(k == 0 && as[i] == 'R') a[i]=1;
			else if(k == 1 && as[i] == 'U') a[i]=-1;
			else if(k == 1 && as[i] == 'D') a[i]=1;
			else a[i]=0;

			if(k == 0 && bs[i] == 'L') b[i]=-1;
			else if(k == 0 && bs[i] == 'R') b[i]=1;
			else if(k == 1 && bs[i] == 'U') b[i]=-1;
			else if(k == 1 && bs[i] == 'D') b[i]=1;
			else b[i]=0;
		}
		int u=!k?w-1:h-1;
		int tar=!k?y:x;
		int s=0, e=u;
		for(i=n-1;i>=0;i--)
		{
			if(b[i] == 1) s=max(0, s-1);
			else if(b[i] == -1) e=min(u, e+1);
			if(a[i] == 1) e--;
			else if(a[i] == -1) s++;
			if(s > e) break;
		}
		if(s <= tar && tar <= e) continue;
		else return !printf("NO\n");
	}
	printf("YES\n");
	return 0;
}
//*/

Measured memory_bytes: 2176