akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nd = Console.ReadLine().Split().Select(long.Parse).ToArray();
        int res = 0;
        for (int i = 0; i < nd[0]; i++)
        {
            var xy = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (xy[0] * xy[0] + xy[1] * xy[1] <= nd[1] * nd[1]) res++;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 46936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N; cin >> N;
    vector<pair<ll, ll> > v(N); 
    for(int i = 0; i < N; ++i){
        ll tmp;
        cin >> tmp;
        v[i] = make_pair(tmp, i);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < N; ++i){
        cout << v[i].second+1;
        if(i != N-1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

int main(){
    ll N ; cin>>N;
    vll b(N);
    REP(i, N) cin>>b[i];
    stack<ll> st;
    for(ll i=N; i>0; i--){
        ll maxj=-1;
        for(ll j=0; j< i; j++){
            if(b[j]==j+1)
                maxj = max(maxj, j);
        }
        if(maxj < 0){
            cout<<-1<<endl;return 0;
        }
        st.push(b[maxj]);
        b.erase(b.begin()+maxj);
    }
    while(!st.empty()){
        cout<< st.top()<<endl;
        st.pop();
    }

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll dp[20][550000];
ll N;
string S;

ll judge(ll x, ll y){
	if(x>y) swap(x, y);
	if(S[y-x-1]=='0'){
		return x;
	}else{
		return y;
	}
}

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

    cin >> N;
    cin >> S;
    ll M = (1ll<<N);
    vector<ll> P(M);
    REP(i, M) cin >> P[i];

    vector<ll> Q(2*M);
    REP(i, M){
    	Q[i] = P[i];
    	Q[i+M] = P[i];
    }

    REP(i, 2*M) dp[0][i] = Q[i];
    for(int i=1;i<=N;i++){
    	ll len = (1ll<<(i-1));
    	for(int j=0;j+len<2*M;j++){
    		dp[i][j] = judge(dp[i-1][j], dp[i-1][j+len]);
    	}
    }

    REP(i, M){
    	cout << dp[N][i] << endl;
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = 1;
  rep(i,n) {
    if (a[i]==0) {
      cout << 0 << endl;
      return 0;
    }
  }
    
  rep(i,n) {
    if (a[i] > INF/ans) {
      cout << -1 << endl;
      return 0;
    }
    
    ans *= a[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4056
#include <stdio.h>

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

    int first = n / 100;
    int second = (n / 10) % 10;
    int third = n % 10;

    while ( n > 0) {
        if ( first == 7) {
            puts("Yes");
            break;
        }
        else if ( second == 7) {
            puts("Yes");
            break;
        }
        else if ( third == 7) {
            puts("Yes");
            break;
        }
        else {
            puts("No");
            break;
        }
    } 
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int x,y;
    bool operator<(const node&o)const
    {
        return y>o.y;
    }
}a[100005];
int n,k,cot=0;
bool vis[100005];

stack<int>s;
int main()
{
    long long ans=0,res=0,type=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(cot<k)
        {
            if(!vis[a[i].x])
            {
                vis[a[i].x]=true;
                type++;
            }
            else s.push(a[i].y);
            res+=a[i].y;
            cot++;
            ans=max(ans,res+type*type);
        }
        else
        {
            if(s.empty())break;
            if(vis[a[i].x]) continue;
            vis[a[i].x]=true;
            type++;
            res+=a[i].y;
            res-=s.top();s.pop();
            ans=max(ans,res+type*type);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,max_num = -1000001,min_num = 1000001,tmp;
	long long int sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		sum += tmp;
		max_num = max(max_num,tmp);
		min_num = min(min_num,tmp);
	}
	printf("%d %d %lld\n",min_num,max_num,sum);
}


Measured memory_bytes: 2736
# 4
# 2 3 6 2019
# 2
# 1 3 4

N = int(input())
X = list(map(int, input().split()))  # 初期配置のリスト
M = int(input())
A = list(map(int, input().split()))  # 操作のリスト

# Aを読み込み、Nを操作
for j in A:
	if X[j - 1] == 2019:
		pass
	elif j <= N - 1:
		if X[j - 1] + 1 == X[j]:
			pass
		else:
			X[j - 1] = X[j - 1] + 1
	else:
		X[j - 1] = X[j - 1] + 1

# 結果出力
for k in X:
	print(k)



Measured memory_bytes: 5604
n=int(input())
arr=[]
for i in range(n):
    a,b,c=map(int,input().split())
    arr.append([a,b,c])
dp0=[0]*n
dp1=[0]*n
dp2=[0]*n
dp0[0]=arr[0][0]
dp1[0]=arr[0][1]
dp2[0]=arr[0][2]
for i in range(1,n):
    dp0[i]=arr[i][0]+max(dp1[i-1],dp2[i-1])
    dp1[i]=arr[i][1]+max(dp0[i-1],dp2[i-1])
    dp2[i]=arr[i][2]+max(dp0[i-1],dp1[i-1])
print(max(dp0[n-1],dp1[n-1],dp2[n-1]))


Measured memory_bytes: 65368
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N; cin >> N;
	string s1, s2; cin >> s1 >> s2;
//	N = 52;
//	s1 = "RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn";
//	s2 = "RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn";

	ll ret = 0;
	
	for (int i = 0; i < N; i++)
	{
		if (i == 0)
		{
			if (s1[i] == s2[i])
			{
				ret = 3;
			}
			else
			{
				ret = 6;
				i += 1;
			}
			continue;
		}

		if (s1[i] == s2[i])
		{
			if (s1[i - 1] == s2[i - 1])
			{
				ret *= 2;
			}
			else
			{
				ret *= 1;
			}
		}
		else
		{
			if (s1[i - 1] == s2[i - 1])
			{
				ret *= 2;
			}
			else
			{
				ret *= 3;
			}
			i += 1;
		}
		ret %= mod;
	}
	cout << ret;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int L = sc.nextInt();

		int gouke = 0;
		int abs = Integer.MAX_VALUE;
		int absNum = 0;
		for (int i = 0; i < N; i++) {
			gouke += L + i;
			if (abs > Math.abs(L + i)) {
				abs = Math.abs(L + i);
				absNum = L + i;
			}
		}
		System.out.println(gouke - absNum);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  string s; cin >> s;
  ll ans = 0;
  if (s == "SUN") ans = 7;
  if (s == "MON") ans = 6;
  if (s == "TUE") ans = 5;
  if (s == "WED") ans = 4;
  if (s == "THU") ans = 3;
  if (s == "FRI") ans = 2;
  if (s == "SAT") ans = 1;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[][] a = new long[n][n];
		boolean[][] disable = new boolean[n][n];
		long ans = 0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				a[i][j] = in.nextLong();
				ans += a[i][j];
			}
		}
		ans /= 2;
		boolean fake = false;
		for(int k=0;k<n;k++) {
			for(int i=0;i<n;i++) {
				for(int j=i+1;j<n;j++) {
					if(i==k || j==k) continue;
					if(a[i][j]==a[i][k]+a[k][j]&&!disable[i][j]) {
						ans -= a[i][j];
						disable[i][j] = true;
					}
					if(a[i][j]>a[i][k]+a[k][j]) fake = true;
				}
			}
		}
		System.out.println(fake?-1:ans);
		in.close();
	}

}


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

int main() {
  int a,b,c,d,N;
  a=0;
  b=0;
  c=0;
  d=0;
  cin >> N;
  vector<string> s(N);
  for (int i=0;i<N;i++) {
    cin >> s.at(i);
    if (s.at(i)=="AC") {
      a++;
    }
    if (s.at(i)=="WA") {
      b++;
    }
    if (s.at(i)=="TLE") {
      c++;
    }
    if (s.at(i)=="RE") {
      d++;
    }
  }
  cout << "AC " << "x " << a  << endl;
  cout << "WA " << "x " << b << endl;
  cout << "TLE " << "x " << c << endl;
  cout << "RE " << "x " << d << endl;
}

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

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  
  if(A*N > B) cout << B << endl;
  else cout << A*N << endl;
}

Measured memory_bytes: 256
h, w = map(int,input().split())
maero='.'*w
maekai=[999]*w
maekai[0]=0
allkai=[]
for i in range(h):
    root=input()
    nowkai=[]
    for j in range(w):
        if root[j]=='.':
            if j==0:
                nowkai.append(maekai[0])
            else:
                nowkai.append(min(nowkai[-1], maekai[j]))
        else:
            if j==0:
                if maero[j]=='.':
                    nowkai.append(maekai[0]+1)
                else:
                    nowkai.append(maekai[0])
            else:
                if root[j-1]=='.':
                    koho1=nowkai[-1]+1
                else:
                    koho1=nowkai[-1]
                if maero[j]=='.':
                    koho2=maekai[j]+1
                else:
                    koho2=maekai[j]
                #print(koho1, koho2)
                nowkai.append(min(koho1, koho2))
    maero=root
    allkai.append(nowkai)
    maekai=nowkai

#for ak in allkai:
    #print(ak)
print(allkai[-1][-1])

Measured memory_bytes: 41328
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		double W = sc.nextInt();
		int[] w = new int[N];
		int[] v = new int[N];
		double ans = 0;
		for (int i = 0; i < N; ++i) {
			w[i] = Integer.parseInt(sc.next());
			v[i] = Integer.parseInt(sc.next());
			if (w[i] <= 0 && v[i] >= 0) {
				ans += v[i];
				W -= w[i];
			}
		}
		ArrayList<Product> add = new ArrayList<Product>();
		ArrayList<Product> sub = new ArrayList<Product>();
		for (int i = 0; i < N; ++i) {
			if (w[i] > 0 && v[i] > 0) {
				add.add(new Product(w[i], v[i]));
			} else if (w[i] < 0 && v[i] < 0) {
				sub.add(new Product(w[i], v[i]));
			}
		}
		Collections.sort(add);
		Collections.sort(sub);
		int addI = add.size() - 1;
		double addX = 1.0;
		int subI = 0;
		double subX = 1.0;
		while (addI >= 0) {
//			System.out.println(W + " " + ans + " " + addI + " " + addX + " " + subI + " " + subX);
			double needW = add.get(addI).w * addX;
			if (W == 0) {
				if (subI >= sub.size() || add.get(addI).e() < sub.get(subI).e()) break;
				double feedW = Math.abs(sub.get(subI).w) * subX;
				if (feedW < needW) {
					W += feedW;
					ans += sub.get(subI).v * subX;
					++subI;
					subX = 1.0;
				} else {
					double difX = needW / Math.abs(sub.get(subI).w);
					W = needW;
					ans += sub.get(subI).v * difX;
					subX -= difX;
				}
//				System.out.println("  " + W + " " + ans + " " + addI + " " + addX + " " + subI + " " + subX);
			}
			if (needW > W) {
				ans += add.get(addI).e() * W;
				addX -= W / add.get(addI).w;
				W = 0;
			} else {
				ans += add.get(addI).e() * needW;
				W -= needW;
				--addI;
				addX = 1.0;
			}
		}
		System.out.println(new BigDecimal(ans).toPlainString());
	}

	static class Product implements Comparable<Product> {
		int w, v;

		Product(int w, int v) {
			this.w = w;
			this.v = v;
		}

		double e() {
			return 1.0 * this.v / this.w;
		}

		public int compareTo(Product o) {
			return this.v * o.w - this.w * o.v;
		}
	}

}

