akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

char S[60] = {'Z',};

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

    rep(i, N) cin >> S[i];
    int count = 0;
    rep(i,N-2) {
        if (S[i]=='A') {
            if (S[i+1]=='B' && S[i+2]=='C') {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    // ll n, a, b;
    // cin>>n>>a>>b;

    // ll ab= a + b;
    // ll ans;
    // if(n/ab>0) ans = (n/ab)*a + n%ab;
    // else if(n<a) ans = n;
    // else ans = a;
    // if(a==0 && b==0) ans = 0;
    // //cout<<n/ab<<" "<<n<<a<<n%ab<<endl;
    // cout<<ans<<endl;
    // return 0;

    int a, b;
    cin>>a>>b;

    for(int x=1;x<=1000;x++){
        if(x*8/100 == a && x/10 == b){
            cout<<x<<endl;
            return 0;
        }
    }

        cout<<"-1"<<endl;
        return 0;
    

}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
struct UnionFind {
  vector<long long> data;
  UnionFind(long long size) : data(size, -1) { }
  bool unionSet(long long x, long long y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(long long x, long long y) {
    return root(x) == root(y);
  }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(long long x) {
    return -data[root(x)];
  }
};

const ll MAX_N = 50, MAX_M = (MAX_N * MAX_N) / 2;
ll N, M;
Pii e[MAX_M];

int main(){
   cin >> N >> M;
   REP(i, M){
      ll a, b; cin >> a >> b; a--; b--;
      e[i] = mp(a, b);
   }
   ll ans = 0;
   REP(i, M){
      UnionFind T(N);
      REP(j, M){
         if(i == j) continue;
         T.unionSet(e[j].first, e[j].second);
      }
//      cout << T.size(0) << endl;
      if(T.size(0) != N) ans ++;
   }
   cout << ans << endl;
}


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

using namespace std;
long long n;
string s[100009];
char ans[100009];
map <char, long long> mp;

bool dfs(long long idx){
  if(idx==n)return true;
  if(mp[s[idx][0]]==0 && mp[s[idx][1]]==0)return false;
  if(mp[s[idx][0]]==mp[s[idx][1]]){
    bool ret;
    mp[s[idx][0]]++;
    mp[s[idx][1]]--;
    if(dfs(idx+1)){
      ans[idx] = s[idx][0];
      return true;
    }
    mp[s[idx][0]]-=2;
    mp[s[idx][1]]+=2;
    if(dfs(idx+1)){
      ans[idx] = s[idx][1];
      return true;
    }
    mp[s[idx][0]]--;
    mp[s[idx][1]]++;
    return false;
  }
  else if(mp[s[idx][0]]>mp[s[idx][1]]){
    mp[s[idx][0]]--;
    mp[s[idx][1]]++;
    ans[idx] = s[idx][1];
    return dfs(idx+1);
  }
  else{
    mp[s[idx][0]]++;
    mp[s[idx][1]]--;
    ans[idx] = s[idx][0];
    return dfs(idx+1);
  }
}

int main(){
  long long a, b ,c;
  cin >> n >> a >> b >> c;
  for(int i=0;i<n;i++)cin >> s[i];
  mp['A'] = a;
  mp['B'] = b;
  mp['C'] = c;
  if(dfs(0)){
    cout << "Yes" << endl;
    for(int i=0;i<n;i++)cout << ans[i] << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 10020
a = [0]
a[0] = int(input())
i = 0


def f(n):
    if n % 2 == 0:
        return int(n / 2)
    elif n % 2 == 1:
        return 3 * n + 1


while (1):
    if f(a[i]) in a:
        print(i + 2)
        break
    a.append(f(a[i]))
    i += 1


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set<int> s;
    rep(i,3) {
        int a; cin >>a;
        s.insert(a);
    }
    if(s.size()==2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main(){
  
  char a,b,c,d;
  cin >> a >> b >> c;
  
  d = 100*a + 10*b + c;
  
  if( d%4 == 0 ){
    
    cout << "YES" << endl;
    
  }
  
  else{
    
    cout << "NO" << endl;
    
  }
  
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
  char a[10]={},b[10]={},c[10]={};
  int an=0,bn=0;
  scanf("%s %s %s",a,b,c);
  an = strlen(a);bn = strlen(b);
  if(a[an-1]==b[0] && b[bn-1]==c[0]){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s, t;
	cin>>s;
	t=s;
	reverse(t.begin(),t.end());
	for(int i = 0; i < s.length(); i++)
	{
		if(t[i]=='b') t[i]='d';
		else if(t[i]=='d') t[i]='b';
		else if(t[i]=='p') t[i]='q';
		else t[i]='p';
	}
	if(s==t)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}


Measured memory_bytes: 512
import sys;
import math;
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()

n,k = get_ints();
arr = get_array();
dp = [10**18 for i in range(n)];
dp[0]=0;
dp[1]=abs(arr[1]-arr[0]);
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[max(0,i-j)]+abs(arr[max(0,i-j)]-arr[i]),dp[i]);
#print(dp);
print(dp[n-1]);


Measured memory_bytes: 89932
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = [0]
for i in range(n):
    s.append((s[-1] + a[i] - 1) % k)

# dic = {remainder:number}
dic = {0:1}
ans = 0
if n < k:
    for i in range(1, n+1):
        if s[i] in dic:
            ans += dic[s[i]]
            dic[s[i]] += 1
        else:
            dic[s[i]] = 1

else:
    for i in range(1, k):
        if s[i] in dic:
            ans += dic[s[i]]
            dic[s[i]] += 1
        else:
            dic[s[i]] = 1

    for i in range(k, n+1):
        dic[s[i-k]] -= 1
        if s[i] in dic:
            ans += dic[s[i]]
            dic[s[i]] += 1
        else:
            dic[s[i]] = 1

print(ans)

Measured memory_bytes: 40712
#include <stdio.h>
#include <iostream>
#include <string>
#include <list>
using namespace std;
#define N 22369620
#define X 50
struct hush
{
	list <int> a;
};
int main(void)
{
	int n, sum = 0, x, f[1000000] = { 0 }, cou = 0;
	char str[7], acgt[13];
	hush H[N / X];
	scanf("%d", &n);	
	for (int i = 0; i < n; i++) {
		sum = 0;
		scanf("%s", str);
		scanf("%s", acgt);
		for (int i = 0, k = 1; acgt[i] != '\0' &&i < 12; i++, k *= 4) {
			switch (acgt[i]) {
			case 'A': x = 1; break;
			case 'C': x = 2; break;
			case 'G': x = 3; break;
			case 'T': x = 4; break;
			}
			sum += x*k;
		}
		if (str[0] == 'i') {
			H[sum / X].a.push_back(sum % X);
		}
		else {
			list<int>::iterator p = H[sum / X].a.begin();
			for (; p != H[sum / X].a.end(); ++p) {
				if ((sum % X) == *p) { f[cou] = 1; }
			}
			cou++;
		}
	}
	for (int i = 0; i < cou; i++) {
		if(f[i]) printf("yes\n");
		else printf("no\n");
	}
}

Measured memory_bytes: 31868
#include<stdio.h>

int main(void) {

	int a, b, c, dif1, dif2;

	scanf("%d%d%d", &a, &b, &c);

	dif1 = b - a;
	dif2 = c - b;

	if (dif1 == dif2) {
		printf("YES\n");
	}
	else {
		printf("NO\n"); 
	}


	return 0;

}

Measured memory_bytes: 128
import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    element = [0]*(2*length-1)
    for i in range(2*length-1):
        element[i] = 0
    return element,length

def update(k,a,element):
    k+=n-1
    element[k]+=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = element[k*2+1]+element[k*2+2]

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return 0
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return vl+vr

n,q = map(int, input().split());

element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key-1,value,element)
    else :
        print(findmin(key-1,value-1))


Measured memory_bytes: 10764
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	string n;
	cin>>n;
	ll ans=0;
	for(int i=0;i<n.size();i++)
	{
		int curr=int(n[i]-'0');
		ans+=curr;
		ans%=9;
	}

	if(ans==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
"""
D - 連結 / Connectivity
https://atcoder.jp/contests/abc049/tasks/arc065_b

"""
import sys


class DisjointSet(object):
    def __init__(self, n):
        self.rank = [0] * n
        self.p = list(range(n))
        self.size = [1] * n

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.size[self.p[x]] += self.size[self.p[y]]
            self.p[y] = self.findSet(x)
        else:
            self.size[self.p[y]] += self.size[self.p[x]]
            self.p[x] = self.findSet(y)
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


from collections import Counter

def solve(N, K, L, PQ, RS):
    r_d = DisjointSet(N+1)
    for p, q in PQ:
        r_d.unite(p, q)
    t_d = DisjointSet(N+1)
    for r, s in RS:
        t_d.unite(r, s)
    for i in range(1, N+1):
        r_d.findSet(i)
        t_d.findSet(i)

    connectivity = Counter()
    for i in range(1, N+1):
        connectivity[(r_d.p[i], t_d.p[i])] += 1
    return [connectivity[(r_d.p[i], t_d.p[i])] for i in range(1, N + 1)]


def main(args):
    N, K, L = map(int, input().split())
    PQ = [[int(i) for i in input().split()] for _ in range(K)]
    RS = [[int(i) for i in input().split()] for _ in range(L)]
    ans = solve(N, K, L, PQ, RS)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 86952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cd(int x){
	int len=0;
	while(x){
		x/=10;
		len++;
	}
	return len;
}
bool prime(ll x){
	for (int i=2;i<=sqrt(x);i++)
		if (x%i==0)return false;
	return true;
}
int main(){
	ll n;
	int i,a,b,ans=11;
	cin>>n;
	if(prime(n)){
		cout<<cd(n);
		return 0;
	}
	
	for (i=sqrt(n);i>=2;i--)
		if(n%i==0){
			a=i;b=n/i;
			//cout<<a<<" "<<b<<" "<<cd(a)<<" "<<cd(b)<<endl;
			ans=min(  max( cd(a), cd(b) ) ,ans);
			break;
		}
	cout<<ans;
	return 0;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int A[maxn];

void Work(){
	int pos;
	REP(i,1,n)if(A[i]>=i)pos=i;
	int nxt;
	REP(i,1,n)if(A[i]>=pos)nxt=i;
	if(((A[pos]-pos)&1)||((nxt-pos)&1))puts("First");
	else puts("Second");
}

void Init(){
	read(n);
	REP(i,1,n)read(A[i]);
	sort(A+1,A+n+1);
	reverse(A+1,A+n+1);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, s: "List[str]"):
    dp = [[0 for w in range(W)] for h in range(H)] # dp[h][w]はh,wに達するための回数
    if s[0][0] == '#':
        dp[0][0] = 1

    for w in range(W-1): # 0行目について
        if s[0][w+1] == '.': # 移動先が白だったら特に変わりなし
            dp[0][w+1] = dp[0][w]
        elif s[0][w] == '.' and s[0][w+1] == '#': # 移動元が白で先が黒ならば、新しく施行1回追加
            dp[0][w+1] = dp[0][w] + 1
        elif s[0][w] == '#' and s[0][w+1] == '#': # 移動元も先も黒だったとしたら、試行回数は変わらない
            dp[0][w+1] = dp[0][w]

    for h in range(H-1): # 1列目について
        if s[h+1][0] == '.':
            dp[h+1][0] = dp[h][0]
        elif s[h][0] == '.' and s[h+1][0] == '#':
            dp[h+1][0] = dp[h][0] + 1
        elif s[h][0] == '#' and s[h+1][0] == '#':
            dp[h+1][0] = dp[h][0]

    for h in range(1, H):
        for w in range(W-1):
            if s[h][w+1] == '.':
                dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
            elif s[h][w] == '.' and s[h][w+1] == '#':
                if s[h-1][w+1] == '.':
                    dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1]+1)
                elif s[h-1][w+1] == '#':
                    dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1])
            elif s[h][w] == '#' and s[h][w+1] == '#':
                if s[h-1][w+1] == '.':
                    dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]+1)
                elif s[h-1][w+1] == '#':
                    dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
    print(dp[H-1][W-1])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3312
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int num[3];
    num[0]=n/100;
    num[1]=(n-num[0]*100)/10;
    num[2]=n%10;
    for(int i=0;i<3;i++){
        if(num[i]==1) num[i]=9;
        else num[i]=1;
    }
    for(int i=0;i<3;i++){
        cout<<num[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
struct Edge{
	int to,next,w;
}e[MAXN<<3];
struct E{
	int u,v,c;
	bool operator < (const E &b)const
	{
		return c<b.c;
	}
}t[MAXN<<1];
int head[MAXN<<3],n,m,fa[MAXN],id[MAXN],sz;
bool vis[MAXN<<3];
int getan(int x)
{
	return x==fa[x]?x:fa[x]=getan(fa[x]);
}
int cnt=0;
inline void insert(int u,int v,int w)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt,e[cnt].w=w;
}
inline void work(int l,int r)
{
	for(int i=l;i<=r;++i){
		vis[t[i].u]=vis[t[i].v]=id[t[i].u]=id[t[i].v]=0;
		fa[t[i].u]=t[i].u;
		fa[t[i].v]=t[i].v;
	}
	for(int i=l,x,y;i<=r;++i)
		x=getan(t[i].u),y=getan(t[i].v),fa[x]=y;
	for(int i=l,x,y;i<=r;++i){
		x=getan(t[i].u),y=getan(t[i].v);
		if(!vis[t[i].u]){
			if(!id[x])id[x]=++sz;
			insert(t[i].u,id[x],0);
			insert(id[x],t[i].u,1);
			vis[t[i].u]=1;
		}
		if(!vis[t[i].v]){
			if(!id[y])id[y]=++sz;
			insert(t[i].v,id[y],0);
			insert(id[y],t[i].v,1);
			vis[t[i].v]=1;
		}
	}
}
struct Node{
	int x,v;
	bool operator < (const Node &b)const
	{
		return v>b.v;
	}
};
priority_queue<Node>q;
int d[MAXN<<3];
inline void dij()
{
	memset(vis,0,sizeof(vis));
	memset(d,0x3f,sizeof(d));
	d[1]=0;
	q.push((Node){1,0});
	while(!q.empty()){
		Node x=q.top();
		q.pop();
		int u=x.x;
		if(vis[u])continue;
		vis[u]=true;
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			if(d[v]>d[u]+e[i].w){
				d[v]=d[u]+e[i].w;
				q.push((Node){v,d[v]});
			}
		}
	}
	cout<<(d[n]==0x3f3f3f3f?-1:d[n])<<endl;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		scanf("%d%d%d",&t[i].u,&t[i].v,&t[i].c);
	}
	sz=n;
	sort(t+1,t+m+1);
	int p=1;
	while(p<=m){
		int r=p;
		while(t[r+1].c==t[r].c)++r;
		work(p,r);
		p=r+1;
	}
	dij();
	return 0;
}


