akhauriyash/Code-Regression huggingface dataset:
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-08-26 09:22:22
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 61;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll l , r , ind , ans;

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

	cin >> l >> r;
	for(int i = LOG ; i >= 0 ; i--){
		if((l & (1ll << i)) & (r & (1ll << i))){
			l ^= (1ll << i);
			r ^= (1ll << i);
		}
		else if(r & (1ll << i)){
			ind = i;
			break;
		}
	}
	
	int flag = 0;
	for(int i = ind - 1 ; i >= 0 ; i--){
		if(r & (1ll << i)){
			flag = 1;
			continue;
		}
		if(flag){
			ans += (1ll << i);
			continue;
		}
		ans += min((1ll << i) , max(0ll , (1ll << i) * 2 - l));
	}
	//cout << ind << sep << ans << endl;
	cout << ans + r - l + 1 << endl;
		
    return 0;
}
/*

*/


Measured memory_bytes: 3648
#include<stdio.h>

static const int N = 100;

int main(){
  int n,i,j,k;
  int min;
  int temp;
  int count=0;
  int A[N];

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

  /*selection sort*/
  for(i=0;i<n-1;i++){
    min=A[i];
    k=i;
    for(j=i+1;j<n;j++){
      if(A[j]<min){
      min=A[j];
      k=j;
      }
    }
    if(A[i]!=A[k]){
      count++;
      temp=A[i];//
      A[i]=A[k];//swap
      A[k]=temp;//
    }
  }

  /*printf data*/
  printf("%d",A[0]);
  for(i=1;i<n;i++)printf(" %d",A[i]);
  printf("\n%d\n",count);
  return 0;
}

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

using namespace std;

#define lli long long int

#define ulli unsigned long long int

#define Pi 3.14159265358979323846264338327950288419716939937510

int main(){
	
    ios :: sync_with_stdio(false);
   
    //ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
    
    double l;
    
    cin>>l;
    
    cout<<setprecision(25)<<(l*l*l)/(27.0);
}

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

int main( void )
{
  double d, t, s;
  double ans;

  cin >> d >> t >> s;

  ans = t - ( d / s );

  if( ans >= 0 )
    cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

int main()
{
	uint32_t N, M;
	int32_t x, prev_x;
	priority_queue<int32_t> X, Dist;
	uint32_t ans = 0;

	cin >> N >> M;

	for (uint32_t i = 0; i < M; i++)
	{
		cin >> x;
		X.push(x);
	}

	// 指定されたマス間の距離を求める
	prev_x = X.top();
	X.pop();
	while (!X.empty())
	{
		x = X.top();
		X.pop();
		Dist.push(prev_x - x);
		prev_x = x;
	}

	// コマの数だけ距離の大きな値をスキップできる
	for (uint32_t i = 0; i < N - 1; i++)
	{
		if (!Dist.empty())
		{
			Dist.pop();
		}
	}
	while (!Dist.empty())
	{
		ans += Dist.top();
		Dist.pop();
	}

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

Measured memory_bytes: 1400
def main():
    N, K = map(int, input().split())
    S = input()
    seq = []
    current = "1"
    cnt = 0
    # 初手が0だと0の累積和が最初に入る(e.g. [1,2,1]が[0,1,2,1]となる)
    # ex. 0001011ならseq = [3,1,1,2] (0が3つ,1が1つ,0が2つ,1が2つ)
    for c in S:
        if c == current:
            cnt += 1
        else:
            seq.append(cnt)
            current = c
            cnt = 1
    seq.append(cnt)  # 切り替えのあったタイミングで初めて挿入されるので、最後のカウントは挿入されていないので、ここで入れる
    if len(seq) % 2 == 0:
        seq.append(0)  # 0挿入なので、大勢には影響しない。理由は不明。

    # K1回で2つの切り替え00010001 = [3,1,3,1]=>右の0３つを変えると=>[3,4]となる
    # 現在seqに格納されているのは切り替えデータだからK*2+1以内なら、全て1になる
    if len(seq) <= K*2+1:
        print(sum(seq))
        return
    ans = 0
    total = 0
    j = 0
    # Kで２つseqが消える→rangeはそれを差し引いた回数
    # 2Kの範囲でseqを前から進めていくansが最大となるものをキープし、出力する

    for i in range(len(seq)-K*2):
        while j < i+K*2+1:
            total += seq[j]
            j += 1
        if i % 2 == 0:
            ans = max(ans, total)
        total -= seq[i]  # 今回のtotalは既にキープしてあるので、動いて消える部分は取り除く
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45552
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

a, b = readline().rstrip().decode('utf-8').split()
N = int(a + b)

LIM = 10 ** 7
for i in range(1, LIM):
    tmp = i * i
    if tmp == N:
        print('Yes')
        exit()
    if tmp > N:
        print('No')
        exit()
    

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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b / gcd(a,b) ;}


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}


