akhauriyash/Code-Regression huggingface dataset:
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
 *
 * @author anand.oza
 */
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);
        BMaximumDifference solver = new BMaximumDifference();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumDifference {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Long[] a = new Long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }
            Arrays.sort(a);

            out.println(a[n - 1] - a[0]);
        }

    }

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

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	return gcd(b, a % b);
}

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

int main()
{
	int N;
	ll M;
	cin >> N >> M;
	vector<ll> a(N);
	auto hasEven = false;
	for (auto i = 0; i < N; ++i)
	{
		cin >> a[i];
		a[i] /= 2;
	}

	auto ans = 0ll;
	auto temp = a[0];
	auto valid = true;
	for (auto i = 1; i < N; ++i)
	{
		temp = lcm(temp, a[i]);
	}
	for (auto i = 0; i < N; ++i)
	{
		if ((temp / a[i]) % 2 == 0)
		{
			valid = false;
			break;
		}
	}

	if (valid)
	{
		ans = (M / temp + 1) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n;
   cin >> n;
   int a[n];
  
   int l;
   int k = 0;
  
   while(cin>>l){
        a[k] = l;
       
        k++;
    }

int max = 0;

int tmp = 0;
  
for(int i = 1;i<n;i++){
  
  //cout << a[i] << endl;
    
  if(a[i-1]>=a[i]){
    
    tmp++;
    
    if(i==n-1){
      
      if(max<tmp+1){
        max = tmp;
        
      }
    }
    
  }else{
    
    if(max<tmp){
     
      max = tmp;
    }
    
    tmp = 0;
    
  }
  
     

}
   
  cout << max << endl;
   
  
  
  
   
  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

class vector
{
  struct node
  {
    int val;
    struct node* next;
    node(int n) : val(n), next(NULL) {}
  };

  node* head;
  node* tail;

public:
  vector()
  {
    head = new node(0);
    tail = head;
  }
  ~vector()
  {
    clear();
    delete head;
  }
  void push_back(int x);
  void dump();
  void clear();
};

void vector::push_back(int x)
{
  node* newobj = new node(x);
  tail->next = newobj;
  tail = newobj;
}

void vector::dump()
{
  node* p = head->next;
  while (p != NULL)
  {
    cout << p->val;
    p = p->next;
    if (p != NULL) cout << " ";
  }
  cout << endl;
}

void vector::clear()
{
  node* p = head->next;
  node* tmp;
  while (p != NULL)
  {
    tmp = p->next;
    delete p;
    p = tmp;
  }
  head->next = NULL;
  tail = head;
}

int main()
{
  int i, n, q, c, t, x;

  cin >> n >> q;

  vector* ary = new vector[n];

  for (i = 0; i < q; i++)
  {
    cin >> c >> t;
    switch (c)
    {
    case 0:
      cin >> x;
      ary[t].push_back(x);
      break;
    case 1:
      ary[t].dump();
      break;
    case 2:
      ary[t].clear();
      break;    
    }
  }

  delete[] ary;

  return 0;
}


Measured memory_bytes: 18796
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;


int main() {

	int N;
	cin >> N;

	vector<int> vec(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}


	int res=0;

	for (int j = 0; j < N; j++) {
		if (vec[j] != j + 1) {
			res++;
		}
	}

	if (res == 2||res==0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


}

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

using namespace std;



int main(){
	
	int N;
	cin >> N;
	vector<int> vec(N);
	vector<int> sorted(N);
	
	int bottom,upper;
	
	for(int i=0; i<N; i++){
		cin >> vec.at(i);
	}
	sorted = vec;
	
	std::sort(sorted.begin(), sorted.end());
	
	bottom = sorted.at(N/2 -1);
	upper = sorted.at(N/2);
	
	/*cout << bottom << " " << N/2 << endl;
	cout << upper << " " << N/2 +1 << endl;
	
	for(int i=0; i<N; i++){
		cout << vec.at(i) << " " ;
	}
	cout << endl;
	for(int i=0; i<N; i++){
		cout << sorted.at(i) << " " ;
	}
	cout << endl;
	*/
	for(int i=0; i<N; i++){
		
		if(vec.at(i)<=bottom) cout  << upper <<endl;
		else if(vec.at(i)>=upper ) cout << bottom<< endl;
		else cout << "problem" << endl;
	}
	
}


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

using namespace std;

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

int main(){
  int N;
  vector<int> A;
  cin >> N;
  for (int i=0; i<N; i++) {
	int Ai;
	cin >> Ai;
	A.push_back(Ai);
  }

  int ans = A.at(0);
  for (int i=1; i<N; i++) {
	ans = gcd(ans, A.at(i));
  }

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

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

int number[6];
int relative[55];

class Dice {
public:
    Dice(){
		relative[31] = relative[43] = relative[24] = relative[12] = 0;
		relative[3] = relative[20] = relative[52] = relative[35] = 1;
		relative[1] = relative[40] = relative[54] = relative[15] = 2;
		relative[4] = relative[10] = relative[51] = relative[45] = 3;
		relative[2] = relative[30] = relative[53] = relative[25] = 4;
		relative[21] = relative[42] = relative[34] = relative[13] = 5;
 	};
    void setLabel(int index, int num) {
        number[index] = num;
    }
    int returnRight(int top, int front) {
        int top_index, front_index;
        for (int i = 0; i < 6; i++) {
            if (top == number[i]) top_index = i;
            if (front == number[i]) front_index = i;
        }
        return number[relative[10 * top_index + front_index]];
    }
};

int main() {
    Dice dice;
    int label, Q, top, front;
    for (int i = 0; i < 6; i++) {
        cin >> label;
        dice.setLabel(i, label);
    }
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> top >> front;
        cout << dice.returnRight(top, front) << endl;
    }
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<algorithm>
using namespace  std;
int b[65536];
int c[65536];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d",b+i);
		for(int i=0;i<a-1;i++)scanf("%d",c+i);
		std::sort(b,b+a);
		std::sort(c,c+a-1);
		long long s=0;
		for(int i=0;i<a;i++)s+=b[i];
		for(int i=0;i<a-1;i++)s+=c[i];
		long long ret=s;
		for(int i=0;i<a-1;i++){
			s-=c[i];
			ret=max(ret,s*(i+2));
		}
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PRINT(s) cout << s << endl;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR((i), 0, (n))

int main() {
    int a, v, b ,w, t;
    cin >> a >> v >> b >> w >> t;
    
    int d;
    if (a == b) {
        PRINT("YES");
        return 0;
    } else if (a < b) {
        d = b - a;
    } else {
        d = a - b;
    }

    int y = v - w;
    if (y < 1) {
        PRINT("NO");
        return 0;
    }
    int jikan = d / y; 
    if (jikan > t) {
        PRINT("NO");
    } else if (t == jikan){
        if (d % y == 0) {
            PRINT("YES");
        } else {
            PRINT("NO");
        }
    } else {
        PRINT("YES");
    }
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A == B) cout << C << endl;
    else if(B == C) cout << A << endl;
    else cout << B << endl;
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i,N) cin >> S[i];
	map<string,int> m;
	rep(i,N){
		m[S[i]]++;
	}
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;

	return 0;
}

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

int main() {
  // ここにプログラムを追記
  int n, a, b, c, d;
  cin >> n;
  a = n / 1000;
  b = n % 1000 / 100;
  c = n % 1000 % 100 / 10;
  d = n % 1000 % 100 % 10;
  //cout << a << b << c << d << endl;
  if((a == b) && (b == c) || (b == c) && (c == d)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int equal(char *s,char *t,int len){
  while(len--){
    if(s[len]!=t[len]) return 0;
  }
  return 1;
}

void run(void){
  char d[]="keyence";
  char s[101];
  scanf("%s",s);
  int n=0;
  while(s[n]!='\0') n++;
  int i;
  for(i=0;i<=7;i++){
    if(equal(d,s,i) && equal(d+i,s+n-7+i,7-i)){
      printf("YES\n");
      return;
    }
  }
  printf("NO\n");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
from numba import njit

@njit('i8(i8)', cache=True)
def popcount(n):
    a = 0
    while n != 0:
        a += n & 1
        n >>= 1
    return a

@njit('i8(i8)', cache=True)
def fun(n):
    ops = 0
    while n:
        pc = popcount(n)
        n %= pc
        ops += 1
    return ops

n = int(input())
xs = list(map(int, input()))

from functools import reduce
sm = reduce(lambda x,y: x*2+y, xs)
pc = xs.count(1)

# pcの差分を出した後の剰余計算を速くするため、事前にmod pc+1, mod pc-1を計算しておく
mp = sm % (pc + 1)
mm = sm % (pc - 1) if pc > 1 else 0

for i in range(n):
    df = 1 if xs[i] == 0 else -1
    pci = pc + df
    if pci == 0:
        print(0)
        continue

    rest = pow(2, n - i - 1, pci)

    if xs[i] == 0:
        smi = (mp + rest) % pci
        print(1 + fun(smi))
    else:
        smi = (mm - rest) % pci
        print(1 + fun(smi))



Measured memory_bytes: 109376
<?php
/*
	AOJ 0556
	Title:Tile
	@kankichi573
*/
function calc_color($n,$a,$b)
{
	if($a > $n / 2)
	  $a = ($n + 1)-$a;
	if($b > $n / 2)
	  $b = ($n + 1)-$b;
	  
	if($a<$b)
	  $ret=$a;
	else 
	  $ret=$b;

	$ret = $ret % 3;
	if($ret==0)
	  $ret=3;
	return($ret);
}

fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%d",$k);
for($i=0;$i<$k;$i++)
  {
    fscanf(STDIN,"%d %d",$a,$b);
    fprintf(STDOUT,"%d\n",calc_color($n,$a,$b));
  }

return(0);

?>

Measured memory_bytes: 6596
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main()
{
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	int cnt = 0,ans = 0;
	for(int i = n;i >= 2;i--)
		if(a[i] <= a[i-1])
			cnt ++;
		else{
			ans = max(ans,cnt);
			cnt = 0;
		}
	ans = max(ans,cnt);
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;

int n;

int main()
{
    fastRead;
    int n;
    cin>>n;
    
    vector<ll>vec(3*n);
    for(int i = 0 ; i < 3*n ; i++ ) cin>>vec[i];
    
    
    sort(vec.begin() , vec.end());
    
    ll ans = 0;
    for(int i =0, j= 3*n-2  ; i < n ;i++ , j-=2 ) {
        ans += vec[j];
    }
    
    cout<<ans<<'\n';
    return 0;
    
}

Measured memory_bytes: 2560
import queue

h, w = map(int, input().split())
s = []
total = h * w
num_b = 0
for i in range(h):
    tmp = input()
    num_b += tmp.count('#')
    s.append(tmp)

visited = set()
q = queue.Queue()

# y, x, depth (start = 1)
q.put((0, 0, 1))
visited.add((0, 0))

while not q.empty():
    y, x, depth = q.get()
    if y == h - 1 and x == w - 1:
        print(total - num_b - depth)
        exit()
    if x < w - 1:
        if (y, x+1) not in visited and s[y][x+1] == '.':
            visited.add((y, x+1))
            q.put((y, x+1, depth+1))
    if x > 0:
        if (y, x-1) not in visited and s[y][x-1] == '.':
            visited.add((y, x-1))
            q.put((y, x-1, depth+1))
    if y < h - 1:
        if (y+1, x) not in visited and s[y+1][x] == '.':
            visited.add((y+1, x))
            q.put((y+1, x, depth+1))
    if y > 0:
        if (y-1, x) not in visited and s[y-1][x] == '.':
            visited.add((y-1, x))
            q.put((y-1, x, depth+1))

print(-1)


Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

ll dp[105][MAX];

int main()
{
	int n, W;
	sd(n);sd(W);
	int w[n], v[n];
	fi(0,n,1){
		sd(w[i]);sd(v[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<MAX;j++){
			if(j==0){
				dp[i][j]=0;
			}else if(i==0 && j!=v[i]){
				dp[i][j]=INF;
			}else if(i==0){
				dp[i][j]=w[i];
			}else if(j-v[i]<0){
				dp[i][j]=dp[i-1][j];
			}else{
				dp[i][j]=min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
			}
			//if(j==v[i])cout<<dp[i][j]<<" ";
		}//cout<<endl;
	}
	ll ans=0;
	fi(0,MAX,1){
		if(dp[n-1][i]!=INF && i>ans && dp[n-1][i]<=W){
			ans=i;
		}
	}
	cout<<ans;
}

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

int main(void){
    int x, y, s, i=0, j=0;
    while(true){
        int max=0, a=0, b=0, newa=0, newb=0;
        cin >> x >> y >> s;
        if(x==0 && y==0 && s==0)break;
        for(i=1;i<s;i++){
            for(j=1;j<s;j++){
                a = i*(100+x)/100;
                b = j*(100+x)/100;
                if((a+b)==s){
                    newa = i*(100+y)/100;
                    newb = j*(100+y)/100;
                    if(max < (newa+newb))max = newa+newb;
                }
            }
        }
        cout << max << endl;
    }
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> A(n + 1);
    vector<bool> ans(n + 1);
    rep(i, n) cin >> A[i + 1];
    for (int i = n; i > 0; i--) {
        int cnt = 0;
        int x = 2 * i;
        while(x <= n) {
            if (ans[x]) cnt++;
            x += i;
        }
        if (cnt % 2 == A[i]) ans[i] = 0;
        else ans[i] = 1;
    }
    vector<int> ret;
    REP(i, 1, n) if (ans[i]) ret.push_back(i);
    cout << ret.size() << endl;
    for (int i : ret) cout << i << " ";
    cout << endl;
}

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


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

typedef struct tagST {
	long long A;
	int B;

} ST;

using namespace std;

// 比較関数を定義
bool asc(const ST& left, const ST& right) {
    return left.A == right.A ? left.B < right.B : left.A < right.A;
}

int main(void) {
	int N, M;

	cin >> N >> M;
	vector<ST> vec;

	for (int i = 0; i < N; i++) {
		ST st;
		cin >> st.A >> st.B;
		vec.push_back(st);
	}

	long long total = 0;
	sort(vec.begin(), vec.end(), asc);
	for (size_t i = 0; i < vec.size(); i++) {
		if (M > vec[i].B) {
			int cnt = vec[i].B;
			M -= cnt;
			total += vec[i].A * cnt;
		} else {
			// M <= vec[i].B
			total += vec[i].A * M;
			M = 0;
			break;
		}
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;

struct SCC{
	vector<vector<int> > gg,rg;
	vector<int> comp,order;
	vector<bool> used;
	vector<vector<int> > ng,vs;
	int n,nn;
	SCC(){}
	SCC(int v):gg(v),rg(v),comp(v,-1),used(v,0),n(v){}
	void add_edge(int x,int y){
		gg[x].push_back(y);
		rg[y].push_back(x);
	}
	int operator[](int k){
		return comp[k];
	}
	void dfs(int v){
		used[v]=1;
		for(int i:gg[v]){
			if(!used[i])dfs(i);
		}
		order.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=1;
		comp[v]=k;
		for(int i:rg[v]){
			if(!used[i])rdfs(i,k);
		}
	}
	int build(){
		for(int i=0;i<n;i++){
			if(!used[i])dfs(i);
		}
		for(int i=0;i<n;i++){
			used[i]=0;
		}
		int k=0;
		for(int i=order.size()-1;i>=0;i--){
			if(!used[order[i]])rdfs(order[i],k++);
		}
		nn=k;
		// それぞれの強連結成分に含まれる頂点の番号
		vs.resize(k,vector<int>());
		for(int i=0;i<n;i++){
			vs[comp[i]].push_back(i);
		}
		// 強連結成分をまとめた後のグラフ
		ng.resize(k,vector<int>());
		for(int i=0;i<n;i++){
			for(int j:gg[i]){
				if(comp[i]!=comp[j]){
					ng[comp[i]].push_back(comp[j]);
				}
			}
		}
		for(int i=0;i<nn;i++){
			sort(ng[i].begin(),ng[i].end());
			ng[i].erase(unique(ng[i].begin(),ng[i].end()),ng[i].end());
		}
		return k;
	}
	int size(){
		return nn;
	}
	vector<vector<int> > graph(){
		return ng;
	}
	vector<int> vertices(int v){
		return vs[v];
	}
};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	SCC scc(n);
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		scc.add_edge(x,y);
	}
	scc.build();
	for(int i=0;i<n;i++){
		vector<int> v;
		for(int j=0;j<n;j++){
			if(scc[i]==scc[j])v.push_back(j);
		}
		cout << v[0]+1;
		for(int k=1;k<v.size();k++){
			cout << " " << v[k]+1;
		}
		cout << endl;
	}
}



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

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

    long int a[310000];

    for (int i = 0; i < 3 * N; i++)
        cin >> a[i];

    sort(a, a + 3*N, greater<int>());

    long int sum = 0;

    for (int i = 0; i < N; i++)
    {
        sum += a[2*i+1];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	ll dp[1010][1010];
int main(){
	ll h,w;
	cin>>h>>w;
	char a[1010][1010];
	rep(i,0,h)rep(j,0,w)cin>>a[i][j];
	dp[0][0]=1;
	rep(i,0,h)rep(j,0,w){
		dp[i][j]%=1000000007;
		if(a[i+1][j]=='.')dp[i+1][j]+=dp[i][j];
		if(a[i][j+1]=='.')dp[i][j+1]+=dp[i][j];
	}
	cout<<dp[h-1][w-1]%1000000007<<endl;
	
}

Measured memory_bytes: 9088
N = int(input())
P = list(map(str, input().split(' ')))
Q = list(map(str, input().split(' ')))
ans = []
now = []

def CulucPermutation(array, now, level):
    if level==N:
        ans.append(''.join(now))
        #print('return and level=',level)
        return
    for i in range(0,N):
        if array[i] not in now:
            now += [array[i]]
            #print('bp',now, level, i)
            CulucPermutation(array, now, level+1)
            now.pop()
            #print('ap',now, level, i)
        else:
            pass

def main():
    # 順列の元となる値をlist格納
    n = []
    for i in range(1,N+1):
        n += [str(i)]
    # 順列を全列挙して結果をリストans(文字型)にため込む
    CulucPermutation(n, now, 0)
    # PとQを文字列化して場所を特定、計算する。
    p = ''.join(P)
    q = ''.join(Q)
    print(abs(ans.index(p) - ans.index(q)))

if __name__=='__main__':
    main()

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

int main() {
  int r;
  cin >> r;
  if(r < 1200){
    cout << "ABC" << endl;
  }
  else if(r < 2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
 string s;
 cin >> s;
  int a=0,b=0,c=0;
  a = s.find("a");
  b = s.find("b");
  c = s.find("c");
  if(a != b && a!= c && b != c){
    if(a != string::npos && b != string::npos && c != string::npos){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner scan = new Scanner(System.in)) {

			int a = scan.nextInt();
			int b = scan.nextInt();
			
			int ans = a - b*2;
			if(ans < 0) ans = 0;
			
			System.out.println(ans);
		}
	}
}

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

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

  int n;
  cin >> n;
  
  int g = 0;
  vector<int> fre(1e6+50, 0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    fre[x]++;
    g = __gcd(g, x);
  }

  if (g != 1) {
    cout << "not coprime\n";
    return 0;
  }
    
  int flag = 1;
  for (int i = 2; i < 1e6+50; ++i) {
    for (int j = 2*i; j < 1e6+50; j += i) {
      fre[i] += fre[j];
    }
    if (fre[i] >= 2) flag = 0;
  }

  if (flag) cout << "pairwise coprime\n";
  else cout << "setwise coprime\n";
}


Measured memory_bytes: 7136
def print_chessboard(h, w):
    """
    h: int
    w: int
    outputs chessboard using '#' and '.'

    >>> print_chessboard(3, 4)
    #.#.
    .#.#
    #.#.
    >>> print_chessboard(5, 6)
    #.#.#.
    .#.#.#
    #.#.#.
    .#.#.#
    #.#.#.
    >>> print_chessboard(2, 2)
    #.
    .#
    """
    for i in range(h):
        line = ''
        for j in range(w):
            if (i+j) % 2 == 0:
                line += '#'
            else:
                line += '.'
        print(line)


if __name__ == '__main__':

    while True:
        (h, w) = [int(i) for i in input().split(' ')]
        if h == 0 and w == 0:
            break
        print_chessboard(h, w)
        print()

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

#define ll long long
#define MOD 1000000007


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

    vector<ll> dist(n);

    for(int i=0;i<n;i++){
        cin>>dist.at(i);
        dist.at(i) = abs(dist.at(i)-x);
    }

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

    ll min = dist.at(0);

    vector<ll> gcd;

    for(int i=1;i*i<=min;i++){
        if(min%i==0){
            gcd.push_back(i);
            gcd.push_back(min/i);
        }
    }

    sort(gcd.begin(),gcd.end(),greater<ll>());


    int z=0;
    ll ans;

    for(int i=0;i<gcd.size();i++){
        for(int j=0;j<n;j++){
            if(dist.at(j)%gcd.at(i)!=0){
                break;
            }
            if(j==n-1){
                z=1;
                ans = gcd.at(i);
            }
        }
        if(z==1)break;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
ll maax=1000001;
ll p[10000001];

 ll dp[200000];

int inv(ll x,ll y)
{
	//ll y=mod-2;
	unsigned int res=1;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y=y>>1;
		x=(x*x)%mod;
	}
	return res;
}
void seive()
{
	p[0]=1;
	p[1]=1;
	for(int i=2;i<maax;i++)
	{
		if(p[i]==0)
		{
			for(int j=2*i;j<maax;j+=i)
			{
				if(p[j]==0)
					p[j]=i;
	
			}
			p[i]=i;
		}
	}
}
ll md(ll a){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}
int main()
{
	ll n;
	cin>>n;
	ll t=10;
	ll ans=0;
	
	while(n>=t)
	{
		
		ans+=n/t;
		t=t*5;
	}
	if(n%2==0)
	cout<<ans;
	if(n%2==1)
		cout<<"0";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int M;
    cin>>M;
    vector<pair<int,ll>> dc(M);
    rep(i,M)cin>>dc.at(i).first>>dc.at(i).second;
    ll keta=0;
    rep(i,M){
        keta+=dc.at(i).second;
    }
    ll sum=0;
    rep(i,M){
        sum+=dc.at(i).first*dc.at(i).second;
    }
    if(sum%9==0){sum-=9;}
    sum/=9;
    cout<<sum+keta-1<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define eps 1e-8
#define N 1000002
#define all(x) (x).begin(), (x).end()

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    map<string,int> mp;
    int n;
    cin >> n;
    int mx = 0;
    while (n--) {
        string s;
        cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    
    vector<string> v;
    for (const auto& p: mp) {
        if (p.second == mx) 
            v.push_back(p.first);
    }

    sort(all(v));
    for (string& s: v) cout << s << '\n';
}


Measured memory_bytes: 25584
#include <stdio.h>

#define MAX 100

int main(void)
{
    int i, j;

    int row, column;
    scanf("%d %d", &row, &column);

    int in_mat[MAX][MAX];
    for (i = 0; i < row; i++) {
        for (j = 0; j < column; j++) {
            scanf("%d", &in_mat[i][j]);
        }
    }

    int in_vec[MAX];
    for (j = 0; j < column; j++) {
        scanf("%d", &in_vec[j]);
    }

    int out_vec[MAX];
    for (i = 0; i < row; i++) {
        out_vec[i] = 0;
        for (j = 0; j < column; j++) {
            out_vec[i] += in_mat[i][j] * in_vec[j];
        }
        printf("%d\n", out_vec[i]);
    }

    return 0;
}

Measured memory_bytes: 636
//maim.cpp/////////////////////////////
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int a,b;
  string ans;
  cin >> a >> b;
  
  if (a*b%2== 0)
  {
    ans = "Even";
  }
  else
  {
    ans = "Odd";
  }
  
  cout << ans;
}


Measured memory_bytes: 256
N = int(input())

prime=[]
for n in range(2, N+1):
    for i in range(2, n):
        if n % i == 0:
            break
    else:
        prime.append(n)
#print(prime)

bucket=[0]*(N+1)
for i in range(2, N+1):
    for p in prime:
        while i % p == 0:
            i //= p
            bucket[p] += 1
#print(bucket)

cnt = 0
for i in range(2, N+1):
    if bucket[i] >= 74:
        cnt += 1
    if bucket[i] >= 24:
        cnt += len([bucket[j] for j in range(2, N+1) \
             if j != i and bucket[j] >= 2])
    if bucket[i] >= 14:
        cnt += len([bucket[j] for j in range(2, N + 1) \
                    if j != i and bucket[j] >= 4])
    if bucket[i] >= 4:
        for j in range(i+1, N+1):
            if j != i:
                if bucket[j] >= 4:
                    #print(i,j)
                    cnt += len([bucket[k] for k in range(2, N + 1)\
                    if k != i and k != j and bucket[k] >= 2])
print(cnt)



Measured memory_bytes: 39088
#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 ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n, r;
  cin >> n >> r;
  int ans = r;
  if (n < 10) {
    ans += 100*(10-n);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<math.h>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a < b && c  < b)
		cout << a+c;
	else if(b < a && c < a)
		cout << b+c;
	else
		cout << a+b;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
 
int main(){
 
  int a, b, c;
  cin >> a >> b >> c;
  
  cout << c << " " << a << " " << b;
  
  
  
}

Measured memory_bytes: 3556
//https://atcoder.jp/contests/abc148/tasks/abc148_e
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
    ll n;cin>>n;
    ll ans=0;
    if(n&1) cout<<0<<endl;
    else
    {
        n/=2;
        while(n)
        {
            n/=5;
            ans+=n;
        }
        cout<<ans<<endl;
    }
    
}


Measured memory_bytes: 3576
import numpy as np

k = int(input())


# ルンルン数で無くても二分探索を怖れない
def check(n):
    digits = []
    while n:
        n, m = divmod(n, 10)
        digits.append(m)
    digits.reverse()

    dp = np.zeros(10, dtype=np.int64)
    dp[1:digits[0]] = 1
    edge = digits[0]
    for d in digits[1:]:
        odp = dp.copy()
        dp[:-1] += odp[1:]
        dp[1:] += odp[:-1]
        dp[1:] += 1
        if edge != -1:
            if edge - 1 > d:
                edge = -1
            elif edge + 1 >= d:
                dp[max(0, edge - 1):d] += 1
                edge = d
            else:
                dp[max(0, edge - 1):edge + 2] += 1
                edge = -1
    result = dp.sum()
    if edge != -1:
        result += 1
    return result >= k


l = 0
r = 3234566667
while l + 1 < r:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)


Measured memory_bytes: 20268
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>

void skip(const std::string &s, size_t &i, bool out) {
  if (s[i] == ',') return;
  assert(s[i] == '(');
  size_t opened=1;
  ++i;
  if (out) printf("(");

  while (opened) {
    if (s[i] == '(') ++opened;
    if (s[i] == ')') --opened;
    if (out) printf("%c", s[i]);
    ++i;
  }
}

void fourt(
    const std::string &s, size_t &i, const std::string &t, size_t &j, 
    char op) {

  assert(s[i] == '(' && t[j] == '(');
  ++i;
  ++j;
  printf("(");
  if (s[i] == ',' && t[j] == ',') {
  } else if (s[i] == ',') {
    skip(t, j, (op == 'u'));
  } else if (t[j] == ',') {
    skip(s, i, (op == 'u'));
  } else {
    fourt(s, i, t, j, op);
  }

  printf(",");
  assert(s[i] == ',' && t[j] == ',');
  ++i;
  ++j;
  if (s[i] == ')' && t[j] == ')') {
  } else if (s[i] == ')') {
    skip(t, j, (op == 'u'));
  } else if (t[j] == ')') {
    skip(s, i, (op == 'u'));
  } else {
    fourt(s, i, t, j, op);
  }

  printf(")");
  ++i;
  ++j;
}

int testcase_ends() {
  char op;
  if (scanf(" %c", &op) == EOF)
    return 1;

  char buf[384];
  scanf("%s", buf);
  std::string s=buf;
  scanf("%s", buf);
  std::string t=buf;

  size_t i=0, j=0;
  fourt(s, i, t, j, op);
  printf("\n");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2740
import std.stdio, std.algorithm, std.range, std.array, std.conv, std.string, std.math, std.container, std.typecons;

void main() {
    auto a = readln.chomp.to!int;
    auto b = readln.chomp.to!int;
    auto c = readln.chomp.to!int;
    auto x = readln.chomp.to!int;
    int cnt = 0;
    foreach (i; 0..min(x/500,a)+1) {
        foreach (j; 0..min((x-500*i)/100,b)+1) {
            auto res = x-500*i-100*j;
            if (res % 50 == 0 && res/50 <= c) {
                cnt++;
            }
        }
    }
    writeln(cnt);
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: Chars,
    }

    let mut count: usize = 0;
    for i in 0 .. n {
        if s[i] == 'R' { count += 1 };
    }

    let mut ans = 0;
    for i in 0 .. count {
        if s[i] == 'W' { ans += 1};
    }

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


Measured memory_bytes: 3048
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int flag[15];

void dfs(int depth);

int len;
char S[15];

typedef long long ll;

ll sum;

ll tolonglong(string s);

int main(){

	scanf("%s",S);

	len = strlen(S);

	sum = 0;
	dfs(0);
	printf("%lld\n",sum);

	return 0;
}
void dfs(int depth) {
	if (depth == len - 1) {
		int i = 0;
		string add = "";
		int flag2 = 0;
		ll add2 = 0;

		while (1) {

			if (flag2 == 1) { break; }

			add = "";
			while (1) {
				if (i == depth + 1) { flag2 = 1; break; }
				if (flag[i] == 1) {
					add += S[i];
					i++;
					break;
				}
				add += S[i];
				i++;
			}

			add2 += tolonglong(add);
		}
		sum += add2;
		return;
	}

	flag[depth] = 1;
	dfs(depth + 1);
	flag[depth] = 0;
	dfs(depth + 1);

}
ll tolonglong(string s) {
	int i;

	ll r = 0;

	ll ten[20];

	ten[0] = 1;

	for (i = 0; i < 19; i++) {
		ten[i + 1] = ten[i] * 10;
	}

	for (i = 0; i < s.size(); i++) {
		ll a = (ll)(s[i] - '0');
		r += a*ten[s.size() - 1 - i];
	}
	return r;
}

Measured memory_bytes: 256
S=input()
ls=[int(ss) for ss in S]
ans=0
for i in range(2**(len(S)-1)):
    #lnum=[]
    #while :#足す項
    #while i&1
    num=ls[0]
    for j in range(len(S)-1):
        if i&1:
            ans+=num
            num=ls[j+1]
            #i=i>>1
            i>>=1
        else:
            num=10*num+ls[j+1]
            i>>=1
    ans+=num

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
int i,j,k;
  int ans=100000000;
  int N;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++)
    scanf("%d ",&A[i]);
  
  for(i=1;i<=100;i++){
    k=0;
    for(j=0;j<N;j++){
      k+=(i-A[j])*(i-A[j]);
    }
    if(k<ans)
      ans=k;
  }
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int k;
	scanf("%d",&k);
	if(k==1){puts("1\n1"); return 0;}
	int n=2*((k+3)/4);
	printf("%d\n",n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)printf("%d ",((i&1)&&(i+j)%n+n<k?(i+j)%n+n:(i+j)%n)+1);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1152
object Main extends App {
  val s = readLine  
  val list = Seq("dream", "dreamer", "erase", "eraser")
  
  def check(str: String): Boolean = {
    val index = list.indexWhere(str.endsWith)

    if (str.isEmpty) true
    else if (index == -1) false
    else check(str.dropRight(list(index).length))
  }
  
  val result = check(s)
  println(if (result) "YES" else "NO")
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(100010);
    rep(i, 0, n) {
        ll a, b;
        cin >> a >> b;
        if (a > m) continue;
        v[a].push_back(b);
    }
    ll ans = 0;
    priority_queue<ll> pq;
    for (int i = 1; i <= m; i++) {
        for (auto j : v[i]) {
            pq.push(j);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5632
a,b,c,d = gets.chomp.split(" ").map(&:to_i)
answer = 0
#main
if ( c >= a && c < b ) then
    if b >= d then
        answer = d - c
    else
        answer = b - c 
    end

elsif ( a >= c && a < d ) then
    if d >= b then
        answer = b - a
    else
        answer = d - a
    end
else
    answer = 0
end

print ("#{answer}\n")

Measured memory_bytes: 3836
N,M=map(int,input().split())
red=[2]+[0 for _ in range(1,N)]
num=[1]*N

for _ in range(M):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if red[x]>0:
        if num[x]==1:
            red[y]=red[x]
            red[x]=0
        else:
            red[x]=1
            red[y]=1
    num[x]-=1
    num[y]+=1

print(len([True for r in red if r>0]))

Measured memory_bytes: 54048
from math import factorial
from itertools import permutations

N = int(input())

M = factorial(N)


primes = [True for _ in range(N + 1)]
primes[0] = primes[1] = False
for i in range(2, N + 1):
    if primes[i]:
        for j in range(2 * i, N + 1, i):
            primes[j] = False


# m >= k^i を満たす最大のiを返す
def f(m, k):
    return (
        1 + f(m // k, k) if m % k == 0 else
        0
    )


# 素因数分解した結果に着目して、七五数になるパターンごとに数え上げ
C = [f(M, k) for k in range(2, N + 1) if primes[k]]
ans = (
    sum(c >= 74 for (c,) in permutations(C, 1)) +
    sum(c1 >= 24 and c2 >= 2 for (c1, c2) in permutations(C, 2)) +
    sum(c1 >= 14 and c2 >= 4 for (c1, c2) in permutations(C, 2)) +
    sum(
        c1 >= 4 and c2 >= 4 and c3 >= 2
        for (c1, c2, c3) in permutations(C, 3)
    ) // 2
)

print(ans)


Measured memory_bytes: 3064
n,m,c  = input().split()
n = int(n)
m = int(m)
c = int(c)

b_list_str = input().split()
b_list = [int(s) for s in b_list_str]

a_matrix_str = []
for i in range(n):
    a_list_str = input().split()
    a_matrix_str.append(a_list_str)

a_matrix = []

for i in range(n):
    a_matrix.append([int(s) for s in a_matrix_str[i]])

count_ans = 0
for i in range(n):
    if sum([a*b for a,b in zip(a_matrix[i], b_list)]) + c > 0:
        count_ans += 1

print(count_ans)



Measured memory_bytes: 3064
h, w = map(int, input().split())
tanpen = min(h, w)
chohen = max(h, w)

if h%3 == 0 or w%3 == 0:
    print(0)
else:
    def findmin(h, w):
        ans = h*w
        for i in range(1, h):
            remi = h - i
            s1 = i*w
            s2 = (w//2) * remi
            s3 = (w - w//2) * remi
            ans = min(ans, max(s1, s2, s3) - min(s1, s2))

            s2 = w * (remi//2)
            s3 = w * (remi - remi//2)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2))
        return ans
    print(min(findmin(h, w), findmin(w, h)))


Measured memory_bytes: 9224
import sys
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
if N >= M:
    print(0)
    sys.exit()
X = [int(_) for _ in stdin.readline().rstrip().split()]
X.sort()
diffs = [X[i+1]-X[i] for i in range(M-1)]
diffs.sort()
print(sum(diffs[:M-N]))

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

int main() {
   int x , a , b ;
  cin >> x >> a >> b ;
  
  int A = abs(x-a) ;
  int B = abs(x-b) ;
  
  if(A>=B) cout << "B" << endl;
  else cout << "A" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  ll prod = 1;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  all(sort, A);
  if (A[0] == 0) {
    cout << "0\n";
    return 0;
  }
  rep(i, N) {
    if (prod > 1000000000000000000LL / A[i]) {
      cout << "-1\n";
      return 0;
    }
    prod *= A[i];
    if (prod > 1000000000000000000LL) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << prod << endl;

  return 0;
}


Measured memory_bytes: 3988
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
string en="\n";
string t="hello";
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isVowel(char ch)
{
    ch=toupper(ch);
    if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E')
        return true;
    return false;
}
int toInt(string s)
{
    int sm;
    stringstream ss(s);
    ss>>sm;
    return sm;
}
template<typename T>inline T gcd(T a,T b)
{
    if(a<0)
        return gcd(-a,b);
    if(b<0)
        return gcd(a,-b);
    return (b==0)?a:gcd(b,a%b);
}
template<typename T>inline T lcm(T a,T b)
{
    if(a<0)
        return lcm(-a,b);
    if(b<0)
        return lcm(a,-b);
    return a*(b/gcd(a,b));
}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>i>>j)
    {
    string ss;
    vs a;
        rep(k,i)
        {
            cin>>ss;
            a.pb(ss);
        }
        j+=2;
        rep(k,j)
        {
            cout<<"#";
        }
        cout<<en;
        rep(k,i)
        {
            cout<<"#";
            cout<<a[k];
            cout<<"#";
            cout<<en;
        }
        rep(k,j)
        {
            cout<<"#";
        }
        cout<<en;

    }
}



Measured memory_bytes: 256