Measured memory_bytes: 13000
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 200005;
const ll mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie(0);
    int k, n, a[N], ans = 1e9;
    cin >> k >> n;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
    }
    sort (a+1, a+1+n);
    a[n+1] = 0;
    for (int i=1; i<=n; i++) {
        int res = 0;
        res = (a[i]-a[1]);
        if (i != n) res += a[1]+k-a[i+1];
        ans = min(ans, res);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
h, w = map(int, input().split())
s = [[] for _ in range(h)]

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

cnt_ver = [[0] * w for _ in range(h)]
cnt_hor = [[0] * w for _ in range(h)]

# check vertical
for i in range(w):
    for j in range(h):
        if s[j][i] == "#":
            cnt_ver[j][i] = 0
        elif j - 1 < 0 or s[j - 1][i] == "#":
            cnt_ver[j][i] = 1
        else:
            cnt_ver[j][i] = cnt_ver[j - 1][i] + 1

for i in range(w):
    for j in range(h - 1, -1, -1):
        if s[j][i] == "#":
            continue
        elif j + 1 < h and cnt_ver[j + 1][i] != 0:
            cnt_ver[j][i] = cnt_ver[j + 1][i]

# check horizontal
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            cnt_hor[i][j] = 0
        elif j - 1 < 0 or s[i][j - 1] == "#":
            cnt_hor[i][j] = 1
        else:
            cnt_hor[i][j] = cnt_hor[i][j - 1] + 1

for i in range(h):
    for j in range(w - 1, -1, -1):
        if s[i][j] == "#":
            continue
        elif j + 1 < w and cnt_hor[i][j + 1] != 0:
            cnt_hor[i][j] = cnt_hor[i][j + 1]

ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_hor[i][j] + cnt_ver[i][j] - 1)