ll r, x, d;

int main(){
  cin >> r >> d >> x;
  for(int i = 0 ; i < 10 ; i++){
    x = r*x-d;
    cout << x << endl;
  }
  return 0;
}


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

const int INF = (int)1e9;

int solve(int E) {
    int res = INF;
    for(int y = 0; y*y <= E; y++) {
        for(int z = 0; y*y + z*z*z <= E; z++) {
            if(res > y + z + E - y*y - z*z*z) {
                res = y + z + E - y*y - z*z*z;
            }
        }
    }
    return res;
}

int main() {
    for(int E; cin >> E, E; ) {
        cout << solve(E) << endl;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main( void )
{
    string S;
    cin >> S;

    int flag_pre = -1;
    int flag_back = -1;

    int tmp;
    tmp = stoi(S.substr(0,2));
    if(tmp >= 1 && tmp <= 12){
        flag_pre = 0;
    }else{
        flag_pre = 1;
    }

    tmp = stoi(S.substr(2,2));
    if(tmp >= 1 && tmp <= 12){
        flag_back = 0;
    }else{
        flag_back = 1;
    }

    if(flag_pre == 0 && flag_back == 0){
        cout << "AMBIGUOUS";
    }else if(flag_pre == 0 && flag_back == 1){
        cout << "MMYY";
    }else if(flag_pre == 1 && flag_back == 0){
        cout << "YYMM";
    }else if(flag_pre == 1 && flag_back == 1){
        cout << "NA";
    }

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ret;
  if (n <= k){
    ret = n * x;
  } else {
    ret = k * x + (n - k) * y;
  }
  cout << ret << endl;
  return 0;
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int>v(N);
    vector<int>x(N);
    vector<int>y(N);

    for (int i = 0; i < N; i++) {
        v[i] = i;
        cin >> x[i] >> y[i];
    }

    int a = 1;
    int k = N;
    while (k > 0) {
        a *= k;
        k--;
    }
    double len = 0;
    do {
        for (int i = 1; i < N; i++) {
            len += sqrt(pow(x[v[i]]-x[v[i-1]], 2) + pow(y[v[i]]-y[v[i-1]], 2));
        } 
    } while (next_permutation(v.begin(), v.end()));

    printf("%.10f\n", len/(double)a);
}


Measured memory_bytes: 3840
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 300000;
const int K = 19;
int used[N], c[N], d[N], ans[N], u[N], v[N], in[N], deg[N];
vector < pair < int, pair < int, int > > > g[N];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n;
    vector < pair < int, int > > e;
    for (int i = 1; i <= n; i++){
        int x, l;
        cin >> x >> l;
        e.pb({x + l, x - l});
    }
    sort(e.begin(), e.end());
    int r = -1e9 - 1;
    int ans = 0;
    for (auto i: e){
        if (i.S >= r){
            ans++;
            r = i.F;
        }
    }
    cout << ans;
}


Measured memory_bytes: 9592
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main()
{
    int i=0,count=0;
    char d[100000];
    scanf("%s",d);
    if(d[1]=='\0')
    {
        printf("0");
    }
    else
    {
        for(i=1;d[i]!='\0';i++)
        {
            if(d[i]==d[i-1]&&d[i-1]=='0')
            {
                d[i]='1';
                count++;
            }
            if(d[i]==d[i-1]&&d[i-1]=='1')
            {
                d[i]='0';
                count++;
            }
        }
        printf("%d",count);
    }
}


Measured memory_bytes: 256
/**
 * Author: Behradm
 * Created: 27-04-2020 20:54:49
 * In the Name of God
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout.tie(0);
	cout.precision(6);
	int n;
	cin >> n;
	set<string> s;
	for (int i = 0; i < n; i++){
		string t;
		cin >> t;
		s.insert(t);
	}

	cout << (int) s.size() << '\n';
	return 0;
}



Measured memory_bytes: 19180
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <string>

typedef long long ll;

using namespace std;

string toLower(string s){
    string t = "";
    for(auto itr = s.begin(); itr < s.end(); itr++){
        t += tolower(*itr);
    }
    return t;
}

void solve(){
    string w, t;
    int count = 0;
    cin >> w;

    while(cin >> t && t != "END_OF_TEXT"){
        if(toLower(t) == toLower(w)){
            count++;
        }
    }
    cout << count << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3200
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static Page[] buffer = new Page[100001];

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			Arrays.fill(buffer, null);
			int W = sc.nextInt();
			int H = sc.nextInt();
			Page[] pages = new Page[N];
			HashMap<String, Integer> map = new HashMap<String, Integer>();
			for (int i = 0; i < N; ++i) {
				String name = sc.next();
				map.put(name, i);
				int b = sc.nextInt();
				pages[i] = new Page(name, b);
				for (int j = 0; j < b; ++j) {
					int x1 = sc.nextInt();
					int y1 = sc.nextInt();
					int x2 = sc.nextInt();
					int y2 = sc.nextInt();
					pages[i].button[j] = new Rectangle(x1, y1, x2 - x1, y2 - y1);
					pages[i].linkTo[j] = sc.next();
				}
			}
			int bp = 0;
			buffer[0] = pages[0];
			int M = sc.nextInt();
			for (int i = 0; i < M; ++i) {
				String q = sc.next();
				if (q.equals("click")) {
					int x = sc.nextInt();
					int y = sc.nextInt();
					for (int j = 0; j < buffer[bp].button.length; ++j) {
						Rectangle rect = buffer[bp].button[j];
						if (rect.x <= x && x <= rect.getMaxX() && rect.y <= y && y <= rect.getMaxY()) {
							for (int k = bp + 1; k < buffer.length && buffer[k] != null; ++k) {
								buffer[k] = null;
							}
							buffer[bp + 1] = pages[map.get(buffer[bp].linkTo[j])];
							++bp;
							break;
						}
					}
				} else if (q.equals("back")) {
					if (bp > 0) --bp;
				} else if (q.equals("forward")) {
					if (bp < buffer.length - 1 && buffer[bp + 1] != null) ++bp;
				} else if (q.equals("show")) {
					System.out.println(buffer[bp].name);
				}
			}
		}
	}

	static class Page {
		Rectangle[] button;
		String[] linkTo;
		String name;

		Page(String name, int buttonCount) {
			this.name = name;
			this.button = new Rectangle[buttonCount];
			this.linkTo = new String[buttonCount];
		}
	}

}

Measured memory_bytes: 14000
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(n);trav(i,a)i=in();
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==i+1)
		{
			if(i<n-1)swap(a[i],a[i+1]);
			else swap(a[i],a[i-1]);
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
  ll X;
  cin>>X;

  rep(i, 120){
    rep(j, 120){
      ll A = pow(i, 5);
      ll B = pow(j, 5);
      // cout<<j<<":"<<A+B<<" "<<A-B<<endl;
      if(A-B == X) {cout<<i<<" "<<j<<endl; return 0;}
      else if (A+B==X){cout<<i<<" "<<-j<<endl; return 0;}
    }
    // if(i==3) break;
  }

}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
  ll n;
  cin>>n;
  if(n==1)cout<<"Hello World"<<endl;
  else{
    ll x,y;
    cin>>x>>y;
    cout<<x+y<<endl;
  } 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }


int solve(int a, int b, int n) {
	int ret = 0; a *= 10;
	for_(i, 0, n) {
		ret += (a/b)%10;
		a %= b;
		a *= 10;
	}
	return ret;
}

int main() {
	int a, b, n;
	while (cin>>a>>b>>n) {
		cout << solve(a, b, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;
	
int N, x, a, b;
int cnt = 0;


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

	
	cin >> N;
	PQ A;
	priority_queue<int, vector<int>, greater<int> > B;
	int asum = 0, bsum = 0;
	REP(i, N) {
		cin >> x;
		if (x == 1) {
			cin >> a >> b;
			cnt += b;
			int t;

			if (A.size() > B.size()) {//後ろに入れる
				t = A.top();

				if (t <= a) {
					B.push(a);
					bsum += a;
				}
				else {
					asum -= A.top();
					bsum += t;
					asum += a;
					A.pop();
					B.push(t);
					A.push(a);
				}
			}
			else {//前に入れる
				if (B.empty()) {
					A.push(a);
					asum += a;
					continue;
				}
				t = B.top();
				if (a <= t) {
					A.push(a);
					asum += a;
				}
				else {
					bsum -= B.top();
					bsum += a;
					asum += t;
					B.pop();
					B.push(a);
					A.push(t);
				}
				
			}

		}
		else {
			cout << A.top() << " ";

			cout << (A.top()*(int)A.size() - asum) + (bsum - A.top()*(int)B.size()) + cnt << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3828
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int a[100020];
long long n,s,w,q,cnt[100020];

int main()
{
   long long ans,temp,num,mul;

    scanf("%lld%lld%lld%lld",&n,&s,&w,&q);
    while(n!=0)
    {

        long long g = s;
        ans=0;
        num=0;
        for(int i=1; i<=n; i++)
        {
            a[i] = (g/7) % 10;
            if( g%2 == 0 )
            {
                g = (g/2);
            }
            else
            {
                g = (g/2) ^ w;
            }
        }
        if((q!=2)&&(q!=5))
        {
        map<int,int>sum;
        cnt[0]=0;
        mul=1;
        for(int i=1;i<=n;i++)
        {
            cnt[i]=cnt[i-1];
            cnt[i]+=a[n+1-i]*mul;
            cnt[i]%=q;
            mul*=10;
            mul%=q;
        }

        //for(int i=1;i<=n;i++)
            //printf("%d ",cnt[i]);

        sum[0]=1;
        for(int i=1;i<=n;i++)
        {
            if(a[n+1-i])ans+=sum[cnt[i]];
            sum[cnt[i]]++;
        }
        printf("%lld\n",ans);}
        else
        {
            temp=0;
            for(int i=1;i<=n;i++)
            {
                if(a[n+1-i]%q==0)temp++;
                if(a[n+1-i])ans+=temp;
            }
            printf("%lld\n",ans);
        }

        scanf("%lld%lld%lld%lld",&n,&s,&w,&q);
    }
    return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,a[maxn];
ll s1[maxn<<1],s2[maxn<<1],ans=0;
inline void add(int l,int r){
	s1[l]+=1-l;s1[r+1]+=l-1;
	++s2[l],--s2[r+1];
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=n;++i) a[i]=read();
	for (int i=1;i<n;++i){
		if (a[i]==a[i+1]) continue;
		else if (a[i]<a[i+1]) add(a[i]+2,a[i+1]),ans+=a[i+1]-a[i];
		else add(a[i]+2,a[i+1]+m),ans+=a[i+1]+m-a[i];
	}
	for (int i=1;i<=2*m;++i) s1[i]+=s1[i-1];
	for (int i=1;i<=2*m;++i) s2[i]+=s2[i-1];
	ll mx=0;
	for (int i=1;i<=m;++i) mx=max(mx,s1[i]+s2[i]*i+s1[i+m]+s2[i+m]*(i+m));
	printf ("%lld\n",ans-mx);
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
  int unused __attribute__((unused));
  int i = 0, len = 0;
  char s[11], scr[11] = {' '};
  unused = scanf("%s", s);

  while(s[i]!='\0'){
    if(s[i]=='0'){
      scr[len] = '0';
      len++;
    }else if(s[i]=='1'){
      scr[len] = '1';
      len++;
    }else if(s[i]=='B'){
      scr[len] = ' ';
      if(len>0) len--;
    }
    i++;
  }
  for(i=0; i<len; i++) printf("%c", scr[i]);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int hani[21][21];
	int n,m;
	int x,y;
	int i,j;
	int iti_x,iti_y;
	int ryou;
	int ok = 0;
	int ii,jj;
	char get[10];
	char muki;
	
	while(1){
		ok = 0;
		iti_x = iti_y = 10;
		for(i = 0;i < 21;i++){
			for(j = 0;j < 21;j++){
				hani[i][j] = 0;
			}
		}
		
		scanf("%d",&n);
		//printf("=1=\n");
		if(n == 0)break;
		for(i = 0;i < n;i++){
			scanf("%d %d",&x,&y);
			hani[20 - y][x] = 1;
		}

		
		
		
		//printf("=2=\n");
		scanf("%d",&m);
		for(j = 0;j < m;j++){
			scanf("%*c");
			scanf("%c %d",&muki,&ryou);
			
			switch(muki){
				case 'N':
				for(i = iti_y;i >= (iti_y - ryou);i--)hani[i][iti_x] += 2;
				iti_y = i + 1;
				break;
				case 'E':
				for(i = iti_x;i <= (iti_x + ryou);i++)hani[iti_y][i] += 2;
				iti_x = i - 1;
				break;
				case 'W':
				for(i = iti_x;i >= (iti_x - ryou);i--)hani[iti_y][i] += 2;
				iti_x = i + 1;
				break;
				case 'S':
				for(i = iti_y;i <= (iti_y + ryou);i++)hani[i][iti_x] += 2;
				iti_y = i - 1;
				break;
				
				
			}
			
		}
		for(i = 0;i < 21;i++){
			for(j = 0;j < 21;j++){
				if(hani[i][j] == 1 && ok != 1){
					
					printf("No\n");
					ok = 1;
				}
			}
		}
		
	if(ok == 0)printf("Yes\n");
		
	}//WhileLoop
	
	
	return 0;
}

Measured memory_bytes: 584
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, D = lr()
A = [lr() for _ in range(H)]
Q = ir()
mul = H*W//D + 1 # Xの横幅
X = np.zeros((D, mul), np.int32)
Y = np.zeros((D, mul), np.int32)

for i in range(H):
    for j in range(W):
        q, r = divmod(A[i][j], D)
        X[r, q] = j
        Y[r, q] = i

magic = np.zeros_like(X)
magic[:, 1:] = (np.abs(np.diff(X, axis=1)) + np.abs(np.diff(Y, axis=1))).cumsum(axis=1)

for i in range(Q):
    l, r = lr()
    q1, r1 = divmod(l, D)
    q2, r2 = divmod(r, D)
    answer = magic[r2, q2] - magic[r1, q1]
    print(answer)


Measured memory_bytes: 19908
def main():
    from collections import deque
    import sys

    input = sys.stdin.readline

    def dfs(s) -> list:
        init = n

        d = [init] * n
        d[s] = 0

        q = deque()
        q.append(s)
        while q:
            v = q.popleft()
            for u in g[v]:
                if d[u] != init:
                    continue
                d[u] = d[v] + 1
                q.append(u)

        return d

    n = int(input())

    g = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add(b)
        g[b].add(a)

    dist_1 = dfs(0)
    dist_n = dfs(n - 1)

    fennec = sum(dist_1[v] <= dist_n[v] for v in range(n))
    snuke = n - fennec

    if fennec > snuke:
        print('Fennec')
    else:
        print('Snuke')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,p[1000005],M[1000005],beg,sum;
ll ans=1;
int x[1000005];
int main(){
	cin>>n;
	rep(i,n) cin>>p[i];
	rep(i,n){
		int a = p[i]-i*2;
		if(a>=1) beg++,sum++;
		else break;
	}
	rep(i,n){
		ans = ans*1LL*(beg==n?sum:(1+sum))%mod;
		while(beg<n && p[beg]-(beg-i-1)*2 >=1){
			beg++; sum++;
		}
		sum--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6400
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}
class Array
  define_method(:sum){self.inject(:+).to_i} unless method_defined?(:sum)
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, M = gets_i_list

k_list = []
M.times do
  l = gets_i_list
  l.shift
  k_list.push l
end
p_list = gets_i_list
total = 0

[0,1].repeated_permutation(N) do |pattern|
  ret = true
  M.times do |i|
    p = p_list[i]
    switches = k_list[i]
    count = switches.map do |k|
      pattern[k-1]
    end.sum

    unless count % 2 == p
      ret = false
      break
    end
  end
  total += 1 if ret
end

puts total

Measured memory_bytes: 2556
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    let t: String = input();
    let t: Vec<char> = t.chars().collect();
    let mut chars: Vec<char> = s.chars().collect();
    for _ in 0..chars.len() {
        let last: char = chars.pop().unwrap();
        chars.insert(0, last);
        if chars == t {
            println!("Yes");   
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    //cant wait for holiday
//    string days[7] ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
//    string s;
//    int n;
//    cin>> s;
//    for (int i = 0; i< 7; i++){
//        if (s== days[i]){
//            n = i;
//        }
//    }
//    n = 7-n;
//    cout<< n;
    //day before christmas eve
    int a=0, b;
    int n;
    cin>> n;
    int prices[n];
    for (int i = 0; i< n; i++){
        cin>> prices[i];
    }
    for (int i = 0; i< n; i++){
        //find the greatest number and the index
        if (prices[i]>=a){
            a = prices[i];
            b = i;
        }
    }
    //b is index, a is value
    a = 0; // a will now be the sum
    prices[b] /=2;
    for (int i =0 ; i< n; i++){
        a+=prices[i];
    }
    cout<< a;
    return 0;
}

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

namespace my {
/*汎用*/
template <typename T>
void input_vec(vector<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_vec" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  if (!a.empty()) {
    cout << "error in input_set" << endl;
    exit(1);
  }
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }

