akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
}
char c[2145][2145];
int a[2145][2145];
int b[2145][2145];
int sum[2145][2145];
signed main(){
	ic(h) ic(w)
	rep(0,i,h)rep(0,j,w)cin>>c[i][j];
	int renzoku=0;
	rep(0,i,h){
		rep(0,j,w){
			if(c[i][j]=='.')renzoku++;
			else{
				rep(j-renzoku,k,j)a[i][k]=renzoku;
				renzoku=0;
			}
		}
		if(renzoku>0)rep(w-renzoku,k,w)a[i][k]=renzoku;
		renzoku=0;
	}	
	rep(0,j,w){
		rep(0,i,h){
			if(c[i][j]=='.')renzoku++;
			else{
				rep(i-renzoku,k,i)b[k][j]=renzoku;
				renzoku=0;
			}
		}
		if(renzoku>0)rep(h-renzoku,k,h)b[k][j]=renzoku;
		renzoku=0;
	}	
	rep(0,i,h)rep(0,j,w)sum[i][j]=a[i][j]+b[i][j];
	int ans=0;
	rep(0,i,h)rep(0,j,w)ans=max(ans,sum[i][j]);
	c(ans-1)
}

Measured memory_bytes: 110208
n, m = gets.split.map(&:to_i)
ac = Hash.new(false)
penalty = Hash.new(0)
m.times do
  p, s = gets.split
  ac[p] = true if s == 'AC'
  penalty[p] += 1 if !ac[p] && s = 'WA'
end
penalty.keys.each do |p|
  penalty[p] = 0 if !ac[p]
end
puts "#{ac.values.count(true)} #{penalty.values.sum}"


Measured memory_bytes: 27484
#include <stdio.h>
 
using namespace std;
 
int main(){
    int C[10001];
    for(int i = 0; i < 10001; i++) C[i] = 0;
    int n;
    scanf("%d",&n);
    int* A = new int[n];
    int* B = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
        C[A[i]]++;
    }
 
    for(int i = 0,j=0; i < 10001; i++){
        if(C[i] != 0){
            for(int k = 0; k < C[i]; k++){
                B[j++] = i;
            }
        }
    }
 
    for(int i = 0; i < n-1; i++) printf("%d ",B[i]);
    printf("%d\n",B[n-1]);
    delete[] A;
    delete[] B;
    return 0;
}