Measured memory_bytes: 20856
#include <bits/stdc++.h>
using namespace std;
int diginum(int n,int i){
  int ans=0;
  while(n){
      n/=i;
      ans++;
  }
  return ans;
} 
int main(){
   int N,K,ans;
   cin>>N>>K;
   ans=diginum(N,K);
   cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template

ll md = 1e9 + 7;
ll fac[100010],ans;
int n,m;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    fac[0] = 1;
    for(int i=1;i<=1e5;i++){
        fac[i] = ((fac[i-1]%md) * (i%md))%md;
    }
    cin>>n>>m;

    if(abs(n-m)>1){ans=0;}
    else{
        ans = (fac[m] * fac[n])%md;
        if(n==m) ans = (ans*2)%md;
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int query = sc.nextInt();
        
        
        // to: 隣接リスト
        List<Integer>[] to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < n - 1; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            to[s].add(t);
            to[t].add(s);
        }
        
        int[] dist = new int[n];
        for (int i = 0; i < query; i++) {
            int p = sc.nextInt() - 1;
            int dis = sc.nextInt();
            dist[p] += dis;
        }
        
        boolean[] visited = new boolean[n];
        
        // 頂点0から順に、親から子へ初期値を配り最終値を求める
        Queue<Integer> que = new ArrayDeque<Integer>();
        que.add(0);
        visited[0] = true;
        while (!que.isEmpty()) {
            int p = que.poll();
            int dis = dist[p];
            
            
            for (Integer q : to[p]) {
                if (visited[q]) continue;
                dist[q] += dis;
                que.add(q);
                visited[q] = true;
            }
        }
        
        
        for (int i = 0; i < n; i++) {
            System.out.print(dist[i]);
            
            if (i != n - 1) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }
}