/*整数*/
ll gcd(ll a, ll b) {  // O( log(max(a,b)) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(max(a,b)) )
ll modinv(ll n, ll mod) {                               // O( log(max(n,mod)) )
  if (mod < 0 || my::gcd(n, mod) != 1) {
    cout << "error in modinv" << endl;
    exit(1);
  }
  n %= mod;
  if (n < 0) n += mod;
  ll a = mod, b = n, x = 1, y = 0;
  while (b != 0) {
    ll q = a / b, r = a % b;
    a = b;
    b = r;
    y -= q * x;
    swap(x, y);
  }
  y %= mod;
  if (y < 0) y += mod;
  return y;
}

bool isPrime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////////////////////////////

int main() {
  const ll M = 1e9 + 7;
  int n;
  cin >> n;
  vector<ll> a;
  my::input_vec(a, n);

  ll sum = 0;
  for (auto &ai : a) sum += ai;
  ll ans = 0;
  for (auto &ai : a) {
    ans += ai * ((sum - ai) % M);
    ans %= M;
  }
  ans *= my::modinv(2, M);
  ans %= M;
  cout << ans << endl;
}

Measured memory_bytes: 5276
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 1e6 + 5;
const int oo = 1e9 + 5;
const LL ooll = 1e18 + 5;
 
// clock_t start = clock();

int v[N];
void solve() {
	int n, k;
	cin >> n >> k;
	for (int i=0;i<n;++i) cin >> v[i];
	int lo = 1, hi = 1e9;
	while(lo < hi) {
		int m = (lo + hi) / 2;
		LL need = 0;
		for (int i=0;i<n;++i) need += (v[i] + m - 1) / m - 1;
		if (need <= k) hi = m;
		else lo = m + 1;
	}
	cout << hi << '\n';
}
 
int main() {
	FASTIO;
	int T = 1;
	// cin >> T;
	while(T--) {
		solve();
	}
	// cout << fixed << setprecision(10);
	// cout << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
	return 0;
} 

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

namespace ConsoleApp5
{
    class Program
    {
        int n;
        int inf = 1050000000;
        int[] kek;
        int result;
        int summ;
       
        double m,k,f;
        bool[,] pairs;
        int[,] g;
        List<int> tank;
        string a, b;
        char tmp;
        List<string> used;
        Dictionary<char, List<int>> tank1;
        int ans;

        public void Run()
        {
            n = int.Parse(Console.ReadLine());
                var Elems = Console.ReadLine().Split().Select(double.Parse).ToArray();
                k = Elems[0];
                m = Elems[1];
            Elems = Console.ReadLine().Split().Select(double.Parse).ToArray();
            double av = 2100000000;
            int index=-1;
            for (int i = 0; i<n; i++)
            {
                if (Math.Abs(k-Elems[i] * 0.006 - m)<av)
                {
                    av = Math.Abs(k - Elems[i]*0.006 - m);
                    index = i;
                }
            }
            Console.WriteLine(index+1);
        }

        
       
        void GoS(int i)
        {
        }

        /* string Kek(int i)
        {
            if (i == 1) return dp[1].ToString() + "+"+n;
            return "(" + Kek(i - 1) + ")" + dp[i].ToString() +"+"+ (n - i + 1).ToString();
        }
*/
        static void Main(string[] args)
        {
                    new Program().Run();
        }
    }
}


Measured memory_bytes: 13312
#include <stdio.h>

int main()
{
  int aj, am, as, ae, bj, bm, bs, be, S, T;

  scanf("%d %d %d %d", &aj, &am, &as, &ae);

  scanf ("%d %d %d %d", &bj, &bm, &bs, &be);

  S = aj + am + as + ae;
  T = bj + bm + bs + be;

  if (T == S){
    printf("%d\n", S);
  }else if (T > S){
    printf ("%d\n", T);
  }else if (T < S){
    printf("%d\n", S);
  }

  return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> s;
    if (s == "ABC") MSG("ARC")
    else MSG("ABC")
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int>p(n);
    for(int i=0;i<n;i++)cin >> p[i];
    sort(p.begin(),p.end());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=p[i];
    }
    cout << ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	double s;
	cin>>s;
	//cout<<n;
	double length=s/3.0;
	s=s-length;
	double breadth = s / 2.0; 
  
    // finding height 
   	double height = s - breadth; 
  
    cout<<fixed<<setprecision(12)<<(length * breadth * height)<<endl; 
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 ) 
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vstr s(n+1);
    rep(i,n)cin>>s[i];
    s[n]="zzzzzzzzzzzzzzzzzzzzzzzzz";
    rep(i,n)sort(all(s[i]));
    sort(all(s));
    ll sum=0;
    ll tmp=1;
    rep(i,n){
        if(s[i]==s[i+1])tmp++;
        else{
            sum+=tmp*(tmp-1)/2;
            tmp=1;
        }
    }
    cout<<sum<<endl;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;