print(ans)


Measured memory_bytes: 142840
#include <bits/stdc++.h>
using namespace std;
using dll=double long;
const int N=3005;
int n;
dll c[N];
dll memo[N][N];
bool vis[N][N];
dll dp(int pos,int ca){
    if(pos==n){
        if(ca*2>n) return 1;
        else return 0;
    }
    if(vis[pos][ca]) return memo[pos][ca];
    dll ans;
    ans=c[pos]*dp(pos+1,ca+1) + (1-c[pos])*dp(pos+1,ca);
    vis[pos][ca]=true;
    return  memo[pos][ca]=ans;
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    cout<<setprecision(10)<<dp(0,0)<<'\n';
	return 0;
}


Measured memory_bytes: 94688
#include <bits/stdc++.h>
using namespace std;
int n,a[1<<18],b[1<<18],ans,x,y;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<1<<n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i++){
        for(int j=0;j<1<<n;j++){
            if(j&(1<<i)){
                x=a[j^(1<<i)],y=b[j^(1<<i)];
                if(a[j]<x)swap(a[j],x);
                b[j]=max(b[j],max(x,y));
            }
        }
    }
    for(int i=1;i<1<<n;i++){
        ans=max(ans,a[i]+b[i]);
        printf("%d\n",ans);
    }
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector< vector<bool> > likes(N, vector<bool>(M, false));
  int K, A;
  for (int i = 0; i < N; ++i) {
    cin >> K;
    for (int y = 0; y < K; ++y) {
      cin >> A;
      likes[i][A - 1] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < M; ++i) {
    bool ok = true;
    for (int y = 0; y < N; ++y) {
      if (!likes[y][i]) {
	ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

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

	ll n = 0, x = 0, ans = 0;
	cin >> n >> x;
	int town[100001] = {};
	int sa[100000] = {};
	ll gcd(ll a, ll b);
	rep(i, n) {
		cin >> town[i];
	}
	town[n] = x;
	sort(town, town + n + 1);
	for (int i = 1; i <= n + 1; i++) {
		sa[i - 1] = town[i] - town[i - 1];
	}
	ans = sa[0];
	for (int i = 1; i < n; i++) {
		ans = gcd(ans, sa[i]);
	}
	cout << ans << endl;

	return 0;
}
ll gcd(ll a, ll b) {
	ll tmp,r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}


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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int N;
  	cin >> N;
  	int ai;
  	map<int, int> mp{};
  	Fr(i, 0, N) {
      cin >> ai;
      mp[ai]++;
    }
  	int mx = 0;
  	for(const auto &it: mp) mx = max(mx, it.Sd);
  	cout << (mx==1 ? "YES" : "NO") << endl;

}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N, K;

signed main()
{
	cin >> N >> K;
	if (N == K) {
		cout << 1 << endl;
		return 0;
	}
	vi a(N);
	int one = -1;
	rep(i, N){
		cin>>a[i];
		if (a[i] == 1) one = i;
	}

	int mn = N + 100;

	rep(l, N) {
		int r = l + K - 1;
		// [l, r]
		if (l <= one and one <= r and r <= N - 1) {
			int cur = 1;
			cur += (l + K - 2) / (K - 1);
			cur += (N - (r + 1) + K - 2)/ (K - 1);

			chmin(mn, cur);
		}
	}

	cout << mn << endl;
}


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

static const int NMAX = 100009;
int N,x,a[NMAX];

int main(){
  cin >> N >> x;
  for(int i=0;i<N;i++) cin >> a[i];

  ll ans = 0;
  for(int i=0;i<N-1;i++){
    if(a[i]+a[i+1] <= x) continue;
    if(a[i]+a[i+1] > x){
      ll sum = a[i]+a[i+1];
      if(sum-a[i+1] <=x){
        ans += a[i+1] - (x - a[i]);
        a[i+1] = x - a[i];
      }
      else{
        ans += a[i+1] + (a[i]-x);
        a[i] = x;
        a[i+1] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
/*
 * main.c
 *
 *  Created on: 2019/04/06
 *      Author: family
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

unsigned long long int limit[5] = {0};

int main()
{
    unsigned long long int N;
    int i = 0;
    unsigned long long int ans = 0;
    unsigned long long int temp = 0;
    scanf("%llu", &N);
    for(i = 0; i < 5; i++) {
        scanf("%llu", &limit[i]);
    }
    i = 0;
    for( i = 0; i < 5; i++) {
        temp = N/limit[i];
        if(N%limit[i] != 0) {
            temp++;
        }
        if(temp > ans) {
            ans = temp;
        }
    }

    printf("%llu\n",ans+4);
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  swap(n, m);
  vector<int> f(n, 0);
  for (int i = 0; i < m; i++) {
  	int k;
  	cin >> k;
  	while (k--) {
  		int x;
  		cin >> x;
  		x--;
  		f[x]++;
  	}
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
  	ans += (int) (f[i] == m);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int n,m,op,ed,x,y,z,vis[100010],g[100010][2],dis[100010][2],id,first[100010],Next[400010],to[400010],w[400010],index_,ans,U[200010],V[200010],W[200010];
void add(int a,int b,int c)
{
	Next[++index_]=first[a];
	first[a]=index_;
	to[index_]=b;
	w[index_]=c;
}
int Read()
{
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return f*x;
}
void dij(int st)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++) dis[i][id]=99999999999999;
	dis[st][id]=0;
	g[st][id]=1;
	q.push(make_pair(0,st));
	while(q.size())
	{
		int u=q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=first[u];i;i=Next[i])
		{
			int v=to[i];
			if(dis[v][id]==dis[u][id]+w[i])
			{
				g[v][id]=(g[v][id]+g[u][id])%mod;
			}
			if(dis[v][id]>dis[u][id]+w[i])
			{
				dis[v][id]=dis[u][id]+w[i];
				g[v][id]=g[u][id];
				q.push(make_pair(dis[v][id],v));
			}
		}
	}
}
signed main()
{
	n=Read(),m=Read(),op=Read(),ed=Read();
	for(int i=1;i<=m;i++) U[i]=x=Read(),V[i]=y=Read(),W[i]=z=Read(),add(x,y,z),add(y,x,z);
	dij(op);
	id++;
	dij(ed);
	ans=((g[ed][0]%mod)*(g[ed][0]%mod))%mod;
	for(int i=1;i<=n;i++)
	{
		if(dis[i][0]==dis[i][1]&&dis[i][0]+dis[i][1]==dis[ed][0])
		{
			ans=ans-(((g[i][0]*g[i][1]%mod)*(g[i][0]*g[i][1]%mod))%mod);
	        ans=(ans+mod)%mod;
		}
	}
    for(int i=1;i<=m;i++)
    {
    	int u=U[i],v=V[i],d=W[i];
    	if(dis[u][0]+d+dis[v][1]==dis[ed][0]&&dis[u][0]+d>dis[v][1]&&dis[v][1]+d>dis[u][0])
		ans=ans-(((g[u][0]*g[v][1]%mod)*(g[v][1]*g[u][0]%mod))%mod),ans=(ans+mod)%mod;
        u=V[i],v=U[i],d=W[i];
    	if(dis[u][0]+d+dis[v][1]==dis[ed][0]&&dis[u][0]+d>dis[v][1]&&dis[v][1]+d>dis[u][0])
		ans=ans-(((g[u][0]*g[v][1]%mod)*(g[v][1]*g[u][0]%mod))%mod),ans=(ans+mod)%mod;
    }
	cout<<ans;
	return 0;
}

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

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

    vector<int> C(N-1), S(N-1), F(N-1);
    for( int i = 0; i < N-1; ++i )
        cin >> C[i] >> S[i] >> F[i];


    int ans = 0;
    for( int i = 0; i < N; ++i ){
        for( int j = i; j < N-1; ++j ){
            if( ans < S[j] ) ans = S[j];
            if( ans%F[j] != 0 ) ans += F[j] - ans%F[j];
            ans += C[j];
            // cout << N << "(station#" << j << "): " << ans << endl;
        }
        cout << ans << endl;
        ans = 0;
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int upper2digit = x / 100;
        int lower2digit = x % 100;

        if (isMonth(upper2digit) && isMonth(lower2digit)) {
            System.out.println("AMBIGUOUS");
            return;
        }

        if (isMonth(upper2digit)) {
            System.out.println("MMYY");
            return;
        }

        if (isMonth(lower2digit)) {
            System.out.println("YYMM");
            return;
        }

        System.out.println("NA");
    }

    public static boolean isMonth(int x) {
        return 0 < x && x < 13;
    }
}


Measured memory_bytes: 21844
def f(a, b)
  result = 0
  until a == b
    result += (a & 1) + (b & 1)
    a = (a + 1) >> 1
    b = b >> 1
  end
  result
end
 
n = gets.to_i
n.times do
  s, d = gets.split.map!(&:to_i)
  puts f(s, d)
end

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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> L(2 * N);
  rep(i, 2 * N) { cin >> L[i]; }
  sort(L.begin(), L.end());
  int answer = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    answer += L[i];
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		for(int i=0;i<n;i++){
			String s = sc.next();
			int count = 0;
			int a, b, max;
			
			while(s.length()>1){
				max = 0;
				for(int j=1;j<s.length();j++){
					a = Integer.valueOf(s.substring(0,j));
					b = Integer.valueOf(s.substring(j,s.length()));
					max = Math.max(max, a*b);
				}
				s = Integer.toString(max);
				count++;
			}
			System.out.println(count);
		}
	}	
}

Measured memory_bytes: 23152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long wa = 11;
        long ans = (x / wa) * 2; // 必要回数

        long rem = x % wa;
        if (rem > 6) {
            ans += 2;
        } else if (rem > 0) {
            ans += 1;

        }
        System.out.println(ans);

        sc.close();
    }
}


Measured memory_bytes: 23252
#include <stdio.h>
int main()
{
	int n,i;
	scanf("%i",&n);
	for(i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			if(i*j==n)
			{
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}


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

int main() {
  const int INF = 1e9;

  int N;
  cin >> N;
  vector<int> T(N - 1);
  for(auto& i: T) cin >> i;

  vector<vector<int>> cur(N/2 + 1, vector<int>(2, INF));
  cur[1][0] = 0;
  cur[0][1] = 0;
  for(auto t: T) {
    vector<vector<int>> nex(N/2 + 1, vector<int>(2, INF));
    for(int j = 0; j <= N/2; ++j) {
      nex[j][1] = min(nex[j][1], cur[j][1]);
      nex[j][1] = min(nex[j][1], cur[j][0] + t);
      if(j == 0) continue;
      nex[j][0] = min(nex[j][0], cur[j - 1][1] + t);
      nex[j][0] = min(nex[j][0], cur[j - 1][0]);
    }
    cur = nex;
  }

  cout << min(cur[N/2][0], cur[N/2][1]) << endl;
}

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

int main()
{
	int n;cin>>n;
    vector<int> a(n+1, 0);
    vector<int> b(n+1, 0);
    for(int i = 1; i <= n; i++) cin>>a[i];
    for(int i = n; i > n/2; i--){
        if(a[i] == 1) b[i] = 1;        
    }
    for(int i = n/2; i > 0; i--){
        int c = 0;
        for(int j = 2*i; j <= n; j += i) c += b[j];
        b[i] = (a[i] + c) % 2;
    }
    int num = 0;
    for(int i = 1; i <= n; i++) num += b[i];
    cout << num << endl;
    for(int i = 1; i <= n; i++) {
        if(b[i] > 0) cout << i << " ";
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    int n;
    cin>>n;
    int A[n+1];
    int DP[n+1]={};
    rep(i,1,n) cin>>A[i];
    DP[2]=abs(A[2]-A[1]);
    rep(i,3,n) DP[i]=min((DP[i-1]+abs(A[i]-A[i-1])),(DP[i-2]+abs(A[i]-A[i-2])));
    cout<<DP[n];
}   

Measured memory_bytes: 1792
import numpy as np
import math

a,b,x = map(int,input().split())
taiseki = a*a*b
mizu_height = x / (a*a)
parcent = x/taiseki

if x/taiseki <= 0.5:
    menseki = mizu_height*a
    a = 2 * menseki / b
    #print(a)
    teihen = np.sqrt(a**2+b**2)
    #print(teihen)
    height = 2*menseki/teihen
    #print(height/b)
    print(90-math.degrees(math.asin(height/b)))

else:
    menseki = mizu_height * a
    daikei_hen = 2*menseki/a - b

    sankaku_b = b - daikei_hen

    sankaku_menseki = a*sankaku_b/2
    daikei_menseki = menseki - sankaku_menseki

    sankaku_teihen = np.sqrt(a**2+sankaku_b**2)
    sankaku_height = 2*sankaku_menseki/sankaku_teihen

    daikei_height = daikei_menseki/sankaku_teihen

    height = daikei_height + sankaku_height

    print(90-math.degrees(math.asin(height/b)))


Measured memory_bytes: 13004
#include <cstdio>
#include <cstring>

const int MAXL = 1e4, MOD = 998244353;
int n, sur, bal, f[MAXL + 5][MAXL + 5];
int fac[MAXL + 5], ifac[MAXL + 5];
char A[MAXL + 5], B[MAXL + 5];

inline void addeq ( int& a, const int b ) { if ( ( a += b ) >= MOD ) a -= MOD; }
inline int mul ( long long a, const int b ) { return ( a *= b ) < MOD ? a : a % MOD; }

inline int qkpow ( int a, int b ) {
	int ret = 1;
	for ( ; b; a = 1ll * a * a % MOD, b >>= 1 ) ret = 1ll * ret * ( b & 1 ? a : 1 ) % MOD;
	return ret;
}

inline void init () {
	fac[0] = 1;
	for ( int i = 1; i <= n; ++ i ) fac[i] = mul ( i, fac[i - 1] );
	ifac[n] = qkpow ( fac[n], MOD - 2 );
	for ( int i = n - 1; ~ i; -- i ) ifac[i] = mul ( i + 1, ifac[i + 1] );
}

inline int comb ( const int n, const int m ) {
	return n < m ? 0 : mul ( fac[n], mul ( ifac[m], ifac[n - m] ) );
}

int main () {
	scanf ( "%s %s", A + 1, B + 1 );
	n = strlen ( A + 1 ), init ();
	for ( int i = 1; i <= n; ++ i ) {
		if ( A[i] ^ '0' && B[i] ^ '0' ) ++ bal;
		else if ( A[i] > B[i] ) ++ sur;
	}
	f[0][0] = 1;
	for ( int i = 0; i <= bal; ++ i ) {
		for ( int j = 0, cur; j <= sur; ++ j ) {
			if ( ! ( cur = f[i][j] ) ) continue;
			addeq ( f[i + 1][j], mul ( cur, mul ( i + 1, j ) ) );
			addeq ( f[i][j + 1], mul ( cur, mul ( j + 1, j + 1 ) ) );
		}
	}
	int ans = 0;
	for ( int i = 0; i <= bal; ++ i ) {
		int fre = bal - i;
		int self = mul ( mul ( fac[fre], fac[fre] ),
			mul ( comb ( bal + sur, fre ), comb ( bal, fre ) ) );
		addeq ( ans, mul ( f[i][sur], self ) );
	}
	printf ( "%d\n", ans );
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

typedef long long ll;
const long long mod = 1000000007;



 
const int mx = 3005;

ll dp[mx][mx];

int main(){
   int n;

   cin>>n;

   int a[n];

   int i,j , k;

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

   for(int l = n-1;l >= 0;l--){
       for(int r = l;r  < n;r++){
           if(l == r)
            dp[l][r] = a[l];
           else{
               dp[l][r] = max(a[l]-dp[l+1][r], a[r]-dp[l][r-1]);
           } 
       }
   }
   cout<<dp[0][n-1];
} 


Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    stack<int> sk;
    int a;
    while (~scanf("%d", &a)){
        if (a == 0){
            cout << sk.top() << endl;
            sk.pop();
        }else{
            sk.push(a);
        }
    }

    return 0;
}

Measured memory_bytes: 3056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();

		char[][] list = new char[h][w];

		for(int i = 0; i < h; i++) {
			String s = sc.next();
			list[i] = s.toCharArray();
		}

		sc.close();


		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {

				if(list[i][j] == '#') {
					continue;
				}

				int c = 0;

				if(i > 0) {
					if(j > 0) {
						c += isBomb(list[i-1][j-1]);
					}
					c += isBomb(list[i-1][j]);
					if(j < w-1) {
						c += isBomb(list[i-1][j+1]);
					}
				}

				if(j > 0) {
					c += isBomb(list[i][j-1]);
				}
				c += isBomb(list[i][j]);
				if(j < w-1) {
					c += isBomb(list[i][j+1]);
				}

				if(i < h-1) {
					if(j > 0) {
						c += isBomb(list[i+1][j-1]);
					}
					c += isBomb(list[i+1][j]);
					if(j < w-1) {
						c += isBomb(list[i+1][j+1]);
					}
				}

				list[i][j] = Character.forDigit(c,  10);

			}
		}

		for(int i = 0; i < h; i++) {
			System.out.println(list[i]);
		}

	}

	private static int isBomb(char c) {
		if(c == '#') {
			return 1;
		} else {
			return 0;
		}
	}

}


Measured memory_bytes: 23380
#include<stdio.h>

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

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

    int ans = 0;
    for(int i=0; i<n; i++){
        int add_flag = 1;
        for(int j=0; j<i; j++){
            if(H[i] < H[j]){
                add_flag = 0;
            }
        }
        if(add_flag){
            ans++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >>a >>b;
  int c=1;
  if(a<b){
    c=0;
  }
  do {
    a=a/b;
    c++;
  } while(a/b > 0);
  if(a%b==0){

  }
  cout <<c;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

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

int main() {
    int a;
    string input;
    cin >> a;
    cin >> input;
    int bestAns;
    int ans = count(input.begin(), input.end(), 'E');
    if (input[0] == 'E') {
        ans--;
    }
    bestAns = ans;
    char current;
    char previous = input[0];
    for (int i = 1; i < a; i++) {
        current = input[i];
        if (previous == 'W') {
            ans++;
        }
        if (current == 'E') {
            ans--;
        }
        previous = current;
        if (bestAns > ans) {
            bestAns = ans;
        }
    }
    cout << bestAns;
    return 0;
}

Measured memory_bytes: 900
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}


*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;
 
int main() {
	// 入力
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    ans = A + B;
    if (A-B>ans) ans = A - B;
    if (A*B>ans) ans = A* B;
    
	//出力
    cout << ans << endl;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

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

void solve(istream& cin, ostream& cout) {
  int x;
  cin >> x;
  if (360 % x == 0) {
    cout << 360 / x << endl;
    return;
  }
  int i = 2;
  while (true) {
    if ((360 * i) % x == 0) {
      cout << 360 * i / x << endl;
      return;
    }
    i++;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3652
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n,m;cin>>n>>m;

  vector<pii> C;
  vvi x(m);
  rep(i, n){
    int a,b;cin>>a>>b;
    if (m-a>=0){
      C.pb(mp(m-a,b));
      x[m-a].pb(b);
    }
  }
  dump(C);
  dump(x);

  int ans = 0;
  multiset<int> ms;
  rrep(i, m){
    each(el, x[i]){
      ms.insert(el);
    }
    if (sz(ms)>0) {
      auto it = ms.end();
      --it;
      ans += *it;
      ms.erase(it);
    }
    dump(i, ans);
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    vector<vector<int>> vec(3, vector<int>(3));
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> vec[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> A(N);

    rep(i, N)
    {
        cin >> A[i];
    }
    rep(i, N)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (A[i] == vec[j][k])
                {
                    vec[j][k] = 0;
                }
            }
        }
    }
    bool ok = false;
    if (vec[0][0] == vec[0][1] && vec[0][1] == vec[0][2])
    {
        ok = true;
    }
    if (vec[1][0] == vec[1][1] && vec[1][1] == vec[1][2])
    {
        ok = true;
    }
    if (vec[2][0] == vec[2][1] && vec[2][1] == vec[2][2])
    {
        ok = true;
    }
    if (vec[0][0] == vec[1][0] && vec[1][0] == vec[2][0])
    {
        ok = true;
    }
    if (vec[0][1] == vec[1][1] && vec[1][1] == vec[2][1])
    {
        ok = true;
    }
    if (vec[0][2] == vec[1][2] && vec[1][2] == vec[2][2])
    {
        ok = true;
    }
    if (vec[0][0] == vec[1][1] && vec[1][1] == vec[2][2])
    {
        ok = true;
    }
    if (vec[0][2] == vec[1][1] && vec[1][1] == vec[2][0])
    {
        ok = true;
    }

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


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int q = a+b;
    int r = q * c;
    int s = r / 2;
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
//#include <iostream>
using namespace std;
 
const int INF = 0x3f3f3f3f;
const int MAXN = 100005;
 
int n;
int k;

 
int A[MAXN];
int abs(int x){
	if(x < 0) return -x;
	else return x;
}
int main(){
	scanf("%d%d",&n,&k);
	A[0] = 0; 
	for(int i = 1;i <= n;i++){
		scanf("%d",&A[i]);	
	}
	sort(A,A+n+1);
	int p;
	for(int i = 0;i <= n;i++){
		if(A[i] == 0){
			p = i;
			break;
		}	
	}
	int ans = INF;
	for(int i = p;i <= n;i++){
		if(i - k >= 0) ans = min(ans,min(abs(A[i]*2) + abs(A[i - k]),abs(A[i]) + abs(A[i - k])*2));
	}//没有包括全在右的情况 
	//printf("%d",)
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
import java.io.*;
class Que {
   int queStart;
   int queTail;
   int procTime;
   String[] arry;
   int elapsedTime;
   int max;
    public Que(int procTime,  int maxLen) {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    }
    public boolean isEmpty() {
        return queStart == queTail;
    }
    public boolean isFull() {
        return queStart == (queTail+1) % max;
    }
    public void enqueue (String arg){
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    }
    public String dequeue() {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    }
    public void eval(Que que){
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    }
}

class Main {
    public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    }
}
        



Measured memory_bytes: 72456
#include <iostream>
#include <vector>
 using namespace std;
int main() {
    int  n;
    cin >> n; 
    vector<vector<int> >arr(n, vector<int>(3));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            cin >> arr[i][j];
        }
    }
    vector<vector<int>> DP(n + 1, vector<int>(3));
    DP[0][0] = arr[0][0];
    DP[0][1] = arr[0][1];
    DP[0][2] = arr[0][2];
    for (int i = 1; i < n; ++i)
    {
        DP[i][0] = arr[i][0] + max(DP[i - 1][1], DP[i - 1][2]);
        DP[i][1] = arr[i][1] + max(DP[i - 1][0], DP[i - 1][2]);
        DP[i][2] = arr[i][2] + max(DP[i - 1][0], DP[i - 1][1]);
    }
 
    cout << max(max(DP[n - 1][0], DP[n - 1][1]), DP[n - 1][2]) << "\n";
    return 0;
}

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	if(n%10==7||n/10%10==7||n/100%10==7) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl

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

int main(){
  ll A, B; cin >> A >> B;
  ll res = 1;
  ll g = gcd(A, B);

  for(ll i = 2; i*i<=g; i++){
    bool ok = false;
    while(g % i == 0){
      ok = true;
      g /= i;
    }
    res += ok;
  }
  res += (g > 1);
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>

#define rep(i,m,n) for(unsigned long long int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll =long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 9 || b > 9)cout << -1 << '\n';
	else cout << a*b << '\n';

	return 0;
}

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

char s[200005];
long long n,now = 0,ans = 0;

int main() {
	scanf("%s",s);
  	n = strlen(s);
  	for(int i=0;i<n;i++) {
    	if(s[i]=='W') ans+=i - now++;
    }
  	printf("%lld\n",ans);
  	return 0;
}

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

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

const ll INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ab(n);
  rep(i, n) cin >> ab[i].second >> ab[i].first;
  sort(ab.begin(), ab.end());
  vector<vector<ll>> dp(1010, vector<ll>(1010, INF));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      chmin(dp[i + 1][j], dp[i][j]);
      if (dp[i][j] + ab[i].second <= ab[i].first) {
        chmin(dp[i + 1][j + 1], dp[i][j] + ab[i].second);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[n][i] < INF) ans = i;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 10808