Measured memory_bytes: 196828
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
int n;
int main(void) {
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    rep(i,n)a[i]*=-1;
    int dp[n+1];
    rep(i,n+1)dp[i]=1<<30;
    rep(i,n){
        auto pt = upper_bound(dp,dp+n,a[i]);
        *pt=a[i];
    }
    int res=0;
    while(dp[res]!=(1<<30))res++;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func find(arr []int, n int) bool {
	for _, v := range arr {
		if v == n {
			return true
		}
	}
	return false
}

func f(n int) int {
	if n%2 == 0 {
		return n / 2
	} else {
		return 3*n + 1
	}
}

func solve(s int) int {
	hist := []int{s}
	n := s
	c := 1
	for {
		n = f(n)
		c++

		if find(hist, n) {
			return c
		}

		hist = append(hist, n)
	}
}

func main() {
	in := read()
	n, _ := strconv.Atoi(in)
	ans := solve(n)
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1e9+7;
const int INF=1001001001;

int64_t dp[105][30][30][30];
int main() {
  int N;
  cin>>N;

  for(int a=0;a<4;a++){
    for(int b=0;b<4;b++){
      for(int c=0;c<4;c++){
        if(a==0&&b==2&&c==1){continue;}
        else if(a==0&&b==1&&c==2){continue;}
        else if(a==2&&b==0&&c==1){continue;}
        else{dp[3][a][b][c]=1;}
      }
    }
  }
  
  for(int n=3;n<N;n++){
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++){
        for(int c=0;c<4;c++){
          for(int now=0;now<4;now++){
          //if(a==0&&i==2&&j==1){continue;}
          //else if(a==0&&i==1&&j==2){continue;}
          //else if(a==2&&i==0&&j==1){continue;}
            if(dp[n][a][b][c]==0){continue;}
            if(now==0&&a==2&&b==1){continue;}
            else if(now==0&&a==1&&b==2){continue;}
            else if(now==2&&a==0&&b==1){continue;}
            else if(now==0&&b==2&&c==1){continue;}
            else if(now==0&&a==2&&c==1){continue;}
            dp[n+1][now][a][b]+=dp[n][a][b][c];
            dp[n+1][now][a][b]%=mod;
          }
        }
      }
    }
  }
  int64_t cnt=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        cnt+=dp[N][i][j][k];
      }
    }
  }
  cout<<cnt%mod<<endl;
  return 0;  
}

