akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

string t = "RGB";

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  auto imos = make_vec<int> (3, n+1);
  for(int i = 0; i < 3; i++){
    for(int j = n-1; j >= 0; j--){
      imos[i][j] = imos[i][j+1] + (s[j] == t[i]);
    } 
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 3; j++){
      if(s[i] == t[j]){
        for(int k = i+1; k < n; k++){
          if(s[k] == t[(j+1)%3]){
            ans += imos[(j+2)%3][k];
            int right = k + (k-i);
            if(right < n && s[right] == t[(j+2)%3]) ans--;
          }
          if(s[k] == t[(j+2)%3]){
            ans += imos[(j+1)%3][k];
            int right = k + (k-i);
            if(right < n && s[right] == t[(j+1)%3]) ans--;
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3732
n, k, q = map(int, input().split())
n_li = [k-q] * n
q_li = [int(input()) for _ in range(q)]
for i in q_li:
    n_li[i-1] += 1
for x in n_li:
    if x > 0:
        print('Yes')
    else:
        print('No')

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    if(K<=A){
        cout<<K<<endl;
    }
    else if(K<=A+B){
        cout<<A<<endl;
    }else{
        int sum=A;
        K-=(A+B);
        sum-=K;
        cout<<sum<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=1e6+6,INF=1e8;
int main(){
    int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;
    int tme=(h2-h1)*60-m1+m2;
    cout<<tme-k<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  auto cmp = [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> pq(cmp);  // value, longestLength;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    pair<int, int> n = {a, 1};
    vector<pair<int, int>> others;
    bool inserted = false;
    while (!pq.empty()) {
      if (abs(pq.top().first - a) <= k) {
        n.second = pq.top().second + 1;
        pq.push(n);
        inserted = true;
        break;
      } else {
        others.push_back(pq.top());
        pq.pop();
      }
    }
		if (!inserted) {
			pq.push(n);
		}
    for (auto other : others) {
      pq.push(other);
    }
  }
  cout << pq.top().second << endl;
}


Measured memory_bytes: 7464
s = list(input())
k = int(input())

check = ""
check_cnt = 0
ans1 = 0
for i in range(len(s)):
    if check_cnt == 0:
        check = s[i]
        check_cnt += 1
        continue
    if check == s[i]:
        check_cnt += 1
        continue
    else:
        check = s[i]
        if check_cnt == 1:
            pass
        elif check_cnt%2 == 0:
            ans1 += check_cnt//2
        else:
            ans1 += (check_cnt - 1)//2
    check_cnt = 1
else:
    if check_cnt == 1:
        pass
    elif check_cnt%2 == 0:
        ans1 += check_cnt//2
    else:
        ans1 += (check_cnt - 1)//2
    
cnt2 = 0
cnt3 = 0

temp = s[0]
for i in range(len(s)):
    if temp == s[i]:
        cnt2 += 1
    else:
        break
    
for i in range(1,len(s)+1):
    if temp == s[-i]:
        cnt3 += 1
    else:
        break

add = 0
if cnt2%2 == 1 and cnt3%2 == 1:
    add = 1
    
same = s[0]
for i in range(len(s)):
    if same == s[i]:
        continue
    else:
        break
else:
    t = len(s) * k
    if t%2 == 0:
        print(t//2)
    else:
        print((t-1)//2)
    exit()
    
print(ans1 * k + add * (k-1))

Measured memory_bytes: 3064
n = gets().to_i
a = gets().split(' ').map(&:to_i)
b = gets().split(' ').map(&:to_i)

s = 0
for i in 0..(n-1)
	if b[i] < a[i]
      a[i] -= b[i]
      s += b[i]
      b[i] = 0
    else
      b[i] -= a[i]
      s += a[i]
      a[i] = 0
      
      if b[i] < a[i + 1]
        a[i + 1] -= b[i]
        s += b[i]
        b[i] = 0
      else
        b[i] -= a[i + 1]
        s += a[i + 1]
        a[i + 1] = 0
      end
    end
end

puts s

Measured memory_bytes: 15388
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, A, B);
  while (A.length() < B.length()) {
    A = "0" + A;
  }
  while (B.length() < A.length()) {
    B = "0" + B;
  }
  print(A == B ? "EQUAL" : A > B ? "GREATER" : "LESS");
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main()
	{
      int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      int b = 0;
      for(int i=a[0]; i<=a[1]; i++) if(i%a[2]==0) b++;
      Console.WriteLine(b);
	}
}

Measured memory_bytes: 27548
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		int fst_top = sc.nextInt();
		int fst_front = sc.nextInt();
		int fst_left = sc.nextInt();
		int fst_right = sc.nextInt();
		int fst_back = sc.nextInt();
		int fst_bottom = sc.nextInt();

		int snd_top = sc.nextInt();
		int snd_front = sc.nextInt();
		int snd_left = sc.nextInt();
		int snd_right = sc.nextInt();
		int snd_back = sc.nextInt();
		int snd_bottom = sc.nextInt();

		boolean ok = false;
		for (int v = 0; v < 4; v++) {

			for (int t = 0; t < 4; t++) {
				//System.out.println(fst_top + " " + fst_front + " " + fst_left + " " + fst_right + " " + fst_back + " " + fst_bottom);
				
				for(int k = 0; k < 4; k++){
				
					if(fst_top == snd_top && fst_front == snd_front && fst_left == snd_left && 
							fst_right == snd_right && fst_back == snd_back && fst_bottom == snd_bottom){
						ok = true;
					}
					
					int tmp = fst_front;
					fst_front = fst_left;
					fst_left = fst_back;
					fst_back = fst_right;
					fst_right = tmp;
				}
				
				int tmp = fst_bottom;
				fst_bottom = fst_right;
				fst_right = fst_top;
				fst_top = fst_left;
				fst_left = tmp;
			}

			int tmp = fst_bottom;
			fst_bottom = fst_front;
			fst_front = fst_top;
			fst_top = fst_back;
			fst_back = tmp;
		}

		System.out.println(ok ? "Yes" : "No");
	}
}

Measured memory_bytes: 17328
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;

int main(int argc, char **argv)
{
  int i, accm = 0;
  char c;
  while (cin.get(c)) {
    if (isdigit(c)) {
      cin.unget();
      cin >> i;
      accm += i;
    }
  }
  cout << accm << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cctype>
#include <cstdlib>

using namespace std;

int main() {
    char s[25];
    int a, b;

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

    for (int i = a-1; i >= 0; i--) {
        if (!isdigit(s[i])){
            puts("No");
            exit(0);
        }
    }
    if (s[a] != '-'){
        puts("No");
        exit(0);
    }
        
    for (int i = a + b; i >= a + 1; i--) {
        if (!isdigit(s[i])){
            puts("No");
            exit(0);
        }
            
    }

    puts("Yes");
    return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var a, b, coin int
	fmt.Scanf("%d %d", &a, &b)

	if a > b {
		coin = a + a - 1
	} else if a == b {
		coin = a + b
	} else {
		coin = b + b - 1
	}

	fmt.Println(coin)
}


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

int main(){
  int n, c;
  cin >> n >> c;
  vector<vector<int>>d(c, vector<int>(c));
  vector<vector<int>>iwa(3, vector<int>(c, 0));
  for(int i=0; i<c; i++){
    for(int j=0; j<c; j++){
      cin >> d[i][j];
    }
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      int tmp;
      cin >> tmp;
      tmp--;
      for(int k=0; k<c; k++){
        iwa[(i+j)%3][k] += d[tmp][k];
      }
    }
  }
  int ret = 2000000000;
  for(int i=0; i<c; i++){
    for(int j=0; j<c; j++){
      for(int k=0; k<c; k++){
        if(i!=j && j!=k && k!=i){
          ret = min(ret, iwa[0][i]+iwa[1][j]+iwa[2][k]);
        }
      }
    }
  }
  cout << ret;
  return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  
  int sum=0;
  for(int i=0; i<N; i++){
    sum += L+i;
  }
  /*
  L, L+1, ... ,L+N-1
  絶対値が最小のものを抜く
  L>=0 ,L
  L<0 && L+N-1>0 ,0 操作不要
  L<0 && L+N-1<0 L+N-1
  */
  if(L>=0){
    sum -= L;
  }
  else if(L<0 && L+N-1<0){
    sum -= L+N-1;
  }
  cout << sum << endl;    
  return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};
//vector<int> dy = {1, 1, 1, 0, -1, -1, -1, 0};
//vector<int> dx = {1, 0, -1, -1, -1, 0, 1, 1};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

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


int main(){
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) cout << "Yes" << endl;
  else cout << "No" << endl;




}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

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

typedef struct E {
  ll to;
  ll cost;
} E;
typedef struct V {
  ll dest;
  vector<E> es;
} V;
typedef vector<V> G;

void dijkstra(G &g, ll s) {
  priority_queue<Pll, vector<Pll>, greater<Pll>> q;
  q.push(mkp(0, s));
  g[s].dest = 0;

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    auto c = p.first;
    auto from = p.second;
    if (g[from].dest < c) continue;

    each (j, g[from].es) {
      auto to = j.to;
      auto cost = j.cost + c;
      if (cost >= g[to].dest) continue;
      g[to].dest = cost;
      q.push(mkp(cost, to));
    }
  }
}

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  G g(n);
  g[0].dest = 1e18;
  for (ll i = 1; i < n; ++i) {
    g[i-1].es.push_back(E{.to=i, .cost=1});
    g[i] = {
      .dest = 1000000000000000000,
      .es = {E{.to=i-1, .cost=1}},
    };
  }
  g[x].es.push_back(E{.to=y, .cost=1});
  g[y].es.push_back(E{.to=x, .cost=1});
  
  vector<ll> ans(n);
  for (ll i = 0; i < n-1; ++i) {
    G g2 = g;
    dijkstra(g2, i);
    for (ll j = i+1; j < g2.size(); ++j) {
      if (g2[j].dest >= 1 && g2[j].dest < n) {
        ans[g2[j].dest]++;
      }
    }
  }

  for (ll i = 1; i < n; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll a,b;
	cin >> a >> b;
	cout << a/b << " " << a%b << " ";
	printf("%.5f",static_cast<double>(a)/b);
}


Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, a, b;std::cin >> n >> a >> b;
  string s;std::cin >> s;

  ll ok = 0, gai = 0;
  re(i, n){
    if(s[i]=='a'){
      if(ok<a+b){
        std::cout << "Yes" << '\n';
        ok++;
      }else std::cout << "No" << '\n';
    }else if(s[i]=='b'){
      gai++;
      if(ok<a+b&&gai<=b){
        std::cout << "Yes" << '\n';
        ok++;
      }else{
        std::cout << "No" << '\n';
      }
    }else{
      std::cout << "No" << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 980
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int n = as.nextInt();
		int[] a={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
		int[] b;
		int[] c={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
		b = new int[a.length];
		for(int i=0;i<a.length;i++){
			b[i] = 0;
		}
		int t;
		for(int i=0;i<a.length;i++){
			if(n<c[i]){
				continue;
			}
			b[i]+=n/c[i];
			if(n>=c[i]){
				c[i]=c[i]*a[i];
				i--;
			}
		}
		long l = 1;
		for(int i=0;i<a.length;i++){
			if(b[i]==0){
				break;
			}
			l = l*(b[i]+1)%1000000007;
		}
		System.out.println(l);
	}
}

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

using namespace std;

int main(){
    long long int N,K,now=0,twice;
    cin >> N >> K;
    vector<long long int> A(N),color(N,-1),visited,roop;

    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i]--;
    }

    visited.push_back(0);
    color[0] = 0;

    for(int i=1;;i++){
        now = A[now];

        if(K==i){
            cout << now+1 << endl;
            return 0;
        }
        
        if(color[now]==0){
            twice = now;
            break;
        }else{
            color[now] = 0;
            visited.push_back(now);
        }
    }

    for(int i=0;i<visited.size();i++){
        if(visited[i]==twice){
            K -= i;
            for(int j=i;j<visited.size();j++){
                roop.push_back(visited[j]);
            }
            break;
        }
    }

    long long int size = roop.size();

    cout << roop[K%size]+1 << endl;
}

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

int gcd(int x, int y){
  if (y == 0)
    return x;
  else
    return gcd(y, x%y);
}

int main(){
  int x,y;

  cin >> x >> y;
  if (x < y)
    swap(x,y);

  cout << gcd(x,y) << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

constexpr int N_MAX = 2500;
constexpr ll INF = 1LL<<60;

struct Edge{
    int from, to; ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

int n, m;
vector<ll> d(N_MAX, INF);
vector<bool> used0(N_MAX, false), usedn1(N_MAX, false);
vector<Edge> edges[N_MAX], edges_rev[N_MAX];

bool bellman_ford(int start){
    d[start] = 0LL;
    bool updated = true;
    for(int i=0;i<n;++i) {
        updated = false;
        for(int j=0;j<n;++j) {
            for(Edge e: edges[j]){
                if(used0[e.to] && usedn1[e.to] && d[e.from] + e.cost < d[e.to]){
                    d[e.to] = d[e.from] + e.cost;
                    updated = true;
                }
            }
        }
        if(!updated) return false;
    }
    return true;
}

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b;
    ll c, p;
    cin >> n >> m >> p;
    for(int i=0;i<m;++i){
        cin >> a >> b >> c;
        --a; --b;
        edges[a].push_back(Edge(a, b, -(c-p)));
        edges_rev[b].push_back(Edge(b, a, -(c-p)));
    }

    queue<Pii> que;
    que.emplace(0, 1);
    used0[0] = true;
    int node, depth;
    while(!que.empty()) {
        tie(node, depth) = que.front(); que.pop();
        for(Edge e: edges[node]) {
            if(!used0[e.to]) {
                used0[e.to] = true;
                que.emplace(e.to, depth+1);
            }
        }
    }
    que.emplace(n-1, 1);
    usedn1[n-1] = true;
    while(!que.empty()) {
        tie(node, depth) = que.front(); que.pop();
        for(Edge e: edges_rev[node]) {
            if(!usedn1[e.to]) {
                usedn1[e.to] = true;
                que.emplace(e.to, depth+1);
            }
        }
    }

    bool has_negative_loop = bellman_ford(0);

    cout << (has_negative_loop?-1:max(0LL, -d[n-1])) << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N;
string S;

//解法
void solve() {

	vector<pair<ll, ll>> front(N);
	ll east = 0, west = 0;

	rep(i, N) {
		if (S[i] == 'W') {
			west++;
			if (i != 0) {
				front[i] = front[i - 1];
				front[i].first++;
			}
			else {
				front[i] = make_pair(1, 0);
			}
		}
		else {
			east++;
			if (i != 0) {
				front[i] = front[i - 1];
				front[i].second++;
			}
			else {
				front[i] = make_pair(0,1);
			}
		}
	}

	ll ans = LLONG_MAX;

	rep(i, N) {
		ll sum = 0;
		if (S[i] == 'W') {
			sum = front[i].first-1 + east - front[i].second;
		}
		else {
			sum = front[i].first + east - front[i].second;
		}
		ans = min(ans, sum);
	}

	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N >> S;
	solve();
	cout << endl;
	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class UnionFind{
	vector<ll> rank;
	vector<ll> diff_weight;
	vector<ll> num;
public:
	vector<ll> par;

	UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
			rank[i]=0;
			diff_weight[i]=0;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		ll r = root(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]) swap(rx,ry);
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		num[rx] += num[ry];
	}

	void relate(ll x,ll y,ll w){
		w+=weight(x),w-=weight(y);
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]){
			swap(rx,ry);
			w = -w;
		}
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		diff_weight[ry] = w;
		num[rx] += num[ry];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}

	ll weight(ll x){
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x,ll y){
		return weight(y)-weight(x);
	}
};