int main() {
    int N, R;
    cin >> N >> R;
    cout << (N < 10 ? R + 100 * (10 - N) : R) << endl;
    return 0;
}

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

int main(){
   int N,M,a,b;
   cin >> N >> M;
    vector<int> vec(N);
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--;
        b--;
        vec[a]++;
        vec[b]++;
    }
    for (int i = 0; i < N; i++) {
        cout << vec[i] << endl;
    }
}


Measured memory_bytes: 256
X = list(input())
L = len(X)

if len(X) < 3:
    print(0)
    exit()

mon1 = 10*int(X[-2]) + int(X[-1])
mon2 = 0

for i in range(L-2):
    mon2 += int(X[i]) * 10 ** (L-i-1)

a = 0
for i in range(5,0,-1):
    b = mon1 % i
    a += (mon1 - b) / i
    mon1 = mon1 % i

if a > mon2 // 100:
    print(0)
else:
    print(1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

int main() {
    std::string s;
    std::cin >> s;
    std::sort(ALL(s));
    std::cout << (s.front() == s.back() ? "No" : "Yes") << '\n';
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var n = parseInt(tmp[0], 10);
    var r = parseInt(tmp[1], 10);
  //  console.log(n,r);

    if(n>=10){var ans=r;
             console.log(ans);}
        else {var b=100*(10-n);
              var   ans=r+b;
              console.log(ans)}     
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
#include <unordered_set>
using namespace std;

int main(void)
{
	long long DataSize = 0;
	long long int Count = 0;

	std::unordered_set<std::string> Datas;

	std::string Tmp;

	cin >> DataSize>> Tmp;
	Datas.emplace(Tmp);
	Count++;

	for (int i=1;i<DataSize;i++)
	{
		cin >>Tmp;
		Datas.emplace(Tmp);
	}

	cout << Datas.size() << endl;

	return 0;
}

Measured memory_bytes: 13960
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){ 
    int  n, m, ans = 0 ; 
    cin >> n >> m ; 
    vector < pair<int, int> > ab(n) ; 
    vector <int>  ocupy ; 
    for (int  i = 1 ; i <= m; i++) ocupy.pb(i); 
    for (int  i = 0 ; i < n ; i++) cin >> ab[i].ss >> ab[i].ff ; 
    sort(all(ab)) ; 
    reverse(all(ab)) ; 
    for (int  i = 0 ; i < n ; i++) { 
        int k = ab[i].ss ; 
        auto  it = lower_bound(ocupy.begin(), ocupy.end(), k ) ; 
        if (it != ocupy.end()) {
            int in =  it - ocupy.begin() ; 
            ocupy.erase( ocupy.begin() + in ) ; 
            ans += ab[i].ff ; 
        }
    }
    co (ans) ; 
}
// https://atcoder.jp/contests/abc137/tasks/abc137_d 

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


Measured memory_bytes: 5844
s=input()
n=len(s)
ans=int(s[0]+s[1]+s[2])
for i in range(1,n-2):
    if abs(int(s[i]+s[i+1]+s[i+2])-753)<=abs(ans-753):
        ans=int(s[i]+s[i+1]+s[i+2])
print(abs(ans-753))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S == U) {
    A--;
  } else {
    B--;
  }
  cout << A << " " << B << endl;
}

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

