akhauriyash/Code-Regression huggingface dataset:
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

n = int(input())
divisors = num_divisors_table(n-1)

print(sum(divisors))

Measured memory_bytes: 16596
#include<stdio.h>
int main()
{
	int a,b,c,temp;
	scanf("%d %d %d",&a,&b,&c);
	temp=a;
	a=b;
	b=temp;
	temp=a;
	a=c;
	c=temp;
	printf("%d %d %d",a,b,c);
return 0;
}

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


int main()
{
    int A[100] , N , key = 0 , j;
    
    cin >> N;
    for( int i = 0; i < N; i++ ){
	cin >> A[i];
    }
    
    for( int i = 1; i <= N; i++ ){
	for( int k = 0; k < N; k++ ){
	    cout << A[k];
	    if( k != N-1 )
		cout << " ";
	}
	cout << endl;
	key = A[i];
	j = i - 1;
	while( j >= 0 && A[j] > key ){
	    A[j+1] = A[j];
	    j--;
	    A[j+1] = key;
	    
	}
    }
    
    
    
    return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())

dp = [[0] * (3*K+1) for _ in range(2*K+1)]
for _ in range(N) :
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'W' :
        x += K
    
    m = min(x//K, y//K)
    x -= m * K
    y -= m * K
    x %= 2 * K
    y %= 2 * K
    
    dp[x][y] += 1
    if x < K and y < K :
        dp[x+K][y+K] += 1
        dp[x][y+2*K] += 1
    elif x < K and y >= K :
        dp[x+K][y-K] += 1
        dp[x+K][y+K] += 1
    elif x >= K and y < K :
        dp[x-K][y+K] += 1
        dp[x][y+2*K] += 1

for i in range(2 * K) :
    for j in range(3 * K) :
        dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        
ret = 0
for i in range(K-1, 2 * K) :
    for j in range(K-1, 3 * K) :
        ret = max(ret, dp[i][j] - dp[i][j-K] - dp[i-K][j] + dp[i-K][j-K])
print(ret)

Measured memory_bytes: 100700
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
H = LI() + [1]
dp = [1] * (n + 1)

for k in range(n):
    new_dp = [0] * (n + 1)
    for i in range(n + 1):
        if H[i] > H[k]:
            new_dp[i] = dp[k] * 2
        elif H[k - 1] <= H[i]:
            new_dp[i] = dp[i] * 2 * pow(2, H[k] - H[i], mod)
        elif H[k - 1] > H[k]:
            new_dp[i] = dp[i] - dp[k] + dp[k] * 2
        else:
            new_dp[i] = (dp[i] - dp[k - 1] + dp[k - 1] * 2) * pow(2, H[k] - H[k - 1], mod)
        new_dp[i] %= mod
    dp = new_dp


print(dp[-1])


Measured memory_bytes: 83748
def func(s):
    # print("xxx func")
    l = len(s)
    z = int((l + 1) / 2)
    same = True
    for i in range(z):
        # print(s[i], s[l - i - 1])
        if s[i] != s[l - i - 1]:
            same = False
    return same


s = input()
l = len(s)
x = int((l - 1) / 2)
y = int((l + 3) / 2)
# print(s[:x])
# print(s[y - 1 :])
if func(s) and func(s[:x]) and func(s[y - 1 :]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    r, D, prev_x = [int(e) for e in input().split()]
    for i in range(1, 11):
        res = r * prev_x - D
        print(res)
        prev_x = res

main()


Measured memory_bytes: 2940
def setse(s, m, i):
    if i < 0:
        return
    s[i] += 1
    if s[i] > m:
        setse(s, m, i - 1)
        if i > 0:
            s[i] = s[i - 1]

n, m, q = map(int, input().split(' '))
a = []
j = [1] * n
sc, scm = 0, 0
for i in range(q):
    al = list(map(int, input().split(' ')))
    a.append(al)
while(j[0] <= m):
    for i in a:
        sc += i[3] if j[i[1] - 1] - j[i[0] - 1] == i[2] else 0
    setse(j, m, n - 1)
    scm = sc if scm < sc else scm
    sc = 0
print(scm)

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

char test[2][26] = {
  {'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'},
  {'y','u','i','o','p','h','j','k','l','n','m'}
};

int main(){
  string s;
  while(1){
    cin>>s;
    if(s=="#")break;

    int cnt=0;
    int right=1;
    for(int i=0;i<s.length();i++){
      if(i == 0){
	for(char c:test[0]){
	  if(s[i]==c) right=right^1;
	}
	continue;
      }
      bool flag=false;
      for(char c:test[right]){
	if(s[i]==c)flag=true;
      }
      if(flag==false){
	cnt++;
	right=right^1;
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1188
N=int(input())
A=list(map(int,input().split()))
li=[]
A.sort()
s=True

for i in range(N-1):
    if A[i]==A[i+1] and s==True:
        li.append(A[i])
        s=False
    else:
        s=True
li.sort(reverse=True)

if len(li)>=2:
    print(li[0]*li[1])
else:
    print(0)
    

Measured memory_bytes: 19860
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    llong X, K, D;
    cin >> X >> K >> D;
    if (X < 0) X = -X;

    llong num1 = X / D;
    if (K <= num1) {
        llong ans = X - K * D;
        cout << ans << endl;
        return 0;
    }

    llong res = X % D;
    llong num2 = K - num1;
    if (num2%2 == 0) {
        llong ans = res;
        cout << ans << endl;
    }
    else {
        llong ans = -(res - D);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3556
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long int ll;
typedef vector<ll> vl;
typedef vector<string> vs;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define ABS(a) ((a)>0 ? (a) : (a * -1))



int main(){
	int a, b, c;
	cin >> a >> b >> c;

	for (int i = 1; i <= b; i++) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}


Measured memory_bytes: 256
a = list(input())
s = a[0]
count = 0
if s == "0":
    for i in range(1, len(a)):
        if int(a[i]) != i % 2:
            count += 1
elif s == "1":
    for i in range(1, len(a)):
        if int(a[i]) != (i + 1) % 2:
            count += 1
print(count)


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,ans=100;
	cin>>n;
	long long cnt=0;
	while(1)
	{
		cnt++;
		ans*=1.01;
		if(ans>=n)
			break;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3636
x,n=map(int,input().split())
if n>0:
    
    a=list(map(int,input().split()))
        
    z=x+1
    y=x-1
    if x not in a:
        print(x)
    else:
        while True:
            if y not in a:
                print(y)
                break
            elif z not in a:
                print(z)
                break
        
            z+=1
            y-=1
        
else:
    print(x)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
int fx4[] = {1 , -1 , 0 , 0};
int fy4[] = {0 , 0 , 1 , -1};
int Kfx[]= {-2,-2,2,2,1,1,-1,-1}; ///knight move x - exis
int Kfy[]= {1,-1,1,-1,2,-2,2,-2}; ///knight move y- exis
int fx8[]= {1,1,1,0,0,-1,-1,-1};
int fy8[]= {0,1,-1,1,-1,0,1,-1};
#define ll long long int
#define pii pair<int,int>
#define llu unsigned long long
#define inf 1<<28
#define gama 0.57721566490
#define PI              acos(-1.0)
#define INF             0x7fffffff
#define MOD             1000000007
#define EPS             1e-7
#define all(r)(r).begin(),(r).end()
/*
bool status[mx];
void sieve(){
   long long int  i,j;
    for(i=2;i<=mx;i++)
    {
        status[i]=0;
    }
    for( i=2;i<=sqrt(mx);i++){
        if(status[i]==0)
        {
            for(j=i*i;j<=mx;j+=i){
                status[j]=1;
            }
        }
    }
}*/
ll BM( ll a , ll b , ll m )
{
    if ( b == 0 ) return 1 ;
    ll x = BM(a,b/2,m);
    x = (( x % m) * (x % m))%m;

    if( b % 2 ) x = (( x % m) * (a %m)) % m ;
    return x ;
}
#define dd double
#define sc scanf
#define pr printf
#define VI vector<int>
#define VS vector<string>
#define VC vector<char>
#define VLL vector<long long int>
#define FILE freopen("input.txt","rt",stdin); freopen("output.txt","w",stdout);
#define p_b push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define F(i,a,b) for(i=a;i<=b;i++)
#define sc1(a) scanf("%d",&a)
#define scL1(a) scanf("%lld",&a)
#define scL2(a,b) scanf("%lld%lld",&a,&b)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define fori(N)          for(int i = 0; i<(N); i++)
#define forj(N)         for(int j = 0; j<(N); j++)
#define fork(N)         for(int k = 0; k<(N); k++)
#define forl(N)         for(int l = 0; l<(N); l++)
#define ford(N)         for(int d = 0; d<(N); d++)
#define fori1(N)          for(int i = 1; i<=(N); i++)
#define forj1(N)         for(int j = 1; j<=(N); j++)
#define fork1(N)         for(int k = 1; k<=(N); k++)
#define ford1(N)         for(int d = 1; d<=(N); d++)
#define sqr(x)           (x)*(x)
#define TEST int test,te=0;cin>>test;
#define segment_tree int l=(n*2),r=(n*2)+1,mid=(l+r)/2
#define Mx 100005
#define mx 10005

int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);///Beware of use it, if u use it dont use scanf or printf
    string a;
    cin>>a;
    string l=a;
     reverse(l.begin(),l.end());
     int f=0;
     if(l!=a)f=1;
    string b="";
    int k=(a.size()-1)/2;
    for(int i=0;i<k;i++)b+=a[i];
    string c=b;
    reverse(c.begin(),c.end());
    
	if(c!=b)f=1;
	k=(a.size()+3)/2;
	string d="";
	for(int i=k-1;i<a.size();i++){
		d+=a[i];
	}
	string z=d;
	 reverse(z.begin(),z.end());
	 if(z!=d)f=1;
	 if(f==0)cout<<"Yes"<<endl;
	 else cout<<"No"<<endl;
	 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int main(){
    int n; 
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8668
# -*- coding: utf-8 -*-
n,m,l = [int(i)for i in input().split(' ')]
A = []
B = []
C = [[0for _ in range(l)]for _ in range(n)]
for i in range(n):
    A.append([int(a)for a in input().split(' ')])
for i in range(m):
    B.append([int(a)for a in input().split(' ')])

for i in range(n):
    for j in range(l):
        s = 0
        for k in range(m):
            s += A[i][k]*B[k][j]
        C[i][j] = s

for x in range(n):
    print(' '.join([str(a)for a in C[x]]))

Measured memory_bytes: 8828
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

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

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,y;
	cin>>n>>y;
	y/=1000;
	rep(i,n+1){
		rep(j,n+1){
			if(n<i+j)continue;
			if(i*10+j*5+(n-i-j)==y){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
}

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

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int dis = 0;
            for (int k = 0; k < d; k++) {
                dis += (x[j][k]-x[i][k]) * (x[j][k]-x[i][k]);
            }
            double f = sqrt(dis);
            if (ceil(f) == floor(f)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

struct NextInfo {
	int n;
	bool isEven;
};

struct Node {
	std::vector<NextInfo> next;
};

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

	std::vector<Node> nodes(N);
	for(int i = 0; i < N - 1; i++) {
		int u, v, w;
		std::cin >> u >> v >> w;

		const bool isEven = w % 2 == 0;
		nodes[u - 1].next.emplace_back(NextInfo{v - 1, isEven});
		nodes[v - 1].next.emplace_back(NextInfo{u - 1, isEven});
	}

	std::vector<bool> isWhite(N);
	std::vector<bool> filled(N, false);

	isWhite[0] = true;
	filled[0] = true;
	std::queue<int> queue;
	queue.push(0);
	while(!queue.empty()) {
		const int from = queue.front();
		const Node *node = &nodes[from];
		queue.pop();

		for(const auto &info : node->next) {
			const int to = info.n;
			if(filled[to]) {
				continue;
			} else {
				if(info.isEven) {
					isWhite[to] = isWhite[from];
				} else {
					isWhite[to] = !isWhite[from];
				}
				filled[to] = true;
				queue.push(to);
			}
		}
	}

	for(int i = 0; i < N; i++) {
		std::cout << (isWhite[i] ? "0" : "1") << std::endl;
	}

	return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll A, B;
  cin >> A >> B;
  cout << ((B%A==0)? (A+B):(B-A));
  return 0;
}


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

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

    for (int i = 0; i < 8; i++) {
        int cnt = N[0] - '0';
        string S = "";
        bitset<3> bs(i);
        for (int j = 0; j < 3; j++) {
            if (bs[j]) {
                cnt += N[j + 1] - '0';
                S += "+";
            }
            else {
                cnt -= N[j + 1] - '0';
                S += "-";
            }
        }
        if (cnt == 7) {
            for (int j = 0; j < 3; j++) {
                cout << N[j] << S[j];
            }
            cout << N[3] << "=7" << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int n;
double x[3],y[3];
struct data{
	double a,b,c;
	data(double aa,double bb,double cc){
		a=aa;
		b=bb;
		c=cc;
	}
};

struct data2{
	double x,y,r;
	data2(){

	}
	data2(double xx,double yy,double rr){
		x=xx;
		y=yy;
		r=rr;
	}
};

data make_line(int i,int j){
	if(x[i]==x[j]){
		return data(0.0,(y[i]+y[j])/2.0,1);
	}
	if(y[i]==y[j]){
		return data((x[i]+x[j])/2,0,0); 
	}
	double aa=(y[i]-y[j])/(x[i]-x[j]);
	aa=-1.0/aa;
	double bb=(y[i]+y[j])/2.0-(x[j]+x[i])/2.0*aa;
	return data(aa,bb,1);
}

data2 cross(data y1,data y2){
	data2 d;
	if(y1.c==0){
		d.x=y1.a;
		d.y=y2.a*d.x+y2.b;
	}
	if(y2.c==0){
		d.x=y2.a;
		d.y=y1.a*d.x+y1.b;
	}
	if(y1.c==1 && y2.c==1){
		d.x=-(y1.b-y2.b)/(y1.a-y2.a);
		d.y=y1.a*d.x+y1.b;
	}
	d.r=sqrt(pow(d.x-x[0],2)+pow(d.y-y[0],2));
	return d; 
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			scanf("%lf %lf",&x[j],&y[j]);
		}
		data y1=make_line(0,1);
		//printf("%.3f %.3f\n",y1.a,y1.b);
		data y2=make_line(0,2);
		//printf("%.3f %.3f\n",y2.a,y2.b);
		data2 y3=cross(y1,y2);
		printf("%.3f %.3f %.3f\n",y3.x,y3.y,y3.r);
	}
	return 0;
}

Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
 
#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>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,w,h,x,y,a;
	cin >> w >> h >> n;
	ll xx=w,yy=h,lx=0,ly=0;
	rep(i,n){
		cin >> x >> y >> a;
		if(a==1) lx=max(lx,x);
		else if(a==2) xx=min(xx,x);
		else if(a==3) ly=max(ly,y);
		else if(a==4) yy=min(yy,y);
	}
	ll sx=xx-lx;
	ll sy=yy-ly;
	if(sx<0 || sy<0) cout << 0 << endl;
	else cout << sx*sy << endl;
    return 0;
}


Measured memory_bytes: 256
S = list(map(int,input()))
ketasu = len(S)
sa_list = []
for i in range(ketasu-2):
    toridashita_kazu = 100*S[i]+10*S[i+1]+S[i+2]
    sa = abs(toridashita_kazu - 753)
    sa_list.append(sa)
print(min(sa_list))

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

int main(void){

    int t_hp, t_atk, a_hp, a_atk;

    scanf("%d", &t_hp);
    scanf("%d", &t_atk);
    scanf("%d", &a_hp);
    scanf("%d", &a_atk);

    // printf("%d\n", t_hp);
    // printf("%d\n", t_atk);
    // printf("%d\n", a_hp);
    // printf("%d\n", a_atk);

    while(1){

        a_hp = a_hp - t_atk;
        if(a_hp <= 0){
            printf("Yes\n");

            break;
        }
 
        t_hp -= a_atk;
        if(t_hp <= 0){
            printf("No\n");

            break;
        }



    }

    return 0;
}

Measured memory_bytes: 1620
#include "bits/stdc++.h"
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  // num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  num = numeric_limits<int>::max(); // min
  int n;
  string s;

  cin >> s;

  for(auto it = s.begin();it+2!=s.end();++it){
    int tmp = abs(100 * (*it - '0') + 10 * (*(it + 1) - '0') + (*(it + 2) - '0') - 753);
    num = min(tmp, num);
  }

  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static readonly long Mod = 998244353;
    static void Main()
    {
        var (N, S) = ReadTuple<int,int>();
        var A = RInts();

        var dp = new long[N+1][];
        for (int i = 0; i < N+1; i++)
        {
            dp[i] = new long[S + 1];
        }
        dp[0][0] = 1;
        for (int i = 0; i < N; i++)
        {
            var a = A[i];
            for (int j = 0; j < S+1; j++)
            {
                dp[i + 1][j] += dp[i][j] * 2;
                dp[i + 1][j] %= Mod;
                if (j + a > S) continue;
                dp[i + 1][j + a] += dp[i][j];
                dp[i + 1][j + a] %= Mod;
            }
        }
        WriteLine(dp[N][S]);
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 99268
#include <stdio.h>

int med3(int x, int y, int z){
	if(x<y){
		if(y<z){
			return y;
		}
		else if(z<x){
			return x;
		}
		else{
			return z;
		}
	}
	else{
		if(x<z){
			return x;
		}
		else if(z<y){
			return y;
		}
		else{
			return z;
		}
	}
}

void sort(int a[], int left, int right){
	if(left<right){
		int i=left, j=right;
		int pivot=med3(a[i], a[i+(j-i)/2], a[j]);
		int temp;
		while(1){
			while(a[i]<pivot){
				i++;
			}
			while(pivot<a[j]){
				j--;
			}
			if(i>=j){
				break;
			}
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
			
			i++;
			j--;
		}
		sort(a, left, i-1);
		sort(a, j+1, right);
	}

}

int main(void){
	int a[210000], n, k, i;
  long long int j;
	
	scanf("%d %d", &n, &k);
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	sort(a, 0, n-1);
	if(k>=n){
      printf("0\n");
      return 0;
    }
  for(i=0; i<n-k; i++){
    j+=a[i];
  }
  printf("%lld\n", j);
  return 0;
}


Measured memory_bytes: 896
n = int(input())
s = input()
mod = 10**9+7
#文字ごとの累積和を取っておく
acc_char = [0 for i in range(26)]
ans = 0
for i in range(n):
    #今回の数字は使うの確定
    char = s[i]
    plus = 1
    for j in range(len(acc_char)):
        if (ord(char) - ord('a')) != j:
            plus *= acc_char[j] + 1
    ans += plus
    ans %= mod
    acc_char[ord(char) - ord('a')] += 1
print(ans%mod)

Measured memory_bytes: 42332
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	void init(int N) {
		par.resize(N);
		siz.assign(N, 1);  // resize だとなぜか初期化されなかった
		for (int i = 0; i < N; ++i) par[i] = i; // 初期では親は自分自身
	}


	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		if (siz[rx] < siz[ry]) swap(rx, ry);
		siz[rx] += siz[ry];
		par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

	int size(int x) { return siz[root(x)]; }
};

signed main(void) {
	int n, m;
	cin >> n >> m;
	vector<int>a(m);
	vector<int>b(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
	}
	int ret = 0;
	rep(i, m) {
		UnionFind tree(n + 1);
		tree.init(n + 1);
		rep(j, m) {
			if (i == j)continue;
			tree.unite(a[j], b[j]);
		}
		if (!tree.same(a[i], b[i]))ret++;
	}
	print(ret);
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		int ans = (a + b) *c / 2;
		
		System.out.println(ans);
		
	}
}


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

namespace ConsoleApp50 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int N = st[0];
            int K = st[1];
            int S = st[2];

            int[] ans = new int[N];

            for (int i = 0; i < N; i++) {
                if (i < K) {
                    ans[i] = S;
                } else {
                    if (S == 1000000000) {
                        ans[i] = S - 1;
                    } else {
                        ans[i] = S + 1;
                    }
                    
                }

            }

            Console.WriteLine(string.Join(" ", ans));

        }
    }
}


Measured memory_bytes: 21212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){    ;
int main() {
 int A,B,C,D,E;
 cin>>A>>B>>C>>D>>E;
 cout<<(C-A)*60+(D-B)-E<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
    ll N, M;
    cin >> N >> M;

    if(2*N >= M){
        cout << M/2 << endl;
    }else{
        cout << N+(M-2*N)/4 << endl;
    }
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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 long long INF = 1LL << 60;

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> xy(15,vector<int>(15, -1));

    vector<int> A(N);
    REP(i,N){
        cin>>A[i];
        REP(j,A[i]){
            int x, y;
            cin >> x>>y;
            x--;
            xy[i][x] = y;
        }
    }

    int max_cnt = 0;

    // 正直者を仮定する
    REP(bit, 1<<N){

        // i番目の人の証言に矛盾がないか確認する
        bool flg = true;    // 証言が正しくない場合はflg=falseになる
        REP(i, N){
            if(!(bit&1<<i)) continue;   // 正直者ではないと仮定した人はスルー

            // 証言内容を確認
            REP(j, N){

                // j番目の人について証言していない場合
                if(xy[i][j]==-1) continue;  

                // 正直者と仮定したj番目の人を、正直者ではないと証言した場合
                if((bit&(1<<j))&&xy[i][j]==0){  
                    flg=false;
                    break;
                }

                // 正直者ではないと仮定したj番目の人を、正直者と証言した場合
                if(!(bit&(1<<j))&&xy[i][j]==1) {
                    flg=false;
                    break;
                }
            }
        }
        if(flg){
            //cout<<bitset<3>(bit)<<endl;
            int cnt=0;
            REP(c, N){
                if(bit&1<<c) cnt++;
            }
            if(max_cnt< cnt) max_cnt=cnt;
        }
    }


    cout << max_cnt << endl;
    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    int ans;
    ans = N / 2;

    if(N%2==1) ans++;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  string a, b;
  cin >> a >> b;

  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
  } else if (a.size() < b.size()) {
    cout << "LESS" << endl;
  } else {
    if (a > b) {
      cout << "GREATER" << endl;
    } else if (a < b)  {
      cout << "LESS" << endl;
    } else {
      cout << "EQUAL" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3028
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else if(a == b){
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

const int mod=1e9+7;
const int inf=-1;
const int sz=2e5;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gap ' '
#define lb lower_bound
#define ub upper_bound
#define SIN(x) sin(x * pi / 180.0)
#define COS(x) cos(x * pi / 180.0)
#define clr(x) memset(x,0,sizeof(x))
#define all(x) sort(x.begin(),x.end())
#define rall(x) reverse(x.begin(),x.end())
#define dbg puts("finding wrong")
#define case(x,y) printf("Case %lld: %lld\n",++x,y)
#define fastio ios::sync_with_stdio(false);cin.tie(0)


int ar[sz];

int main()
{
  fastio;
  ll n, x, y, i;
  cin>>n;
  set<ll>v1,v2;
  for(i=0; i<n; i++)
  {
      cin>>x>>y;
      ll p=x+y;
      ll q=x-y;
     v1.insert(p);
     v2.insert(q);
  }
  ll ans=max((*v1.rbegin()-*v1.begin()),(*v2.rbegin()-*v2.begin()));
  cout<<ans<<endl;
}


Measured memory_bytes: 22360
n = int(input())
if n < 112:
    print(111)
elif n < 223:
    print(222)
elif n < 334:
    print(333)
elif n < 445:
    print(444)
elif n < 556:
    print(555)
elif n < 667:
    print(666)
elif n < 778:
    print(777)
elif n < 889:
    print(888)
else:
    print(999)

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

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> p(N);
  for(int i=0; i<N; i++){
    string S;
    int P;
    cin >> S >> P;
    p.at(i) = make_pair(make_pair(S,-P),i+1);
  }

  sort(p.begin(),p.end());
  for(int i=0; i<N; i++){
    cout << p.at(i).second << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int[] input = ReadInts();
        int A = input[0];
        int B = input[1];
        int C = input[2];
        int D = input[3];
        while(true)
        {
            C -= B;
            if (C <= 0) return "Yes";
            A -= D;
            if (A <= 0) return "No";
        }       
    }

    public static int Gcd(int a, int b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 27548
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL x, y;
int main()
{
    scanf("%lld %lld", &x, &y);
    if(x == 1 || y == 1)
    	cout << "1" << endl;
    else{
	    if(x % 2)
	        printf("%lld\n", (x / 2 + 1) * y - y / 2);
	    else
	        printf("%lld\n", x / 2 * y);
	}
    
    return 0;
}


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

#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;

vector<int> vi;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int K;
    cin >> K;

    int idx = 0;
    if (A <= B)
    {
        if (B <= C) idx = 3;
        else idx = 2;
    }
    else if (A <= C) idx = 3;
    else idx = 1;

    int ans = 0;
    if (idx == 1)
    {
        ans += A * (int)pow(2, K) + B + C;
    }
    else if (idx == 2)
    {
        ans += B * (int)pow(2, K) + A + C;
    }
    else
    {
        ans += C * (int)pow(2, K) + A + B;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <stdio.h>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n, 0);

    for (int i = 0; i < n; i++) scanf("%d", &a[i]);

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        for(int j = n - 1; j > i; --j) {
            if(a[j] < a[j-1]) {
                swap(a[j], a[j-1]);
                ++cnt;
            }
        }
    }
    ostringstream os;
    for_each(a.begin(), a.end() - 1,
             [&os](const int& e){
                 os << e << " ";
             });
    os << *(a.end() - 1);
    cout << os.str() << endl;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3264
# D - String Formation
from collections import deque
s = deque(input())
q = int(input())
odd = 0
for i in range(q):
    t,*fc = input().split()
    if t=='1': odd ^= 1 #t1
    else: #t2
        if odd ^ (int(fc[0])-1): s.append(fc[1])
        else: s.appendleft(fc[1])
if odd: deque.reverse(s)
print(*s, sep='')

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


signed main(){

	int N;
	cin >> N;
	string S;
	cin >> S;

	int sum_white[223456], sum_black[223456];
	rep(i, N + 1){
		sum_white[i] = sum_black[i] = 0;
	}
	rep(i, N + 1){
		sum_white[i + 1] = sum_white[i] + (S[i] == '.' ? 1 : 0);
		sum_black[i + 1] = sum_black[i] + (S[i] == '#' ? 1 : 0);
	}

	int ans = INF;
	rep(i, N+1){
		ans = min(ans, sum_black[i] - sum_black[0]
			+ sum_white[N + 1] - sum_white[i]);
//		cerr << sum_black[i] - sum_black[0]
//			+ sum_white[N + 1] - sum_white[i] << endl;
	}

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

Measured memory_bytes: 4100
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	class Pair {
		public int A;
		public long B;
		public Pair(int a, long b){
			A = a; B = b;
		}
	}
	public void Solve(){
		
		Pair[] P = new Pair[N];
		for(int i=0;i<N;i++){
			P[i] = new Pair(A[i], B[i]);
		}
		
		Array.Sort(P, (p, q) => {
			if(p.A != q.A) return p.A.CompareTo(q.A);
			else return -1 * p.B.CompareTo(q.B);
		});
		
		long ans = 0;
		
		var SH = new SkewHeap<long>();
		
		int idx = 0;
		for(int i=M-1;i>=0;i--){
			while(idx < N){
				if(P[idx].A + i <= M){
					SH.Push(-P[idx].B);
					idx++;
					continue;
				}
				break;
			}
			if(SH.Count > 0){
				var m = SH.Top;SH.Pop();
				ans += -m;
			}
		}
		Console.WriteLine(ans);
		
	}
	int N,M;
	int[] A;
	long[] B;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[N];
		B = new long[N];
		for(int i=0;i<N;i++){
			d = ria();
			A[i] = d[0]; B[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}




class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}


Measured memory_bytes: 24004
#include<cstdio>
#include<cstring>
#define maxn 100005
int n,r1,r2,s1[maxn],s2[maxn],ans[maxn],ma[maxn];
bool vis[maxn];
struct node { int v; node *nxt; } edge[maxn*16],*head[3][maxn],*ncnt;
void addedge(int u,int v,int d)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[d][u];
	head[d][u]=ncnt;
}
int s[maxn],top;
void dfs(int d,int u)
{
    if(s1[u]==0)
        s[++top]=u;
	for(node *p=head[d][u];p;p=p->nxt)
	{
		int v=p->v;
		dfs(d,v);
	}
}
void dfs2(int u,int c)
{
	ans[u]=c,vis[u]=true;
	for(node *p=head[2][u];p;p=p->nxt)
	{
		int v=p->v;
		if(!vis[v]) dfs2(v,-c);
	}
}
int main()
{
	ncnt=&edge[0];
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int fa;
		scanf("%d",&fa);
		if(fa>0) { addedge(fa,i,0); s1[fa]^=1; }
		else r1=i;
	}
	for(int i=1;i<=n;i++)
	{
		int fa;
		scanf("%d",&fa);
		if(fa>0) { addedge(fa,i,1); s2[fa]^=1; }
		else r2=i;
	}
	for(int i=1;i<=n;i++)
		if(s1[i]!=s2[i]) { printf("IMPOSSIBLE\n"); return 0; }
	printf("POSSIBLE\n");
	top=0;
	dfs(0,r1);
	while(top>=2){
        ma[s[top]]=s[top-1];
        ma[s[top-1]]=s[top];
        top-=2;
	}
	for(int i=1;i<=n;i++)
		if(ma[i]) addedge(i,ma[i],2);
	memset(ma,0,sizeof(ma));
	top=0;
	dfs(1,r2);
	while(top>=2){
        ma[s[top]]=s[top-1];
        ma[s[top-1]]=s[top];
        top-=2;
	}
	for(int i=1;i<=n;i++)
		if(ma[i]) addedge(i,ma[i],2);
	for(int i=1;i<=n;i++)
		if(!vis[i]) dfs2(i,1);
	for(int i=1;i<=n;i++) printf("%d ",s1[i]?0:ans[i]);
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int n,ans[233333];
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a;scanf("%d",&a);
		ans[a]++;
	}
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 4612
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	int d[N];
	rep(i, 0, N) cin >> d[i];

	set<int> s;
	rep(i, 0, N) s.insert(d[i]);
	cout << s.size() << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  //整数a,bを導入
  int a, b;
  //入力を求める
  cin >> a >> b;
  //画面にxを表示
  cout << (a + b) / 2 + (a + b) % 2 << endl;
}


Measured memory_bytes: 256
import sys 

target = int(input())

r1 = str(target)[-1]
if (str(r1) == "2" or str(r1) == "4" or str(r1) == "5" or str(r1) == "7" or str(r1) == "9"):
    print("hon")

if (str(r1) == "0" or str(r1) == "1" or str(r1) == "6" or str(r1) == "8"):
    print("pon")

if str(r1) == "3":
    print("bon")

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
typedef long long ll;
 
int main() {
  int N;
  scanf("%d", &N);
  vector<ll> A(N);
  for(int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  vector<ll> acc(N + 1);
  for(int i = 0; i < N; i++) {
    acc[i + 1] = acc[i] + A[i];
  }
  ll ans = 1LL << 62;
  for(int j = 1; j < N - 2; j++) {
    int i1 = lower_bound(acc.begin(), acc.begin() + j + 1, acc[j + 1] / 2) - acc.begin() - 1;
    int i2 = i1 - 1;
    int k1 = lower_bound(acc.begin() + j + 1, acc.end(), (acc[N] - acc[j + 1]) / 2 + acc[j + 1]) - acc.begin() - 1;
    int k2 = k1 - 1;
    //cout << i2 << "," << i1 << "," << j << "," << k2 << "," << k1 << endl;
    vector<ll> I = {i1};
    vector<ll> K = {k1};
    if (i2 >= 0) I.push_back(i2);
    if (k2 > j) K.push_back(k2);
    for(int ii = 0; ii < I.size(); ii++) {
      for(int kk = 0; kk < K.size(); kk++) {
        int i = I[ii], k = K[kk];
        vector<ll> area;
        area.push_back(acc[i + 1]);
        area.push_back(acc[j + 1] - acc[i + 1]);
        area.push_back(acc[k + 1] - acc[j + 1]);
        area.push_back(acc[N] - acc[k + 1]);
        sort(area.begin(), area.end());
        ans = min(ans, area.back() - area[0]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3328
n,m = map(int, input().split())
bl = [int(input())-1 for _ in range(m)]
l = [i for i in range(n)]
cnt = 0
for num in bl:
    del l[num-cnt]
    cnt +=1
    
mod = 1000000007

al = [0]*n
if 0 in l and 1 in l:
    al[0] = 1
    al[1] = 2
elif 0 in l:
    al[0] =1
elif 1 in l:
    al[1] = 1
else:
    print(0)
    exit()
    
li = [i for i in l if i>=2]
for i in li:
    al[i] = (al[i-1] + al[i-2])%mod
    if al[i] == 0:
        print(0)
        exit()

print(al[-1])


Measured memory_bytes: 11768
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47352
S = input()
N = len(S)
for i in range(N):
    if i and S[i] == S[i-1]:
        print(i, i+1)
        break
    elif i>=2 and S[i] == S[i-2]:
        print(i-1, i+1)
        break
else:
    print(-1, -1)

Measured memory_bytes: 3188
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
	std::io::Read::read_to_string(
		&mut std::io::stdin(),
		&mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
	let mut get = || stdin.next().unwrap();
	macro_rules! get {
		() => (get().parse::<i64>().unwrap());
	}
    
    let a = get!();
    let b = get!();
    let c = get!();
    let d = get!();
    let ans = std::cmp::min(a, b)
			+ std::cmp::min(c, d);
	println!("{}", ans);
}

Measured memory_bytes: 4352