class Data{
public:
	int u,v,d;
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	double x[4],y[4];
	while(cin>>x[0]){
		cin>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3];
		double dx1=x[1]-x[0],dy1=y[1]-y[0];
		double n=hypot(dx1,dy1);
		dx1/=n;
		dy1/=n;
		double dx2=x[3]-x[2],dy2=y[3]-y[2];
		n=hypot(dx2,dy2);
		dx2/=n;
		dy2/=n;
		if(abs(dx1*dx2+dy1*dy2)<1e-10){
			out("YES");
		}
		else{
			out("NO");
		}
	}
	return 0;
}


Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
int main(){
	int n;
	char a[4];
	gets(a);
//	scanf("%d",&n);
//	a[0]=n/1000;
//	a[1]=n/100%10;
//	a[2]=n/10%10;
//	a[3]=n%10;
	
//	if(a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3]){
//		printf("Yes\n");
//		return 0;
//	}
	if((a[0]==a[1]&&a[0]==a[2])||(a[1]==a[2]&&a[1]==a[3])){
		printf("Yes\n");
		return 0;
	}
//	if((a[1]==a[2]&&a[1]==a[3])){
//		printf("Yes\n");
//		return 0;
//	}
//	if((a[0]==a[3]&&a[0]==a[2])){
//		printf("Yes\n");
//		return 0;
//	}
//	if((a[3]==a[1]&&a[0]==a[3])){
//		printf("Yes\n");
//		return 0;
//	}
	printf("No\n");
	return 0;
}

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