const int N = 100005;

int k, vis[N], dist[N];

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

    // 0-1 BFS 수행을 위한 초기화
    deque<int> dq;
    for(int i = 0; i < k; i++) dist[i] = k;
    dist[1] = 0;
    dq.push_back(1);

    while(!dq.empty()){
        int cur = dq.front();
        dq.pop_front();
        // 각 정점당 최대 한 번만 처리하게 하기 위함.
        // 다익스트라 알고리즘의 구현과 달리, Deque에 거리 정보를 같이 넣지 않으므로
        // visit 배열을 통해 구현함.
        if(vis[cur]) continue;
        vis[cur] = 1;

        // +1의 경우 (가중치 1)
        int plus = (cur + 1) % k;
        if(dist[plus] > dist[cur] + 1){
            dist[plus] = dist[cur] + 1;
            // 가중치가 1이므로 뒤에 넣는다.
            dq.push_back(plus);
        }

        // *10의 경우 (가중치 0)
        int mult = cur * 10 % k;
        if(dist[mult] > dist[cur]){
            dist[mult] = dist[cur];
            // 가중치가 0이므로 앞에 넣는다.
            dq.push_front(mult);
        }
    }

    printf("%d\n", dist[0] + 1);
}

Measured memory_bytes: 1280
/*input
6
30 10 60 10 60 50
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

typedef pair<int,int> ii;
typedef long long ll;

const int MOD = 1e9+7;

void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0;i<n;i++) cin >> arr[i];

    int dp[n];
    dp[0] = 0;
    for(int i=1;i<n;i++){
        if(i==1){
            dp[i] = dp[i-1]+abs(arr[i]-arr[i-1]);
        }
        else
            dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout << dp[n-1];
}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll k, x;
    cin >> k >> x;
    ll c = 1000000;
    for(ll i = max(-c, x-k+1); i <= min(c, x+k-1); i++) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 256
import numpy as np
n, m, q = map(int, input().split())
cnt = [[0]*(n+1)for _ in range(n+1)]
for _ in range(m):
    L, R = map(int, input().split())
    cnt[L][R] += 1

S = np.cumsum(cnt, axis=0).cumsum(axis=1)

L, R = map(np.array, zip(
    *[tuple(map(int, input().split())) for _ in range(q)]))


ans = S[R, R]-S[R, L-1]-S[L-1, R]+S[L-1, L-1]
print(*ans, sep='\n')

Measured memory_bytes: 34160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n;
    cin>>n;
    pair<pair<string,int>,int> p[n];
    rep(i,n){
        string s;
        int x;
        cin>>s>>x;
        int q=-x;
        p[i]=make_pair(make_pair(s,q),i);
    }
    sort(p,p+n);
    rep(i,n){
        cout<<p[i].second+1<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)
typedef struct sssi{
  char s[20];
  int ss;
}sssi;

int compare(const void *b1, const void *b2){ // 昇順
  return strcmp(((sssi*)b1)->s,((sssi*)b2)->s);
}





int main(){
  int n;
  scanf("%d",&n);
  sssi sss[n];
  int count=0;
  F(i,0,n){
    scanf("%s",sss[i].s);
    sss[i].ss=strlen(sss[i].s);
  }
  qsort(sss,n,sizeof(sssi),compare);
  F(i,0,n-1){
    if(sss[i].ss==sss[i+1].ss && strcmp(sss[i].s,sss[i+1].s)==0){
      count++;
    }
  }
  printf("%d\n",n-count);
  
  return 0;
}

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

int main(){
	int h,w,k;
	cin >> h >> w >> k;
	vector<string> c(h);
	int ans = 0;
	rep(i,h) cin >> c[i];
	rep(is,1<<h)rep(js,1<<w){
			int counts = 0;
		rep(i,h)rep(j,w){
			if(is>>i&1) continue;
			if(js>>j&1) continue;
			if(c[i][j] == '#') counts++;
		}
		if(counts == k) ans++;
	}
	cout << ans << endl;
	}

Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    int i,len;
    char input[101],word[101],tmp[201],text[201];
    char *re;
     
    scanf("%s",text);
    strcpy(tmp,text);
    strcat(text,tmp);
     
    scanf("%s",word);
     
    if((re=strstr(text,word))!=NULL){
        puts("Yes");
    }
    else puts("No");
 
return 0;
}

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

using namespace std;

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (auto &a : A) cin >> a;
  sort(A.begin(), A.end());

  int d_max = K - A[N - 1] + A[0];
  for (int i = 0; i < N - 1; i++) {
    chmax(d_max, A[i + 1] - A[i]);
  }
  cout << K - d_max << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    var (a, b, c) = readLine()!!.split(' ').map { it.toInt() }
    val k = readLine()!!.toInt()

    var cnt = 0
    while (a >= b) {
       b *= 2
        cnt++
    }
    while (b >= c) {
        c *= 2
        cnt++
    }
    if (cnt <= k) println("Yes")
    else println("No")
}

Measured memory_bytes: 36456
N,X,Y=map(int,input().split())
def dist(i,j):
  return min([j-i,abs(X-1-i)+1+abs(Y-1-j),abs(Y-1-i)+1+abs(X-1-j)])
dists = {v:0 for v in range(1,N)}
for i in range(N-1):
  for j in range(i+1,N):
    d = dist(i,j)
    dists[d]+=1
for i in range(1,N):
  print(dists[i])
  
    

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string t;
int a[4005],s[5][4005],u[5];
 int main(){
 	int n;
 	cin>>n>>t;
 	for(int i=1;i<=n;i++)
 	{
 		if(t[i-1]=='R') a[i]=0;
 		if(t[i-1]=='G') a[i]=1;
 		if(t[i-1]=='B') a[i]=2;
	 }
	 for(int i=n;i>=1;i--)
	   {
	   	 for(int j=0;j<3;j++)s[j][i]=s[j][i+1];
	   	 s[a[i]][i]=s[a[i]][i+1]+1;
	   }
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]==a[j])continue;
			memset(u,0,sizeof(u));
			u[a[i]]=1;u[a[j]]=1;
			int x;
			for(int k=0;k<3;k++)
			   if(u[k]==0)x=k;
			ans+=s[x][j+1];
			if(j-i+j<=n&&a[j-i+j]==x)ans--;
		}
	}
 cout<<ans;
return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B;
	cin >> A >> B;

	cout << max(0, A - (B + B));

	return 0;
}


Measured memory_bytes: 3552