Measured memory_bytes: 17940
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;
#define GG puts("FUCK")
#define N 280050
inline char nc() {
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
int rd() {
	int x=0; char s=nc();
	while(s<'0'||s>'9') s=nc();
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=nc();
	return x;
}
int n,a[N],f[N],ans[N],b[N],cnt;
char pbuf[100000],*pp=pbuf;
void push(const char ch) {
	if(pp-pbuf==100000) fwrite(pbuf,1,100000,stdout),pp=pbuf;
	*pp++=ch;
}
void write(int x) {
	static int sta[37];
	int top=0;
	do{sta[++top]=x%10,x/=10;}while(x);
	while(top) push(sta[top--]+'0');
	push('\n');
}
int main() {
	n=rd();
	int m=(1<<n);
	register int i,j;
	for(i=0;i<m;i++) {
		a[i]=rd();
	}
	/*int mx3=0;
	f[0]=ans[0]=a[0];
	for(i=1;i<m;i++) {
		int mx1=0,mx2=0;
		cnt=0;
		for(j=0;j<n;j++) {
			if(i&(1<<j)) {
				mx1=max(mx1,f[i-(1<<j)]);
				mx2=max(mx2,ans[i-(1<<j)]);
				b[++cnt]=a[i-(1<<j)];
			}
		}
		sort(b+1,b+cnt+1);
		if(cnt>1) mx2=max(mx2,b[cnt]+b[cnt-1]);
		mx2=max(mx2,mx3);

		f[i]=max(mx1,a[i]);
		ans[i]=max(mx2,mx1+a[i]);
		printf("%d\n",ans[i]);
		mx3=max(mx3,ans[i]);
	}*/
	int maxx=0;
	for(i=1;i<m;i++) {
		int mx=a[0],me=0;
		for(j=i;j;j=i&(j-1)) {
			if(a[j]>=mx) me=mx,mx=a[j];
			else if(a[j]>me) me=a[j];
		}
		if(maxx>mx+me) write(maxx);
		else write(mx+me),maxx=mx+me;
	}
	fwrite(pbuf,1,pp-pbuf,stdout);
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 1e3 + 5;
const int mod = 0;
char s[N], t[N];
int main(){
	scanf("%s %s", s + 1, t + 1);
	int n = strlen(s + 1), m = strlen(t + 1);
	int mi = N;
	for(int i = 1;i <= n - m + 1; i++){
		int cnt = 0;
		for(int j = 0; j < m; j++){
			if(s[i + j] != t[j + 1]) cnt++;
		}
		mi = min(mi, cnt);
	}
	printf("%d", mi);


}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int MOD = 1e9+7;
const int N = 5*1e5;



int main(){
    AC
    string s;
    cin>>s;
    switch(s[s.size()-1]){
        case '2':
        case '4':
        case '5':
        case '7':
        case '9': 
            cout<<"hon"<<endl;
            break;
        case '3':
            cout<<"bon"<<endl;
            break;
        default:
            cout<<"pon"<<endl;
            break;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int n,t;
  std::cin >> n >> t;
  vector<int> a(n);
  int min;
  std::cin >> min;
  a[0]=0;
  int max=0;
  for (size_t i = 1; i < n ; i++) {
    std::cin >> a[i];
    if (a[i]<min) min=a[i];
    a[i]-=min;
    if (a[i]>max) max=a[i];
  }
  int count=0;
  for (size_t i = 0; i < n; i++) {
    if (a[i]==max) {
      count++;
    }
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, D, A;
    cin >> N >> D >> A;
    vector<pair<int, int>> posAndNumPairs;
    for (int i = 0; i < N; ++i)
    {
        int X, H;
        cin >> X >> H;
        posAndNumPairs.push_back({ X, (H + A - 1) / A });
    }
    sort(posAndNumPairs.begin(), posAndNumPairs.end());
    // 左から順になるべく右側のモンスターを巻き込めるよう貪欲に爆破していく
    vector<LLONG> S(N + 1); // S[i]:i番目のモンスターがこれまで爆破された回数
    LLONG ans = 0;
    int r = 1;  // iを爆破したとき，爆風が届かない最初のモンスター（結果を引き継ぐためループ外で定義）
    for (int i = 0; i < N; ++i)
    {
        LLONG Ni = posAndNumPairs[i].second;    // 素の必要回数
        if (Ni > S[i])
        {
            int Xi = posAndNumPairs[i].first;   // 位置
            LLONG Hi = Ni - S[i];               // 必要爆破回数
            // iより右側で，爆風が届かない最初のモンスターを探す
            while (r < N)
            {
                int Xr = posAndNumPairs[r].first;
                if (Xr - Xi <= 2 * D) ++r;
                else break;
            }
            // imos法
            S[i] += Hi;
            S[r] -= Hi;
            ans += Hi;
        }
        // 累積和の更新
        S[i + 1] += S[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3440
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A), greater<>());

  map<int, int> m;
  REP(i, N) m[A[i]]++;

  int p = 1;
  while(A[0] >= p) p *= 2;

  int ans = 0;
  REP(i, N){
    while(A[i]*2 < p) p /= 2;


    if(m[p-A[i]]){
      if(A[i] == p-A[i]){
        if(m[A[i]] >= 2){
          ans++;
          m[A[i]] -= 2;
        }
      }else{
        if(m[A[i]]){
          ans++;
          m[A[i]]--;
          m[p-A[i]]--;
        }
      }
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 26880
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	static final int INF = 50000000;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		String s = sc.next();
		int one = 0;
		for (char c: s.toCharArray()) {
			if(c=='1')one++;
		}
		long remP = 0;
		long remN = 0;
		for (int i = N-1; i >= 0; i--) {
			int x = s.charAt(i)-'0';
			if (one > 1)
				remP = (remP+x*power(2,N-1-i,one-1))%(one-1);
			remN = (remN+x*power(2,N-1-i,one+1))%(one+1);
		}
		
		for (int i = 0; i < N; i++) {
			long rem;
			if (s.charAt(i)=='0') {
				rem = (remN+power(2,N-1-i,one+1))%(one+1);
			} else {
				if (one == 1) {
					pw.println(0);
					continue;
				}
				rem = ((one-1)+remP-power(2,N-1-i,one-1))%(one-1);
			}
			int ans = 1+op(rem);
			pw.println(ans);
		}
		pw.close();
	}
	
	public static int op(long n) {
		if (n==0)
			return 0;
		else
			return 1+op(n%Long.bitCount(n));
	}
	
	//Fast exponentiation (x^y mod m)
	public static long power(long x, long y, long m) {
		long ans = 1;
		x %= m;
		while (y > 0) {
			if(y % 2 == 1)
				ans = (ans * x) % m;
			y /= 2;
			x = (x * x) % m;
		}
		return ans;
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

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

long long abs(long long a,long long b){
  if(a>b)
    return (long long)a-b;
  else
    return (long long)b-a;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<long long> da(n),dp(n,1000000000);
  dp[0]=0;
  for(int i=0;i<n;i++){
    cin >> da[i];
  }
  int cou=0;
  for(int i=0;i<n;i++){
    for(int j=1;j<k+1;j++){
      if(i+j<0)
        cou++;
        dp[i+j]=min(dp[i+j],(long long)dp[i]+abs(da[i],da[i+j]));
    }
  }
  //for(int i=0;i<n;i++)
    //cout << dp[i] << endl;
  //cout << cou << endl;
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))



int main(void){
	string s,t;
	cin>>s>>t;
	vector<vector<int> > map(26);
	int idx[26];
	rep(i,26)idx[i]=0;

	rep(i,s.length()){
		map[s[i]-'0'-49].push_back(i);
		idx[s[i]-'0'-49]++;
	}
	/*rep(i,26){
		if(idx[i] != 0){
			cout<<"num:"<<i<<endl;
			rep(j,idx[i])cout<<map[i][j]<<" ";
			cout<<endl;
		}

	}*/
	ll ans=0;
	int cur=0;
	rep(i,t.length()){
		int char_num = t[i]-'0'-49;
		//cout<<t[i]<<endl;
		//cout<<cur<<","<<ans<<endl;
		if(idx[char_num] == 0){
			ans = -1;
			break;
		}
		//rep(j,idx[char_num])cout<<map[char_num][j]<<" ";
		//cout<<endl;
		if(map[char_num][idx[char_num]-1] < cur){
			cur = 0;
			ans+=s.length();
		}

		int iter=lower_bound(map[char_num].begin(),map[char_num].end(),cur)-map[char_num].begin();
		//cout<<"iter:"<<iter<<","<<map[char_num][iter]<<endl;
		cur = map[char_num][iter]+1;

		if(i == t.length()-1)ans+=cur;
	}

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


Measured memory_bytes: 1216
x, y, z, k = gets.split(' ').map(&:to_i)
as = gets.split(' ').map(&:to_i)
bs = gets.split(' ').map(&:to_i)
cs = gets.split(' ').map(&:to_i)
as.sort!.reverse!
bs.sort!.reverse!
cs.sort!.reverse!
ks = []
ans = []
x.times do |i|
    y.times do |j|
        ks << as[i] + bs[j]
    end
end
kks = ks.sort!.reverse![0..k-1]
kks.length.times do |i|
    z.times do |j|
        ans << kks[i] + cs[j]
    end
end
puts ans.sort.reverse[0..k-1]


Measured memory_bytes: 93420
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(n):
    if a[i] < 0:
        count += 1
        a[i] *= -1
if count % 2 == 0:
    print(sum(a))
else:
    min_a = min(a)
    ans = sum(a)-min_a*2
    print(ans)



Measured memory_bytes: 64880
N,M,c = map(int,input().split())
B = list(map(int,input().split()))
A = []
ans = 0
for _ in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)
for a in A:
    tmp = 0
    for i in range(M):
        tmp += a[i]*B[i]
    tmp += c
    if tmp > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>
#include <queue>

using namespace std;
const int INF = 100000000;

typedef pair<int, int> P;

char maze[1000][1000 + 1];
char tmp;
int R, C;
int sx, sy;
int gx, gy;
int cntWhite =0;
int cntBlack = 0;
int cntBlackLast = 0;
int cntTurn = 0;
int d[50][50];


int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {

			cin >> tmp;
			if (tmp == '.')
			{
				cntWhite++;
			}
			else
			{
				cntBlack++;

				que.push(P(i, j));
			}
			maze[i][j] = tmp;
		}
	}
	while (que.size())
	{
		if (cntWhite == 0)
		{
			break;
		}
		int kEnd = cntBlack - cntBlackLast;
		cntBlackLast = cntBlack;
		for (int k = 0; k < kEnd; k++)
		{
			P p = que.front(); que.pop();
			for (int i = 0; i < 4; i++)
			{
				int nx = p.first + dx[i], ny = p.second + dy[i];
				if (0 <= nx && nx < R && 0 <= ny && ny < C && maze[nx][ny] != '#')
				{
					que.push(P(nx, ny));
					maze[nx][ny] = '#';
					cntWhite--;
					cntBlack++;
				}
			}

		}
		cntTurn++;

	}

	return cntTurn;
}

int main()
{
	
	cin >> R >> C;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			maze[i][j] = tmp;
		}
	}
	int res = bfs();
	cout << res ;
}


Measured memory_bytes: 9360
#include<iostream>
#include<vector>

using namespace std;
 
const int MAXV=(int) 1e5+1;
const int INF= (int) 1e8;

struct edge{
    int to;
};
 
vector <edge> G[MAXV];
int Takahashi[MAXV];
int Aoki[MAXV];

int Aoki_distance( int i, int count ){
    if( Aoki[i]<0 ){
        Aoki[i]=count;
        count++;
        //cout << "i visited[i] " << i << " " << visited[i] << endl;
    }
    for( auto& e:G[i] ){
        if( Aoki[e.to]<0 ){
            Aoki_distance( e.to, count );
        }
    }
    return 0;
}

int Takahashi_distance( int i, int count ){
    if( Takahashi[i]<0 ){
        if(Aoki[i]<=count){
            return 0;
        }
        Takahashi[i]=count;
        count++;
        //cout << "i visited[i] " << i << " " << visited[i] << endl;
    }
    for( auto& e:G[i] ){
        if( Takahashi[e.to]<0 ){
            Takahashi_distance( e.to, count );
        }
    }
    return 0;
} 

int main(){
    int N,u,v;
    cin >> N >> u >> v;

    int a[N-1],b[N-1];

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

    for(int i=0; i<=N; i++){
        Takahashi[i]=-1;
        Aoki[i]=-1;
    }

    for(int i=0; i<N-1; i++){
        edge e = { b[i] };
        G[a[i]].push_back(e);
        e = { a[i] };
        G[b[i]].push_back(e);
    }

    Aoki_distance(v,0); 
    Takahashi_distance(u,0);
    /*
    cout << "Aoki results" << endl;
    for(int i=1; i<=N; i++){
        cout << Aoki[i] << endl;
    }
    cout << "end of Aoki results" << endl;
    cout << "Takahashi results" << endl;
    for(int i=1; i<=N; i++){
        cout << Takahashi[i] << endl;
    }
    cout << "end of Aoki results" << endl;*/

    int goal=0;
    int goal_val=0;
    for(int i=1; i<=N; i++){
        if(Aoki[i]>goal_val && Takahashi[i]>=0){
            goal_val=Aoki[i];
            goal=i;
        }
    }    

    //cout << "goal, Aoki, Takahashi " <<  goal << " " << Aoki[goal] << " " << Takahashi[goal] << endl;
    if( Aoki[goal]<=0 ){
        cout << 0 << endl;
    }else{
        cout << Aoki[goal]-1 << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll A,B;

int main(){
  cin>>A>>B;
  if(A==B){
    cout<<1<<endl;
    return 0;
  }
  for(ll i=1LL<<60LL;i>=1LL;i>>=1LL){
    if((A&i)==(B&i)){
      if((A&i)>0){A^=i; B^=i;}
    }else break;
  }

  ll res=0;

  ll p=1;
  while(p*2<=B)p*=2;
  ll ub1=p*2-1;
  ll lb1=p|A;

  res+=p-A;

  ll ub2=B,lb2=p;
  for(ll i=p>>1LL;i>=1LL;i>>=1LL){
    if(B&i){
      ub2=p+2*i-1;
      break;
    }
  }


  if(lb1<=ub2){
    cout<<res+ub1-lb2+1<<endl;
  }else{
    cout<<res+ub1-lb1+1+ub2-lb2+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B,T; cin >> A >> B >> T;
    res = T/A * B;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a.at(i) >> b.at(i);
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if ((k | a.at(i)) == k) ans += b.at(i);
  }
  
  for (int i = 0; i < 31; i++) {
    if ((k & (1 << i)) == 0) continue;
    ll k2 = k ^ (1 << i);
    for (int j = 0; j < i; j++) k2 |= (1 << j);
    ll keep = 0;
    for (int j = 0; j < n; j++) {
      if ((k2 | a.at(j)) == k2) keep += b.at(j);
    }
    ans = max(ans, keep);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1792
// C - Streamline
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, m, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n >> m;
  vlli d(m), e(m - 1, 0);
  rep(i, 0, m)
  {
    cin >> d[i];
  }
  SORT(d);
  rep(i, 0, m - 1)
  {
    w = abs(d[i + 1] - d[i]);
    e[i] = w;
  }
  SORTR(e);
  count = n - 1;
  rep(i, 0, m - 1)
  {
    if (count <= 0)
    {
      ans += e[i];
    }
    else
    {
      count--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4764
{-# LANGUAGE TupleSections #-}
import           Control.Arrow (second)
import           Control.Monad (unless)
import           Data.Char     (isLower)
import           Data.Function (on)
import           Data.List     (splitAt)
import qualified Data.Map      as Map (foldl', fromListWith, intersectionWith)

main :: IO ()
main = do
  n <- readLn :: IO Int
  unless (n >= 1 && n <= 18) $ error "1 <= n <= 18"
  s <- getLine
  unless (all isLower s) $ error "lower case"
  unless (length s == 2 * n) $ error "length"

  print $ f s

f :: String -> Int
-- f s = length $ intersect (partitions front) (partitions rear)
f s = Map.foldl' (+) 0 $ (Map.intersectionWith (*) `on` toMap . partitions) front rear
  where
    toMap = Map.fromListWith (+) . map (,1)
    (front, rear) = twoFold s

partitions :: [a] -> [([a], [a])]
partitions []     = [([], [])]
partitions (x:xs) = partitions xs >>= \(ys, zs) -> [(x:ys, zs), (ys, x:zs)]

twoFold :: [a] -> ([a], [a])
twoFold xs = second reverse $ splitAt (length xs `div` 2) xs


Measured memory_bytes: 165116
# suffix array
# z-algorithm
# rolling-hash
# dp
n = int(input())
s = input()

# z-algorithm
# i左端
# j iからの距離
# k i-i+jの間を進みながら比較
ans = 0
for num in range(n - 1):
    S = s[num:]
    A = [0] * (n - num)
    A[0] = n - num
    i = 1
    j = 0
    while i < n - num:
        while i + j < n - num and S[j] == S[i + j]:
            j += 1
        A[i] = j
        ans = max(ans, min(i, j))
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < n - num and k + A[k] < j:
            A[i + k] = A[k]
            ans = max(ans, min(k, A[k]))
            k += 1
        i += k
        j -= k
print(ans)


Measured memory_bytes: 53724
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

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

//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main() {
  string s;cin >> s;
  int c=0;
  int n=s.size();
  rep(i,n){
    if(s[i]=='1')c++;
  }
  cout << 2*min(c,n-c);
}


Measured memory_bytes: 636
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
 
#define loop(j,n) for(int j = 0;j < int(n);j++)
#define loop2(i,n) for(int i = 1;i <= int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define rloop2(j,n) for(int j = int(n);j >= 1;j--)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfi4(v1,v2,v3,v4) scanf("%d %d %d %d",&v1,&v2,&v3,&v4)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfll4(v1,v2,v3,v4) scanf("%I64d %I64d %I64d %I64d",&v1,&v2,&v3,&v4)
#define sz(v) int(v.size())
#define test(x) cout<<">>>>>>>>>>>>>>>>>>>>"<<(x)<<endl
 
typedef long long ll;
 
 //ios_base::sync_with_stdio(0);
    //cout.tie(0);
	//cin.tie(0);
//const int N = 1e5 + 2;
 
using namespace std;
 
string s,t;
int cnt=0;
int main()
{
    cin>>s;
  	cin>>t;
    loop(i,3)
    {if(s[i]==t[i])cnt++;
    }
  cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if((A <= C) && (C <= B)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
const int N = 3e5 + 233;
int n, fa[N], pre[N], c[N][2], ans = 0, w[N];
inline int find(int x) {
  return pre[x] == x ? x : pre[x] = find(pre[x]);
}
struct Node {
  int id;
  bool operator < (const Node &rhs) const {
    int cu0 = c[id][0];
    int cu1 = c[id][1];
    int cv0 = c[rhs.id][0];
    int cv1 = c[rhs.id][1];
    return ((cu0 * cv1 > cv0 * cu1)
             || (cu0 * cv1 == cv0 * cu1 && id > rhs.id));
  }
};
set<Node> q;

main(void) {
  read(n);
  for(int i = 2; i <= n; i ++)
    read(fa[i]);
  for(int i = 1; i <= n; i ++)
    read(w[i]);
  for(int i = 1; i <= n; i ++) {
    pre[i] = i;
    c[i][w[i]] = 1;
  }
  for(int i = 2; i <= n; i ++)
    q.insert((Node) {i});
  for(int i = 1; i <= n - 1; i ++) {
    int u = q.begin()->id; q.erase(q.begin());
    int p = find(fa[u]); u = find(u); q.erase((Node) {p});
    // cout << c[u][0] << " " << c[p][1] << "\n";
    ans += c[u][0] * c[p][1];
    c[p][1] += c[u][1]; c[p][0] += c[u][0];
    c[u][1] = 0; c[u][0] = 0;
    pre[u] = p;
    // cout << u << " " << p << " " << ans << "\n";
    if(p != 1 && !q.count((Node) {p})) q.insert((Node) {p});
    // for(int k = 1; k <= n; k ++)
    //   cout << c[k][0] << " " << c[k][1] << "\n";
    // puts("--");
  }
  cout << ans << "\n";  
}


Measured memory_bytes: 20096
#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int main() {
	string s;
	getline(cin, s);
	int n = 0;
	for (char c : s) {
		if (c == '1')
			++n;
	}
	int m = int(s.size());
	printf("%d\n", min(n, m - n) * 2);
	return 0;
}


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

int main(){
    int x[15][15] = {0};
    int count = 0;
    int i,j,k;
    int n,d;
    double dis;

    scanf("%d %d",&n,&d);

    for(i = 1; i <= n ; i++){
        for(j = 1 ; j <= d; j++){
            scanf("%d",&x[i][j]);
        }
    }
    dis = 0;
    for(i = 1; i < n ; i++){
        for(k = i+1; k <= n ; k++){
            dis = 0;
            for(j = 1; j <= d ; j++){
            dis += (double)(x[i][j] - x[k][j]) * (double)(x[i][j] - x[k][j]);
            }
            //printf("%f\n",dis);
            dis = sqrt(dis);
            //printf("%f\n",dis);
            if(ceil(dis) == floor(dis)){
                count++;
            }
        }
    }
    printf("%d\n",count);

    return 0;



}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}
// v = compress(v);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    if(K <= (N+1)/2){
        cout << "YES" << enld;
    }else{
        cout << "NO" << enld;
    }
    return 0;
}

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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int result( vector<int>& d );

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

  vector<int> d( n ), cd;
  REP( i, n ){
    cin >> d[i];
    d[i] /= 10;
  }
  
  reverse_copy( ALL(d), back_inserter(cd) );

  if( result( d ) && result( cd ) ){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }
}

int result( vector<int>& d ){
  int dmax = 0;

  REP( i, d.size() ){
    if( dmax < i ) return 0;
    dmax = max( dmax, i + d[i] );
  }
  return 1;
}



Measured memory_bytes: 6140
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,s[3][105],x,answer;
	scanf("%d",&n);
	for(int i=1;i<=2;i++){
		for(int j=1;j<=n;j++){
			cin>>x,s[i][j]=s[i][j-1]+x;
		}
	}
	for(int i=1;i<=n;i++){
		answer=max(answer,s[1][i]+s[2][n]-s[2][i-1]);
	}
	printf("%d\n",answer);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
            if(i*j==n)
                cout<<"Yes"<<endl,exit(0);
    cout<<"No"<<endl;
}


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

int main()
{
   int n;
   cin >> n;
   vector<int> d(n);
   rep(i,n) cin >> d[i];

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
	int open,close,num;
	string kakko;
	open = close = 0;
	std::cin >> num;
	std::cin >> kakko;
	for (size_t i = 0; i < kakko.size(); i++) {
		if (kakko[i] == '(') {
			open++;
		}
		if (kakko[i] == ')') {
			if (open > 0) {
				open--;
			}
			else{
				close++;
			}
		}
	}

	for (size_t i = 0; i < close; i++) {
		std::cout << '(';
	}
	std::cout << kakko;
	for (size_t i = 0; i < open; i++) {
		std::cout << ')';
	}
	std::cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int x[5];

int main(void){
  int i;
  int tem=0;
  for(i=0;i<5;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<5;i++){
    if(x[i]==0){
      tem=i+1;
      printf("%d\n",tem);
    }
  }
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <cstdint>
#include <cassert>

using u32 = std::uint32_t;

template <class Monoid> class segment_tree {
public:
    using T = typename Monoid::value_type;
    using size_t = std::size_t;

private:
    std::vector<T> tree;

public:
    segment_tree() = default;
    explicit segment_tree(const size_t n) : tree(n * 2, Monoid::identity) {}

    size_t size() const noexcept { return tree.size() / 2; }

    T fold(size_t first, size_t last) const {
        assert(first <= last);
        assert(last <= size());
        first += size();
        last += size();
        T fold_l = Monoid::identity;
        T fold_r = Monoid::identity;
        while (first != last) {
            if (first % 2 != 0) {
                fold_l = Monoid::operation(fold_l, tree[first]);
                first += 1;
            }
            first /= 2;
            if (last % 2 != 0) {
                last -= 1;
                fold_r = Monoid::operation(tree[last], fold_r);
            }
            last /= 2;
        }
        return Monoid::operation(fold_l, fold_r);
    }

    void update(size_t index, const T x) {
        assert(index < size());
        index += size();
        tree[index] = x;
        while (index != 1) {
            index /= 2;
            tree[index] = Monoid::operation(tree[index * 2], tree[index * 2 + 1]);
        }
    }
};

struct BitOr {
    using value_type = u32;

    static constexpr u32 identity = 0;
    static u32 operation(u32 x, u32 y) {
        return x | y;
    };
};

int popcount(u32 bits) {
    bits = bits - (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = bits + (bits >> 4) & 0x0f0f0f0f;
    bits = bits * 0x01010101;
    return bits >> 24;
}

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

    segment_tree<BitOr> seg(n);
    for (int i = 0; i < n; ++i) {
        char c;
        std::cin >> c;

        seg.update(i, 1u << (c - 'a'));
    }

    int q;
    std::cin >> q;
    for (int i = 0; i < q; ++i) {
        int k;
        std::cin >> k;

        if (k == 1) {
            int x;
            char c;
            std::cin >> x >> c;

            seg.update(x - 1, 1u << (c - 'a'));
        }
        else {
            int l, r;
            std::cin >> l >> r;
            std::cout << popcount(seg.fold(l - 1, r)) << std::endl;
        }
    }
}

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

const long long linf = (1LL<<60);
const int mod = 1e9+7;

long long dfs(int K, const vector<vector<int>>&graph, int now, int from) {
  int can_use_color_num;
  if(from == -1) {
    can_use_color_num = K-1;
  } else {
    can_use_color_num = K-2;
  }

  if(K < graph[now].size()) {
    return 0;
  } else {
    long long case_num = 1;
    for(auto e : graph[now]) {
      if(e == from) continue;

      case_num *= can_use_color_num;
      can_use_color_num--;
      case_num %= mod;
    }
    for(auto e : graph[now]) {
      if(e == from) continue;
      case_num *= dfs(K, graph, e, now);
      case_num %= mod;
    }
    return case_num;
  }
}

int main() {
  int N, K; cin >> N >> K;
  vector<vector<int> > graph(N);
  for(int i = 0; i < N - 1; ++i) {
    int a, b; cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  long long ans = K * dfs(K, graph, 0, -1);
  ans %= mod;
  cout << ans << endl;

  return 0;
}


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


int main(){
  int n, m; cin >> n >> m;
  vector<pair<int, int>> pair(n);

  for(int i=0; i<n; ++i) cin >> pair[i].first >> pair[i].second;

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

  long long ans = 0;
  int cnt = 0;
  while(m--){
    if(pair[cnt].second == 0) ++cnt;
    ans += pair[cnt].first;
    --pair[cnt].second;
  }

  cout << ans << endl;
}


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

#include <iostream>
#include <vector>
// #include<list>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t large_product(long long n1, long long n2) {			// To deal with large numbers
   int128_t ans = (int128_t) n1 * n2;
   return ans;
}
#define l long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define rep(i,n) for (i = 0; i < n; i++) 
#define REP(i,k,n) for (i = k; i <= n; i++) 
#define REPR(i,k,n) for (i = k; i >= n; i--) 
#define pii pair<int,int>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl

int  main(int arg,char** argc)
{
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);    
    string s,t;
  cin>>s>>t;
  int flag=0;
  for(int i=0;i<s.length();i++){
    if(s[i]!=t[i])
    {
      flag=1;
      break;
    }
  }
  if(flag){
    no;
  }
  else{
    yes;
  }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main() {
  int H, W;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
S = input()

ls =[0 for i in range(2019)]
ls[0] += 1
p_amari = 0
ret = 0
len_s = len(S)
for i in range(len_s) :
	p_amari = ( int(S[len_s-1-i]) * pow(10, i, 2019) + p_amari ) % 2019
	ret += ls[p_amari]
	ls[p_amari] += 1
print(int(ret))

Measured memory_bytes: 68388
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define P pair
#define M 998244353
#define fr(i,n) for(int i=0;i<n;i++)
#define M2 1000000007
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
#define Take_n ll n; cin>>n;
using namespace std;

int main() 
{
	//your code
	int n,k,i,j;
	cin>>n>>k;
	int h[n];
	for(i=0;i<n;i++)
	cin>>h[i];
	int dp[n];
	for(i=0;i<n;i++)
	dp[i]=INT_MAX;
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		for(j=1;j<=k;j++)
		{
			if(j<=i)
			{
				dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 4372
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

const int INF = 1e9 + 7;
int q;

int main() {
	INIT
	long long n, a, b, ans = 0;
	cin >> n >> a >> b;
	if (a == 0) {
		cout << '0';
		return 0;
	}
	ans = 1ll * (n / (a + b)) * a + min(a, n % (a + b));
	cout << ans;

	return 0;
}

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

typedef long long int lli;

vector<int> move(string s, const vector<int> &cs) {
    vector<int> next(cs.size(), 0);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'L' ) {
            next[i-1] += cs[i];
        } else {
            next[i+1] += cs[i];
        }
    }
    return next;
}

int main() {
    string s; cin >>s;
    vector<int> cs(s.size(), 1);

    vector<int> nearL(s.size(), 0);
    vector<int> nearR(s.size(), 0);
    vector<int> ans(s.size(), 0);
    int m = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            m = i;
        }
        nearL[i] = m;
    }
    m = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            m = i;
        }
        nearR[i] = m;
    }

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            int idx = nearL[i];
            int diff = idx - i;
            if (diff % 2 == 1) {
                ans[idx - 1] += 1;
            } else {
                ans[idx] += 1;
            }
        } else {
            int idx = nearR[i];
            int diff = i - idx;
            if (diff % 2 == 1) {
                ans[idx + 1] += 1;
            } else {
                ans[idx] += 1;
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int main(void){

//??????
/*	int d, c;

	cin >> d >> c;

	cout << d * c << endl;
	*/
//??????
/*	int c1, c5, c10, c50, c100, c500;

	cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;

	if (c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500 >= 1000)
		cout << '1' << endl;
	else cout << '0' << endl;
	*/
//??????
/*	int n, k, p;

	cin >> n;
	for (int i = 0; i < n; i++){

		cin >> k >> p;

		if (k % p == 0){
			cout << p;
		}
		else cout << k % p;
		cout << endl;
	}
	*/
//??????
	int n, n2;
	int h[101], m[101], k[101], g[101];
	int minute_n[101];
	int minute_n2[101];

	cin >> n;
	for (int i = 0; i < n; i++){

		cin >> h[i] >> m[i];
		minute_n[i] = h[i] * 60 + m[i];
	}

	cin >> n2;
	for (int i = 0; i < n2; i++){

		cin >> k[i] >> g[i];
		minute_n2[i] = k[i] * 60 + g[i];
	}

	int i = 0, j = 0;
	while (i != n || j != n2){

		if (i != n && j != n2){
			if (minute_n[i] == minute_n2[j]){

				if (m[i] >= 10)
					cout << h[i] << ':' << m[i];
				else
					cout << h[i] << ":0" << m[i];
				i++; j++;
			}
			else if (minute_n[i] < minute_n2[j]){

				if (m[i] >= 10)
					cout << h[i] << ':' << m[i];
				else
					cout << h[i] << ":0" << m[i];
				i++;
			}
			else{

				if (g[j] >= 10)
					cout << k[j] << ':' << g[j];
				else
					cout << k[j] << ":0" << g[j];
				j++;
			}
		}
		else if (j == n2){

			if (m[i] >= 10)
				cout << h[i] << ':' << m[i];
			else
				cout << h[i] << ":0" << m[i];
			i++;
		}

		else{

			if (g[j] >= 10)
				cout << k[j] << ':' << g[j];
			else
				cout << k[j] << ":0" << g[j];
			j++;
		}
		

		if (!(i == n && j == n2)) cout << ' ';
		else cout << endl;
	}
}

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

typedef long long ll;
const ll N = 1e6 + 77;
const ll inf = 1e18;

int main()
{
  ll n, b, used[N] = {0}, ans = 0;
  scanf("%lld", &n);
  b = n;
  if (n == 1)
  {
    printf("0\n");
    return 0;
  }
  ll i = 2;
  for (i = 2; i * i <= b; i++)
  {
    if (used[i])
      continue;
    if (n % i == 0)
    {
      ll c = 0, div = i;
      while (n % div == 0)
      {
        c++;
        n /= div;
        used[div] = 1;
        div *= i;
      }
      ans += c;
      while (n % i == 0)
      {
        n /= i;
      }
    }
  }
  // cout << n << endl;
  // for (i = 2; i * i <= n; i++)
  // {
  //   if (n % i == 0)
  //   {
  //     while (n % i == 0)
  //     {
  //       n /= i;
  //     }
  //   }
  // }
  if (n > 1)
    ans += 1;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 11640
import java.util.*;

public class Main {

	private long gcd(long a, long b){
		if(b == 0)  return a;
		else        return gcd(b, a%b);
	}
	
	private long lcm(long a, long b){
		return a / gcd(a, b) * b;
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			long [] data = new long[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextLong();
			}
			
			long res = 1;
			for(int i= 0; i < n; i++){
				res = lcm(res, data[i]);
			}
			System.out.println(res);
		}

	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

#define lint long long
#define P pair<lint, int>


signed main() {
    int N, K;
    cin >> N >> K;

    int t[N]; lint d[N];

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

    vector<P> lis;
    for(int i = 0; i < N; ++i){
        pair<lint, int> tmp = make_pair(d[i], t[i]);
        lis.push_back(tmp);
        
    }

    sort(lis.begin(), lis.end(), greater<P>());

    lint ans;
    lint sum = 0;
    set<int> sp;
    map<int, int> cnt;
    for(int i = 0; i < K; ++i){
        sum += lis[i].first;
        sp.insert(lis[i].second);
        cnt[lis[i].second]++;
    }

    ans = sum + (lint)(sp.size() * sp.size());

    priority_queue<P, vector<P>, greater<P>> unti;
    priority_queue<P, vector<P>, less<P>> tinko;

    for(int i = 0; i < K; ++i){
        unti.push(lis[i]);
    }
    for(int i = K; i < N; ++i){
        tinko.push(lis[i]);
    }



    while(!tinko.empty()){
        P tmp = tinko.top(); tinko.pop();
        if(cnt[tmp.second]){
            continue;
        }

        bool flag = false;

        while(!unti.empty()){
            P buri = unti.top(); unti.pop();
            if(cnt[buri.second] < 2){
                continue;
            }

            sum -= buri.first;
            cnt[buri.second]--;
            flag = true;
            break;
        }

        if(!flag){
            continue;
        }
        sum += tmp.first;
        cnt[tmp.second]++;
        sp.insert(tmp.second);

        ans = max(ans, sum + (lint)(sp.size() * sp.size()));

    }

    cout << ans << endl;


}


Measured memory_bytes: 11760