int main() {
	int n,m=0;
	scanf("%d",&n);
	for(int i=1;i<=9;i++)
	    for(int j=1;j<=9;j++)
	        if (i*j==n) m=1;
    if (m==1) printf("Yes");
    else printf("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
ll calc(ll n){
  ll count=0;
  n=n/2;
  while(n!=0){
    count += n/5;
    n=n/5; 
  }
  return count;
}
int main() {
  ll n;
  cin >> n;
  if(n%2==1){
    cout << 0 << endl;
  }else{
    cout << calc(n) << endl;
  }
  
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);


            Console.WriteLine(Math.Min(a * n, b).ToString());
        }
    }
}

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

int main(void){
	char S[1000];
	char T[1000];
	int num;
	int ans;

	scanf("%s",S);
	scanf("%s",T);
    
	for(int i=0;i<strlen(S)-strlen(T)+1;i++){
		num=0;
	 for(int j=0;j<strlen(T);j++){
		 if(S[i+j]!=T[j]) num+=1;
	 }
    if(i==0) ans=num; 
	else {
		if(num<ans) ans=num;
	}
	}

	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2156
n, k = map(int, input().split())
targets = list(map(int, input().split()))

seen = dict()
goal = dict()

seen[1] = 0
goal[0] = 1

prev = targets[0]
startFlag = False
for i in range(1, k):
    seen[prev] = i
    goal[i] = prev
    current = targets[prev - 1]
    if current in seen:
        before = seen[current]

        finalGoal = (k - (i+1)) % (i + 1 - before)
        print(goal[finalGoal + before])
        exit()
    prev = current


print(prev)

Measured memory_bytes: 126376
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vl a(n),b(n),c(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,n)cin>>c[i];

  sort(rng(a));
  sort(rng(b));
  sort(rng(c));
  
  vl S(n+1),B(n);
  rep(i,n){
    B[i] = lower_bound(rng(a),b[i])-a.begin();
  }
  rep(i,n){
    S[i+1] = B[i]+S[i];
  }
  //rep(i,n+1)cout<<S[i]<<endl;
  ll ans = 0;
  rep(i,n){
    int x = lower_bound(rng(b),c[i])-b.begin();
    ans+=S[x];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4224
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let s: String = read();

    let mut ans = 1000;
    for i in 0..s.len() - 2 {
        let a: isize = *&s[i..i + 3].parse().unwrap();
        ans = min(ans, (753 - a).abs());
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define max 1000000
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define lli long long int
#define endl '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a,n) for(int i=0;i<n;i++) cin >> a[i];
#define CopyArray(a,temp,n) for(int i=0;i<n;i++) temp[i]=a[i];
#define PrintArray(a,n) for(int i=0;i<n;i++) cout << a[i] << " "; cout << endl;
using namespace std;


int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif
	FastInput;

	int n; 
	cin >> n;
	int k = n % 10;
	if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) {
		cout << "hon\n";
	} else if (k == 0 || k == 1 || k == 6 || k == 8) {
		cout << "pon\n";
	} else if (k == 3) {
		cout << "bon\n";
	}

	cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
	return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll,int> m;
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        if ( i % 2 == 0 ) m[A[i]]++;
    }
    sort(A.begin(), A.end());
    for ( int i = 0; i < N; i++ ) {
        if ( i % 2 == 0 ) m[A[i]]--;
    }
    ll ans = 0;
    for ( auto p : m ) {
        if ( p.second > 0 ) ans++;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7296
n, p = map(int, input().split())
a = list(map(int, input().split()))
m = [0, 0]
for i in range(n):
    m[a[i] % 2] += 1
if m[1] == 0 and p == 1:
    print(0)
else:
    print(2**m[0] * 2**(m[1]-1) if m[1] > 0 else 2**m[0])

Measured memory_bytes: 3060
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

newUF :: PrimMonad m => Int -> m (VM.MVector (PrimState m) Int)
newUF n = do
  d <- VM.new n
  VM.set d (-1)
  return d

findUF :: PrimMonad m => VM.MVector (PrimState m) Int -> Int -> m Int
findUF d x = do
  dx <- VM.read d x
  if dx < 0
    then return x
    else do dx' <- findUF d dx
            VM.write d x dx'
            return dx'

uniteUF :: PrimMonad m => VM.MVector (PrimState m) Int -> Int -> Int -> m ()
uniteUF d x y = do
  x' <- findUF d x
  y' <- findUF d y
  when (x' /= y') $ do
    let (x'', y'') = if (x' <= y') then (x', y') else (y', x')
    dx <- VM.read d x''
    dy <- VM.read d y''
    VM.write d x'' (dx + dy)
    VM.write d y'' x''
  return ()

sameUF :: PrimMonad m => VM.MVector (PrimState m) Int -> Int -> Int -> m Bool
sameUF d x y = do
  fx <- findUF d x
  fy <- findUF d y
  return $ fx == fy

sizeUF :: PrimMonad m => VM.MVector (PrimState m) Int -> Int -> m Int
sizeUF d x = do
  fx <- findUF d x
  dfx <- VM.read d fx
  return (-dfx)

main = do
  [n, m] <- getIntList
  ps <- getIntVec n

  uf <- newUF (n+1)
  replicateM m $ do
    [x, y] <- getIntList
    uniteUF uf x y

  let solve i res | i > n = return res
                  | otherwise = do
                      b <- sameUF uf (ps V.! (i - 1)) i
                      let res' = res + if b then 1 else 0
                      solve (i+1) res'

  ans <- solve 1 0

  print ans

Measured memory_bytes: 14844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
    long long int l,r;
    cin >> l >> r;
    if(r -l >= 2019){
        cout << "0" << endl;
        return 0;
    }
    static long long int ans=LLONG_MAX;
for(long long int i=l;i<=r;i++)
for(long long int j=l;j<i;j++){
    if(ans > (i * j)% 2019){
ans = (i * j)%2019;
    }
}
cout << ans;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

bool check(vector<string>& s, vll& v) {
    for(ll i = 0; i < v.size(); i++) {
        for(ll j = i + 1; j < v.size(); j++) {
            if(s[v[i]][v[j]] == '1') return false;
        }
    }
    return true;
}

void solve() {
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vvll d(n, vll(n, 1));
    rep(i, n) rep(j, n) if(s[i][j] == '0') d[i][j] = INFL;
    rep(k, n) rep(i, n) rep(j, n) {
        chmin(d[i][j], d[i][k] + d[k][j]);
    }
    pll p;
    ll dmax = 0;
    rep(i, n) rep(j, n) {
        if(i == j) continue;
        if(d[i][j] > dmax) {
            dmax = d[i][j];
            p = make_pair(i, j);
        }
    }
    vll even, odd;
    for(ll i = 0; i < n; i++) {
        if(d[p.first][i] % 2) odd.push_back(i);
        else even.push_back(i);
    }
    if(!check(s, even) || !check(s, odd)) {
        cout << -1 << endl;
        return;
    }
    cout << dmax + 1 << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3924
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var N = lines[0];
  var days = [ 'SUN','MON','TUE','WED','THU','FRI','SAT' ];
  var idx = days.indexOf(N);
  var result = 7 - idx;
  console.log(result);
});

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

#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define bitcount(a) __builtin_popcount(a) // count set bits
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

typedef long long int ll;
const ll MOD = 1e9+7;

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
/*
inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M,only if M is prime
ll add(ll a,ll b,ll M)  { return mod(( mod(a,M ) + mod(b,M )),M);     }
ll sub(ll a, ll b,ll M) { return mod((mod(a,M ) + M - mod(b,M )),M);   }
ll mult(ll a,ll b,ll M) { return  mod(( mod(a,M)*mod(b,M) ),M) ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

  
               /* -------------------------------Main Code------------------------------- */						
int main(){
    FAST
    int n,m;cin>>n>>m;
    vector<vector<int>> vp(1e5+5);
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        vp[a].push_back(b);
    }
    ll ans = 0;
    priority_queue<int> PQ;
    for(int i=m-1;i>=0;i--){
        for(auto x : vp[m-i]) PQ.push(x);
        if(!(PQ.empty())){
            int cur = PQ.top();
            PQ.pop();
            ans += cur;
        }
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	/*
	int n,q;
  cin >> n >> q;
	vector<int> c(n);
  rep(i,n) {
	  cin >> c[i];
	}
	*/

	string s;
	cin >> s;

	if (s == "RRR") cout << 3;
	else if (s == "RRS" || s == "SRR") cout << 2;
	else if (s == "SSS") cout << 0;
	else cout << 1;
	cout << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n ,m, x;
    cin >> n >> m >> x;
    VI a(n+1);
    rep(i, m){
        int j;
        cin >> j;
        a[j]++;
    }
    int ans = 200;
    int sum = 0;
    for(int i = x; i >= 0; i--){
        if (a[i] == 1) sum++;
    }
    ans = min(ans, sum);
    sum = 0;
    for(int i = x; i <= n; i++){
        if (a[i] == 1) sum++;
    }
    ans = min(ans, sum);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

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);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	String S = in.next();
        	String T = in.next();
        	String tmp = S;
        	String ans = "No";
        	
        	for(int i = 0; i < 100; i++) {
        		tmp = tmp.substring(tmp.length()-1) + tmp.substring(0, tmp.length() - 1);
        		if(tmp.equals(T)) {
        			ans = "Yes";
        			break;
        		}
        	}        	
        	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: 22612