Measured memory_bytes: 5428
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void split(string& str, vector<string>& v){
  string::size_type index_space = str.find_first_of(" ");
  if(index_space!=string::npos){
    v.emplace_back(str.substr(0,index_space));
    string s(str.substr(index_space+1));
    split(s, v);
  }else{
    v.emplace_back(str);
  }
  return;
}

int main(){
  while(true){
    string str; getline(cin,str);
    if(str=="END OF INPUT") break;
    vector<string> v;
    split(str,v);

    for(int i=0;i<v.size();++i){
      if(v[i]==",") cout<<".";
      else cout<<v[i].size();
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  cin >>A>>B;
  int y=3*A+B;
  int z=y/2;
  cout << z<< endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main()
{

  int i, j, n, A[N], flag, count = 0, tmp;

  scanf("%d", &n);

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

  flag = 1;

  while(flag){
    flag = 0;
    for(j=n-1; j>=1; j--){
      if(A[j] < A[j-1]){
	tmp = A[j];
	A[j] = A[j-1];
	A[j-1] = tmp;
	flag = 1;
	count++;
      }
    }
  }

  for(j=0; j<n-1; j++){
    printf("%d ", A[j]);
  }

  printf("%d", A[n-1]);
  printf("\n");
  printf("%d\n", count);

  return 0;

}

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

int main()
{
    int h1, w1, h2, w2;

    cin >> h1 >> w1;
    
    int a[h1][w1];
    for( int i = 0; i < h1; i++ )
        for( int j = 0; j < w1; j++ )
            cin >> a[i][j];

    bool b[h1][w1];
    for( int i = 0; i < h1; i++ )
        for( int j = 0; j < w1; j++ )
            cin >> b[i][j];

    cin >> h2 >> w2;

    bool c[h2][w2];
    for( int i = 0; i < h2; i++ )
        for( int j = 0; j < w2; j++ )
            cin >> c[i][j];

    int res = -1000000000;
    bool judge = false;
    for( int i = 0; i <= h1 - h2; i++ )
        for( int j = 0; j <= w1 - w2; j++ )
        {
            int sum = 0;
            bool issame = true;
            for( int k = i; k < i + h2; k++ )
            {
                for( int l = j; l < j + w2; l++ )
                {
                    if( b[k][l] != c[k-i][l-j] )
                    {
                        issame = false;
                        break;
                    }
                    else
                        sum += a[k][l];
                }
                if( !issame )
                    break;
            }
            if( issame && res < sum )
            {
                judge = true;
                res = sum;
            }
        }

    if( !judge )
        cout << "NA" << endl;
    if( judge )
        cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{

    string s;
    cin >> s;
    ll a = 0;
    ll ans = 0;
    rep(i, s.size() - 1)
    {
        //cerr << s[i] << " ";
        if (s[i] == 'A')
        {
            a++;
        }
        else
        {
            if (s[i] == 'B' && s[i + 1] == 'C')
            {
                ans += a;
                i++;
            }
            else
            {
                a = 0;
            }
        }
        //cerr << a << "," << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


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

int selectionSort(int A[],int N) {
	int count = 0;
	int flag;
	for (int i = 0; i < N; i++) {
		int minj = i;
		flag = 0;
		for (int j = i; j < N; j++) {
			if (A[minj] > A[j]) {
				minj = j;
				flag = 1;
			}
		}
		if (flag==1) {
			int tmp;
			tmp = A[minj];
			A[minj] = A[i];
			A[i] = tmp;
			count += 1;

		}
	}
	for (int i = 0; i < N-1; i++) {
		cout << A[i] << " ";
	}
	cout << A[N - 1];
	cout<<endl;
	return count;
}

int main() {
	int N, A[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	cout << selectionSort(A, N) << endl;
}


Measured memory_bytes: 3120
#include<iostream>
using namespace std;
int main() {
	long a[6], b[6], c[6],a2[3],b2[3],c2[3];
	for (int i = 0; i < 6; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 6; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < 6; i++) {
		cin >> c[i];
	}
	a2[0]= a[0] * 3600 + a[1] * 60 + a[2];
	b2[0] = b[0] * 3600 + b[1] * 60 + b[2];
	c2[0] = c[0] * 3600 + c[1] * 60 + c[2];
	a2[1] = a[3] * 3600 + a[4] * 60 + a[5];
	b2[1] = b[3] * 3600 + b[4] * 60 + b[5];
	c2[1] = c[3] * 3600 + c[4] * 60 + c[5];
	a2[2] = a2[1] - a2[0];
	b2[2] = b2[1] - b2[0];
	c2[2] = c2[1] - c2[0];
	a[0] = a2[2] / 3600; a2[2] = a2[2] % 3600;
	a[1] = a2[2] / 60; a2[2] = a2[2] % 60;
	a[2] = a2[2];
	b[0] = b2[2] / 3600; b2[2] = b2[2] % 3600;
	b[1] = b2[2] / 60; b2[2] = b2[2] % 60;
	b[2] = b2[2];
	c[0] = c2[2] / 3600; c2[2] = c2[2] % 3600;
	c[1] = c2[2] / 60; c2[2] = c2[2] % 60;
	c[2] = c2[2];
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	cout << b[0] << " " << b[1] << " " << b[2] << endl;
	cout << c[0] << " " << c[1] << " " << c[2] << endl;


}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=1e18;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),dp(n+1,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    dp[i+1]=dp[i]+a[i];
  }
  for(int split=2;split+1<n;split++){
    ll p=0,q=dp[split],r=0,s=dp[n];
    auto itr1 = lower_bound(dp.begin(), dp.begin()+split, dp[split]/2);
    auto itr2 = lower_bound(dp.begin()+split, dp.end(), (dp[n]+dp[split])/2);
    
    for(int d=-1;d<2;d++){
      if(max(p,q-p)>max(*(itr1+d),q-*(itr1+d))){
        p=*(itr1+d);
      }
      if(max(r-q,s-r)>max(*(itr2+d)-q,s-*(itr2+d))){
        r=*(itr2+d);
      }      
    }
    ll diff=max({s-r,r-q,q-p,p})-min({s-r,r-q,q-p,p});
    ans=min(ans,diff);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
    char par[4];
    char par2[4];
    scanf("%s",par);
    scanf("%s",par2);
   if(par[0]==par2[2]&&par[1]==par2[1]&&par[2]==par2[0])
{
    printf("YES\n");
}
  else{
    printf("NO\n");
  }
   return 0;
}



Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
	int c = sc.nextInt();
	
	int output = c - (a - b);
	
	if(output < 0)
		System.out.println(0);
	else
		System.out.println(output);
  }
	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define MAX_V 40
#define INF 1e5
using namespace std;

/*????°??????¨???(???????????£????????????????????¨) O(F|V||E|)*/

//????????¨????§???????(???????????????????????????????????????)
struct edge{int to, cap,cost,rev;};
int V;                         //????????°
vector<edge> G[MAX_V];         //??°???????????£??\???????????¨???
int dist[MAX_V];               //???????????¢
int prevv[MAX_V],preve[MAX_V]; //??´??????????????¨???

// from??????to??????????????????cap????????????cost???????????°????????????????????????
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}

//s??????t????????????f???????°??????¨???????±???????
//??????????????´???-1?????????
int min_cost_flow(int s,int t,int f){
  int res=0;
  while(f>0){
    //????????????????????????????????????,s-t????????????????±???????
    fill(dist,dist+V,INF);
    dist[s]=0;
    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
	    dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1; //????????\??????????????????
    
    //s???t?????????????????£??????????????????
    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    res += d*dist[t];
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int door[26][10],key[26][10];
int mnalpha[26],mnnum[10];

int S = 26+10,T=S+1;
void mkG(int bit){
  for(int i=0;i<MAX_V;i++)G[i].clear();

  V = 26+10+2;
  //0 -> 25 num
  //26 -> 35 alpha
  
  for(int i=0;i<26;i++)add_edge(S,i,1,0);
  for(int i=0;i<10;i++)add_edge(i+26,T,1,0);

  set<int> used;
  for(int i=0;i<26;i++)
    for(int j=0;j<10;j++){
      if((bit>>j&1)||door[i][j]==0)continue;
      used.insert(i);
    }
  
  for(int i=0;i<26;i++){
    if(used.count(i)==0) add_edge(i,T,1,0);
    else add_edge(i,T,1,mnalpha[i]);
    for(int j=0;j<10;j++){
      if(bit>>j&1)add_edge(i,26+j,1,key[i][j]-mnnum[j]);
    }
  }
}

int main(){
  int n,m;
  cin>>n;
  for(int i=0;i<n;i++){
    char ch;
    int num;
    cin>>ch>>num;
    door[ch-'A'][num] = 1;
  }

  for(int i=0;i<26;i++)for(int j=0;j<10;j++)key[i][j]=INF;
  for(int i=0;i<10;i++) mnnum[i]=INF;
  for(int i=0;i<26;i++) mnalpha[i] = INF;
  
  cin>>m;  
  for(int i=0;i<m;i++){
    char ch;
    int num,cost;
    cin>>ch>>num>>cost;
    key[ch-'A'][num] = min(key[ch-'A'][num],cost);
    mnnum[num] = min(cost,mnnum[num]);
    mnalpha[ch-'A']=min(cost,mnalpha[ch-'A']);
  }

  int ans = INF;
  for(int i=0;i<(1<<10);i++){
    mkG(i);
    int cost=0;
    for(int j=0;j<10;j++)if(i>>j&1) cost+=mnnum[j];
    int res = min_cost_flow(S,T,26);
    if(res!=-1)ans=min(ans,cost+res);
  }
  if(ans>=INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3184
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>

using namespace std;

constexpr auto DIV = 1000000007ull;

struct Int {
  int value = 0;
  Int& operator++() {
    ++this->value;
    return *this;
  }
};

int main() {
  unordered_map<char, Int> table;
  string input;
  cin >> input;
  for (auto&& val : input) {
    ++table[val];
  }
  for (auto&& val : table) {
    if (val.second.value % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
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);
        DSummerVacation solver = new DSummerVacation();
        solver.solve(1, in, out);
        out.close();
    }

    static class DSummerVacation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<ArrayList<Integer>> a = new ArrayList<>();
            for (int i = 0; i <= m; i++) {
                a.add(new ArrayList<>());
            }
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                if (x <= m)
                    a.get(x).add(y);
            }
            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
            long ans = 0;
            for (int i = 1; i <= m; i++) {
                for (int j : a.get(i)) {
                    pq.add(j);
                }
                if (!pq.isEmpty()) {
                    ans += pq.poll();
                }
            }
            out.println(ans);

        }

    }

    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());
        }

    }
}



Measured memory_bytes: 52468
#include<stdio.h>

int main(){
  int i,j;
  int x,y;
  int s;
  int ans;
  int ans1,ans2;
  int rel;
  int rel1,rel2;
  int max=-1;

  while(1){
    max=-1;
    scanf("%d %d %d",&x,&y,&s);

    if(x==0&&y==0&&s==0) break;

    for(i=1;i<s;i++){
      for(j=i;j<=s;j++){
        ans1=i*(100+x)/100;
        ans2=j*(100+x)/100;
        ans=ans1+ans2;
        if(ans==s){
          rel1=i*(100+y)/100;
          rel2=j*(100+y)/100;
          rel=rel1+rel2;
          if(max<rel) max=rel;
        }
      }
    }

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

  }

  return 0;
}

Measured memory_bytes: 600
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val s = inputs(0)
  val t = inputs(1)

  println(solve(s, t))

  def solve(s: String, t: String): String = {
    val sortedS = s.sorted
    val sortedT = t.sorted.reverse

    if(sortedS < sortedT) {
      "Yes"
    } else {
      "No"
    }
  }
}

Measured memory_bytes: 55044
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
#include<bitset>


using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから

typedef long long ll;



//英字ならture、数字ならfalse
bool isalpha(char s){
    if(('A'<=s&&s<='Z')||('a'<=s&&s<='z')){
        return 1;
    }else{
        return 0;
    }
}
//全ての文字が英字ならture、数字ならfalse
bool Isalpha(string s){
    ll n;
    bool tmp = true;
    rep(i,n){
        if(isalpha(s[i])){
            tmp = false;
        }
    }
    return tmp;
}




using Graph = vector<vector<ll>>;



//cout<<fixed<<setprecision(10);

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

#define MOD 1000000007

ll INFLL =  pow(10,9)+1;




string periodic_table[104] = {
    "None","H(1)","He(2)", //2
    "Li(3)","Be(4)","B(5)","C(6)","N(7)","O(8)","F(9)","Ne(10)", //10
    "Na(11)","Mg(12)","Al(13)","Si(14)","P(15)","S(16)","Cl(17)","Ar(18)", //18
    "K(19)","Ca(20)","Sc(21)","Ti(22)","V(23)","Cr(24)","Mn(25)","Fe(26)","Co(27)","Ni(28)","Cu(29)","Zn(30)","Ga(31)","Ge(32)","As(33)","Se(34)","Br(35)","Kr(36)", //36
    "Rb(37)","Sr(38)","Y(39)","Zr(40)","Nb(41)","Mo(42)","Tc(43)","Ru(44)","Rh(45)","Pd(46)","Ag(47)","Cd(48)","In(49)","Sn(50)","Sb(51)","Te(52)","I(53)","Xe(54)", //54
    "Cs(55)","Ba(56)","La(57)","Ce(58)","Pr(59)","Nd(60)","Pm(61)","Sm(62)","Eu(63)","Gd(64)","Tb(65)","Dy(66)","Ho(67)","Er(68)","Tm(69)","Yb(70)","Lu(71)","Hf(72)","Ta(73)","W(74)","Re(75)","Os(76)","Ir(77)","Pt(78)","Au(79)","Hg(80)","Tl(81)","Pb(82)","Bi(83)","Po(84)","At(85)","Rn(86)", //86
    "Fr(87)","Ra(88)","Ac(89)","Th(90)","Pa(91)","U(92)","Np(93)","Pu(94)","Am(95)","Cm(96)","Bk(97)","Cf(98)","Es(99)","Fm(100)","Md(101)","No(102)" //102
};

int main(){
    ll n;
    cin>>n;
    vector<ll> l(n);
    rep(i,n){
        cin>>l[i];
    }
    ll ans = 0;

    sort(l.begin(),l.end());

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]!=l[j]&&l[j]!=l[k]){
                    if(l[i]+l[j]>l[k]){
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif


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

  int min_p = N+1;
  int ans = 0;
  rep(i, N) {
    int P; cin >> P;
    if (P < min_p) {
      ++ans;
      min_p = P;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,t;
    cin>>n>>t;
    ll now,prev,res=0;
    cin>>now;
    prev=now;
    rep(i,n-1){
        cin>>now;
        res += min(t,now-prev);
        prev=now;
    }
    res +=t;
    cout<< res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,c;
cin>>a>>b>>c;
int k;
cin>>k;
int ans=0;
while(b<=a)
{
    b*=2;
    ans++;
}
while(c<=b)
{
    c*=2;
    ans++;
}
if(ans<=k)
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3632