akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a;
  int temp;
  rep(i,n){ 
    cin >> temp;
    a.push_back(temp);
  }
  int no1 = 0;
  int no2 = 0;
  vector<int> no1index;
  int no2index = 0;
  rep(i,n){
    if (no1 < a[i]) {
      no2 = no1;
      no2index = no1index[0];
      swap(no1, a[i]);
      no1index.clear();
      no1index.push_back(i);
    }
    else if (no1 == a[i]){
      no1index.push_back(i);
    }
    if (no2 < a[i]) {
      no2 = a[i];
      no2index = i;
    }
  }

  vector<int> ans(n,no1);
  for(auto& i : no1index){
    ans[i] = no2;
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
  
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	long long sum=0;
	vector<int> vec(n);
	for(int i=0;i<n;++i)
	{
	    cin>>vec[i];
	    sum+=vec[i];
	}
	
	double temp=(double)sum/(4*m);
	int count=0;
	for(int i=0;i<n;++i)
	{
	    if(vec[i]>=temp)
	    count++;
	}
	if(count>=m)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
using namespace std;
typedef long long int ll;

void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i+1;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}



int main() {
    ll X;
    cin >> X;
    ll result = 0;
    result += (X/500)*1000;
    X = X % 500;
    result += (X/5)*5;
    cout << result << endl;


}


Measured memory_bytes: 256
N = int(input())
S = [list(input()) for i in range(N)]

A = []
B = []

for i in range(N):
    a = 0  # (の個数
    b = 0  # )の個数
    c = 0  # 始点に対する最下点の高さ（(を+1,)を-1とみなす）
    for j in range(len(S[i])):
        if S[i][j] == '(':
            a += 1
        else:
            b += 1
            c = min(a-b,c)
    if a-b >= 0:
        A.append((a-b,c))  # (何個高くなるか,最下点の相対的高さ)
    else:
        B.append((a-b,c))  # (何個高くなるか,最下点の相対的高さ)

a,b = len(A),len(B)

from operator import itemgetter

A = sorted(A,key=itemgetter(1),reverse=True)

c = 0  # Aの元を全て繋げた時,何個高くなるか

for i in range(a):
    if c + A[i][1] < 0:
        print('No')
        exit()
    else:
        c += A[i][0]

for i in range(b):
    B[i] = (-B[i][0],B[i][1]-B[i][0])

B = sorted(B,key=itemgetter(1),reverse=True)

d = 0  # Bの元を全て繋げた時,何個高くなるか

for i in range(b):
    if d + B[i][1] < 0:
        print('No')
        exit()
    else:
        d += B[i][0]

if c == d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 286076
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
INF=10**9

def dfs(cur,a,b,c):
  if cur == N:
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
  ret0=dfs(cur+1,a,b,c)
  ret1=dfs(cur+1,a+l[cur],b,c)+10
  ret2=dfs(cur+1,a,b+l[cur],c)+10
  ret3=dfs(cur+1,a,b,c+l[cur])+10
  return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

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

#define INF 100000000



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

    stack<int> a;
    a.push(s[0]);
    rep2(i,1,n){
        if(s[i] != a.top()) a.push(s[i]);
    }

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

    return 0;
}


Measured memory_bytes: 768
#include<cstdio>
using namespace std;

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        int ans;
        if(a==b&&a==c)
            ans=1;
        else if(a!=b&&a!=c&&b!=c)
            ans=3;
        else
            ans=2;
        printf("%d\n",ans);
    }
    return 0;
}


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

int main(){
  string s,t;
  cin >>s >>t;
  string modt;
  rep(i,s.size()){
    modt += t[i];
  }
  if(s==modt) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
	
using namespace std;

typedef long long LL;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100010;

struct man{
	int a,b;
}a[N];
LL ans,sum;
int X,Y,Z;
int n;
int numa[N],numb[N],num[N],ta[N],tb[N];
int wa,wb;
LL va,vb;
bool bza[N],bzb[N];

bool cmpa(int x,int y){
	return a[x].a>a[y].a;
}

bool cmpb(int x,int y){
	return a[x].b>a[y].b;
}

bool cmp(int x,int y){
	return a[x].b-a[x].a>a[y].b-a[y].a;
}

int main(){
	X=get();Y=get();Z=get();
	n=X+Y+Z;
	fo(i,1,n){
		int x=get(),y=get(),z=get();
		sum=sum+x;
		y-=x;z-=x;
		a[i].a=y;a[i].b=z;
		numa[i]=numb[i]=num[i]=i;
	}
	sort(numa+1,numa+1+n,cmpa);
	sort(numb+1,numb+1+n,cmpb);
	sort(num+1,num+1+n,cmp);
	fo(i,1,n)ta[numa[i]]=i,tb[numb[i]]=i,bza[i]=1;
	fo(i,1,Z)vb=vb+a[num[i]].b,bzb[num[i]]=1,bza[num[i]]=0;
	wb=n;
	int tot=0;
	wa=0;va=0;
	while(wa<n&&tot<Y){
		wa++;
		if (bza[numa[wa]])tot++,va=va+a[numa[wa]].a;
	}
	ans=sum+va+vb;
	fo(i,Z+1,n-Y){
		bzb[num[i]]=1;
		bza[num[i]]=0;
		if (tb[num[i]]<=wb){
			vb=vb+a[num[i]].b;
			while(!bzb[numb[wb]])wb--;
			vb=vb-a[numb[wb]].b;
			wb--;
		}
		if (ta[num[i]]<=wa){
			va=va-a[num[i]].a;
			tot--;
			while(wa<n&&tot<Y){
				wa++;
				if (bza[numa[wa]])tot++,va=va+a[numa[wa]].a;
			}
		}
		if (sum+va+vb>ans)ans=sum+va+vb;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  string S;
  int N;
  cin>>N>>S;
  for(int i=0;i<S.size();i++){
    S[i]+=N;
    if(S[i]>'Z'){
      S[i]-=26;
    }
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-Ofast"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;

using namespace std;

const int MX = 307;

ld f[MX + 5][MX + 5][MX + 5];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            c1++;
        } else if (x == 2) {
            c2++;
        } else {
            c3++;
        }
    }

    for (int k = 0; k < MX; k++) {
        for (int j = 0; j + k < MX; j++) {
            for (int i = 0; i + j + k < MX; i++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                if (i + j + k > MX) {
                    continue;
                }
                ld wait = 1.0 * n / (i + j + k);
                ld pi = 1.0 * i / (i + j + k);
                ld pj = 1.0 * j / (i + j + k);
                ld pk = 1.0 * k / (i + j + k);

                if (i) {
                    f[i][j][k] += pi * f[i - 1][j][k];
                }
                if (j) {
                    f[i][j][k] += pj * f[i + 1][j - 1][k];
                }
                if (k) {
                    f[i][j][k] += pk * f[i][j + 1][k - 1];
                }
                f[i][j][k] += wait;
            }
        }
    }

    cout.precision(10);
    cout << fixed << f[c1][c2][c3] << "\n";
    return 0;
}



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

int main(){
    long long a,b,n;
    cin >> a >> b >> n;
    long long ans;
    if(b > n){
        /*f(n)*/
        ans = (a*n)/b;
    }
    else{
        /*f(b - 1)*/
        ans = (a*(b - 1))/b;
    }

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

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>

int main(){
	int a,b,sum = 0,num = 0,i = 0;
	while(scanf("%d,%d",&a,&b) != EOF){
		sum += a * b;
		num += b;
		i++;
	}
	printf("%d\n%d\n",sum,(int)floor((double)num / i + 0.5));
	return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
		int num = in.nextInt();	
		int a = num/100;
		int b = num%100/10;
		int c = num%100%10;
		if(num == c*100+b*10+a)
		{
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n;
    m=n;
    while(m>0)
    {
        sum+=m%10;
        m/=10;
    }
    if(n%sum==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>

int const max_N = 1e5;

int main() {
    int N, x[max_N + 1], y[max_N + 1], t[max_N + 1];
    x[0] = 0;
    y[0] = 0;
    t[0] = 0;
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) {
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }

    for (int i = 1; i <= N; ++i) {
        int tmp = std::fabs(x[i] - x[i - 1]) + std::fabs(y[i] - y[i - 1]);
        if (tmp > t[i] - t[i - 1] || tmp % 2 != (t[i] - t[i - 1]) % 2) {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
	ll n,k;
  	cin >> n >> k;
  	vl h(n);
  	ll kaisu =0;
  	rep(i,n) cin >> h[i];
  	sort(all(h)) ; 
  	rep(i,k) h.pp();
  	rep(i,h.size()) kaisu+=h[i];
    cout << kaisu << endl;
 	
  	return 0;
}

Measured memory_bytes: 1792
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,lint> pl;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint dp[100100][2];
lint a[100100];
int main()
{
	int n;cin>>n;
	rep(i,n) cin>>a[i];
	lint inf=1E16;
	rep(i,100010) dp[i][0]=dp[i][1]=-inf;
	dp[0][0]=0;
	rep(i,n-1){
		dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
		dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
	}
	cout<<max(dp[n-1][0]+a[n-1],dp[n-1][1]-a[n-1])<<endl;
}


Measured memory_bytes: 2560
#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 vpii = vector<pll>;

int main(){
  vl arr(3);
  rep(i, 3){
    cin >> arr[i];
  }

  stable_sort(arr.begin(), arr.end());

  if((arr[0] == 5) && (arr[1] == 5) && (arr[2] == 7)){
    cout << "YES" << endl;
  } else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;

namespace DefaultNamespace
{
	
	public class Stuck
	{
		
		public  static void Main(string[] args)
		{
			string read=Console.ReadLine();
			string[] dataArray=read.Split();
			Answer ans= new Answer();
			Console.WriteLine(ans.answer(dataArray));
			
		}
		/*public static int answer(string[] s)
		{
		   // ?????????????????????push ???????????????pop ?????????????????????????????\
		   //string?????????s[]????????????????????????????????????????????????????????????????????????????????????????????????
		   for(int i=0;i<s.Length;i++){
		   int number=0;
		   if(int.TryParse(s[i],out number))
		      {
		   	push(number);
		      }
		   else{//???????????????????????????????????????
		   	calc(s[i]);
		   }
		   }
		   return stuck[1];
		}
		public static  void push(int num)
		{
			sPointer++;
			stuck[sPointer]=num;
			
		}
		
		public  static void calc(string ope)
		{//???????????????????????§switch
			int temp=0;
			switch(ope){//????????????????????????????????§????????????
					case "+": temp =stuck[sPointer-1]+stuck[sPointer];
					break;
					case "-": temp =stuck[sPointer-1]-stuck[sPointer];
					break;
					case "*": temp =stuck[sPointer-1]*stuck[sPointer];
					break;
					case "/": temp=stuck[sPointer-1]/stuck[sPointer];
					break;
			}
			sPointer-=2;
			push(temp);
			
		}
		*/
	}
	public class Answer
	{
		public  int sPointer=0;
		public  int[] stuck=new int[101] ;
	public  int answer(string[] s)
		{
		   // ?????????????????????push ???????????????pop ?????????????????????????????\
		   //string?????????s[]????????????????????????????????????????????????????????????????????????????????????????????????
		   for(int i=0;i<s.Length;i++){
		   int number=0;
		   if(int.TryParse(s[i],out number))
		      {
		   	push(number);
		      }
		   else{//???????????????????????????????????????
		   	calc(s[i]);
		   }
		   }
		   return stuck[1];
		}
		public   void push(int num)
		{
			sPointer++;
			stuck[sPointer]=num;
			
		}
		
		public   void calc(string ope)
		{//???????????????????????§switch
			int temp=0;
			switch(ope){//????????????????????????????????§????????????
					case "+": temp =stuck[sPointer-1]+stuck[sPointer];
					break;
					case "-": temp =stuck[sPointer-1]-stuck[sPointer];
					break;
					case "*": temp =stuck[sPointer-1]*stuck[sPointer];
					break;
					case "/": temp=stuck[sPointer-1]/stuck[sPointer];
					break;
			}
			sPointer-=2;
			push(temp);
			
		}
	}
}

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

int main(){
    int n,k;cin>>n>>k;
    int P[n+1],C[n+1];
    rep(i,n){
        scanf("%d",&P[i+1]);
    }
    rep(i,n){
        scanf("%d",&C[i+1]);
    }
    ll ans=-1e18;
    for(int i=1;i<=n;i++){
        int j=i;
        ll candidate;
        vector<int> loop;
        ll sum=0;
        while(1){
            loop.push_back(C[j]);
            sum+=C[j];
            j=P[j];
            if(j==i)break;
        }
        candidate=0;
        int l=loop.size();
        ll now=0;
        rep(si,l){
            now+=loop[si];
            if(si+1>k)break;
            candidate=now;
            if(sum>0){
                ll e=(k-(si+1))/l;
                candidate+=sum*e;
            }
            ans=max(ans,candidate);
        }
    }
    cout<<ans<<endl;
}

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

int exp(int a, int n) {
  if(n == 0) return 1;
  else {
    int ret = exp(a, n-1)*a;
    return ret;
  }
}

int main() {
  int a; 
  cin >> a;
  int ans = 0;
  ans = exp(a, 3) + exp(a, 2) + exp(a, 1);
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
typedef long long ll;
 
int N,K;
 
int A[14][10];
int B[14][10];
 
int check(int y,int m){
  if(m==2){
    if(y%400==0)return 29;
    else if(y%100==0)return 28;
    else if(y%4==0)return 29;
    else return 28;
  }else if(m==4||m==6||m==9||m==11)return 30;
  else return 31;
}
 
ll t[100];
ll u[100];
 
void make(){
  int y=0,m=1,d=1;
  while(y<10000){
     
    int sum=0;
    sum+=B[0][y/1000];
    sum+=B[1][(y/100)%10];
    sum+=B[2][(y/10)%10];
    sum+=B[3][y%10];
    sum+=B[4][m/10];
    sum+=B[5][m%10];
    sum+=B[6][d/10];
    sum+=B[7][d%10];
    t[sum]++;
 
    d++;
    int last=check(y,m);
    if(d>last){
      d=1;m++;
    }
    if(m>12){
      m=1;y++;
    }
  }
}
 
void make2(){
  int h=0,m=0,s=0;
  while(h<24){
 
    int sum=0;
    sum+=B[8][h/10];
    sum+=B[9][h%10];
    sum+=B[10][m/10];
    sum+=B[11][m%10];
    sum+=B[12][s/10];
    sum+=B[13][s%10];
    u[sum]++;
     
    s++;
    if(s>59){
      s=0;m++;
    }
    if(m>59){
      m=0;h++;
    }
  }
}
 
void init(){
  for(int i=0;i<14;i++){
    for(int j=0;j<10;j++){
      A[i][j]=1;
      B[i][j]=0;
    }
  }
  for(int i=0;i<100;i++)t[i]=u[i]=0;
}
 
int main(){
  while(cin>>N>>K){
    init();
    for(int i=0;i<K;i++){
      int a,b;
      cin>>a>>b;
      A[a][b]=0;
    }
    for(int i=0;i<14;i++){
      B[i][1]=A[i][2]+A[i][5];
      B[i][2]=A[i][0]+A[i][2]+A[i][3]+A[i][4]+A[i][6];
      B[i][3]=A[i][0]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
      B[i][4]=A[i][1]+A[i][2]+A[i][3]+A[i][5];
      B[i][5]=A[i][0]+A[i][1]+A[i][3]+A[i][5]+A[i][6];
      B[i][6]=A[i][0]+A[i][1]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
      B[i][7]=A[i][0]+A[i][2]+A[i][5];
      B[i][8]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][4]+A[i][5]+A[i][6];
      B[i][9]=A[i][0]+A[i][1]+A[i][2]+A[i][3]+A[i][5]+A[i][6];
      B[i][0]=A[i][0]+A[i][1]+A[i][2]+A[i][4]+A[i][5]+A[i][6];
    }
    make();
    make2();
 
    ll ans=0;
    for(int i=0;i<=N;i++){
      ans+=t[i]*u[N-i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}


int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}


int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}


int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int n,k;
  cin>>n>>k;
  map<int,int> m;
  for(int i=0;i<k;i++){
    int j;
    cin>>j;
    for(int k=0;k<j;k++){
      int h;
      cin>>h;
      m[h]++;
    }
  }
  cout<<n-m.size();
}

Measured memory_bytes: 3632
#include <iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	
	int n,k;
	cin>>n>>k;
	
	vector<long long> h(n);
	
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	sort(h.begin(),h.end());
	
	vector<long long> sa(n-k+1);
	
	for(int i=0;i<n-k+1;i++)
	{
		sa[i]=h[i+k-1]-h[i];
	}
	
	sort(sa.begin(),sa.end());
	
	cout<<sa[0]<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[5]=='1'){
        cout<<"TBD"<<endl;
    }
    else if(s[6]=='1' || s[6]=='2' || s[6]=='3'){
        cout<<"Heisei"<<endl;
    }
    else if(s[6]=='4'){
        if(s[7]=='3' && s[8]=='1'){
            cout<<"TBD"<<endl;
        }
        else cout<<"Heisei"<<endl;
    }
    else cout<<"TBD"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{

    long int a,b,k,p,q;
    scanf("%li %li %li",&a,&b,&k);

    if(a+b<k)
      {

       p=0;
       q=0;
       printf("%li %li\n",p, q);
       return 0;

      }


       else if(a>k)
          {
              p=a-k;
              q=b;
         printf("%li %li\n",p, q);
         return 0;

          }


         else if(a<k);
        {
              p=0;
             q=b-(k-a);
        printf("%li %li\n",p, q);

        }


return 0;

 }

Measured memory_bytes: 128
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b<10)
        cout<<a+b<<endl;
    else
        cout<<"error"<<endl;
    return 0;
}





















Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

const int MAX = 55556;

int main() {
	bool table[MAX] = { false };

	for (int i =2; i < MAX; i++) {
		if (table[i])continue;
		for (int j = i * 2; j < MAX; j += i) {
			table[j] = true;
		}
	}

	int n;
	cin >> n;

	for (int i = 2; i < MAX; i++) {
		if (table[i])continue;
		if (i % 5 == 1) {
			cout << i;
			n--;
			if (n == 0)break;
			else cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
int ar[N];
vector<int> lis;
vector<pair<int,int> > ans;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,now;
	string s;
	cin>>s;
	n=s.size();
	s=' '+s;
	if(s[n]=='1'){
		cout<<-1;
		return 0;
	}
	if(s[1]=='0'){
		cout<<-1;
		return 0;
	}
	for(i=1;i<n;i++){
		if(s[i]!=s[n-i]){
			cout<<-1;
			return 0;
		}
		if(s[i]=='1'){
			lis.push_back(i);
		}
	}
	now=lis.size()+1;
	for(i=0;i<lis.size();i++){
		ans.push_back({i+1,i+2});
		if(i){
			k=lis[i]-lis[i-1]-1;
		}
		else{
			k=lis[0]-1;
		}
		for(j=1;j<=k;j++){
			now++;
			ans.push_back({i+1,now});
		}
	}
	for(i=0;i<ans.size();i++){
		cout<<ans[i].first<<' '<<ans[i].second<<'\n';
	}
}

Measured memory_bytes: 2788
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  int N;
  cin >> N;
  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    cin >> A[i];
    A[i]--;
  }
  vector<int> B(N);
  for (int i = 0; i < N - 1; i++)
  {
    B[A[i]]++;
  }
  for (int i = 0; i < N; i++)
  {
    cout << B[i] << endl;
  }
}


Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>

using namespace std;


int main(){
    int d;
    cin >> d;
    int arr[d];
    for (int i = 0; i < d; i++){
        int tmp;
        cin >> tmp;
        arr[i] = tmp;
    }
    sort(arr, arr+d);
    int total = 0;
    for (int i = 0; i < d-1; i++){
        total +=  arr[i];
    }
    total += arr[d-1]/2;
    cout << total << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int x, n;
    cin >> x >> n;
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];
    sort(p.begin(), p.end());
    int res = 1000;
    int res_abs = 1000;
    for (int i = -1; i <= 101; ++i) {
        if (find(p.begin(), p.end(), i) != p.end()) continue;
        int tmp = abs(x - i);
        if (tmp < res_abs) {
            res = i;
            res_abs = tmp;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
# Author: cr4zjh0bp
# Created: Mon Mar  9 08:21:56 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A, B = na()

print(A * B - (A + B - 1))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>

using namespace std;


int main(){

    priority_queue<pair<int,int>> pque;

    //入力
    long long n,m;
    cin >> n >> m;
    vector<long long> a(n);
    for(long long i = 0; i < n; i++){
        cin >> a[i];
        pque.push(make_pair(a[i], 1));
    }
    vector<long long> b(m);
    vector<long long> c(m);
    for(long long i = 0; i < m; i++){
        cin >> b[i] >> c[i];
        pque.push(make_pair(c[i], b[i]));
    }

    long long sum = 0;
    for(long long i = 0; i < n; i++){
        auto p = pque.top();
        pque.pop();
        sum += p.first;

        if(p.second > 1){
            p.second--;
            pque.push(p);
        }
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 4852
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;

signed main() {
	cin >> n;
	cout << (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int abs(int num){
  return num<0?-num:num;
}
int main(){
  int n;cin>>n;
  int a[n];
  for(int i=0;i<n;i++)	cin>>a[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    map<string,int>m;
    for(int i=0;i<n;++i){
        string s;
        cin>>s;
        m[s]++;
    }
    int ans=0;
    for(auto x:m){
        if(x.second%2)ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;
using i64 = long long;
using f64 = double;

#define FOR(i, s, n) for (size_t i = (s); i < (size_t)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

template <typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b ? (a = b, true) : false;
}

template <typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b ? (a = b, true) : false;
}

int main() {
  int n;
  cin >> n;
  auto count = 0;
  int d[2];
  REP(i, n) {
    REP(j, 2) {
      cin >> d[j];      
    }
    if (d[0] == d[1]) {
      count++;
      if (count >= 3) {
        cout << "Yes"; 
        return 0;
      }
    } else {
       count = 0;
    }
  }

  cout << "No";
  return 0;
}


Measured memory_bytes: 3628
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Control.Monad.ST
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Mutable as VM
import qualified Data.ByteString.Char8 as B
import Debug.Trace

constructN' :: Int -> (V.Vector a -> a) -> V.Vector a
constructN' !n !f = runST $ do
  v  <- VM.new n
  v' <- V.unsafeFreeze v
  fill v' 0
 where
  fill !v i | i < n =
    let x = f $ V.unsafeTake i v
    in  x `seq` do
          v' <- V.unsafeThaw v
          VM.unsafeWrite v' i x
          v'' <- V.unsafeFreeze v'
          fill v'' (i + 1)
  fill v _ = return v

solve :: Int -> VU.Vector Int -> Int
solve !n !an = fst $ VU.head $ V.last dp
 where
  dp :: V.Vector (VU.Vector (Int, Int))
  dp = constructN'
    n
    (\(!vec) ->
      let !i = V.length vec
      in  VU.map
              (\(!j) -> if i == 0
                then let z = an VU.! j in (0, z)
                else minimum
                  [ let (c1, s1) = vec V.! k VU.! j
                        (c2, s2) = vec V.! (i - k - 1) VU.! (j + k + 1)
                        s        = s1 + s2
                    in  (c1 + c2 + s, s)
                  | k <- [0 .. i - 1]
                  ]
              )
            $ VU.fromList [0 .. n - i - 1]
    )

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n an


Measured memory_bytes: 6140
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

ll l[51], p[51];

ll calc(ll N, ll X){
  if (X==0) return 0;
  else if (N==0) return 1;
  else if (X<=l[N-1]+1) return calc(N-1,X-1);
  else {
    X -= l[N-1] + 1;
    return p[N-1] + 1 + calc(N-1,X-1);
  }
}

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

  l[0] = 1;
  p[0] = 1;
  rep(i,N) l[i+1] = 2*l[i] + 3;
  rep(i,N) p[i+1] = 2*p[i] + 1;

  cout << calc(N,X) << endl;



  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int maxV = 10005;

vector<int> to[maxV];

bool visited[maxV];
void dfs(int i, vector<int>& ans) {
    if (visited[i]) return;
    visited[i] = true;
    for (int e : to[i]) {
        dfs(e, ans);
    }
    ans.push_back(i);
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int V, E;
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        to[s].push_back(t);
    }
    vector<int> ans;
    for (int i = 0; i < V; i++) {
        dfs(i, ans);
    }
    for (int i = V - 1;  i>= 0; i--) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

int n, ans = 0;

void check(vector<int> v) {
  long long p = 1;
  for (int i = 0; i < n; i++) {
    p *= v[i];
  }
  if (p%2 == 0) {
    ans++;
  }
  return;
}

void dfs(vector<int> v, int cnt) {
  if (cnt == n) {
    check(v);
    return;
  }
  int tmp = v[cnt];
  dfs(v, cnt + 1);
  v[cnt] = tmp - 1;
  dfs(v, cnt + 1);
  v[cnt] = tmp + 1;
  dfs(v, cnt + 1);
  v[cnt] = tmp;
  return;
}

int main() {
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  dfs(v, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));

$a = (int) $a;
$b = (int) $b;

if ($a < $b) {
    echo "a < b\n";
} elseif ($a == $b) {
    echo "a == b\n";
} else {
    echo "a > b\n";
}
?>


Measured memory_bytes: 9192
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
 
int main() {
  int w, h;
  while (cin >> w >> h, w || h) {
    int maps[h][w];
    //step,LR,x,y;
    priority_queue<pair<pair<int,bool>,pair<int,int> > >qu;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
    {
      char tmp;
      cin>>tmp;
      maps[i][j]=tmp-'0';
      if(tmp=='X')
        maps[i][j]=-1;
      if(tmp=='S')
        {
          qu.push(make_pair(make_pair(0,false),make_pair(i,j)));
          qu.push(make_pair(make_pair(0,true),make_pair(i,j)));
          maps[i][j]=0;
        }
      if(tmp=='T')
        maps[i][j]=-2;
    }
    /*
    for(int i=0;i<h;i++,cout<<endl)
      for(int j=0;j<w;j++)
    {
      cout<<"i,j="<<i<<","<<j<<" ";
      cout<<maps[i][j]<<" ";
    }
    */
    int ans = -1;
    int dy[]={1,1,1,1,1,2,2,2,3};
    int dx[]={2,1,0,-1,-2,-1,0,1,0};
    bool closed[2][h][w];
    memset(closed,false,sizeof(closed));
    while(!qu.empty())
      {
    int step=-qu.top().first.first;
    bool foot =qu.top().first.second;
    pair<int,int> pos=qu.top().second;
    int x=pos.first;
    int y=pos.second;
    qu.pop();
    //  cout<<step<<" "<<foot<<" "<<x<<" "<<y<<endl;
    if(closed[foot][x][y])
      continue;
    closed[foot][x][y]=true;    
    for(int i=0;i<9;i++)
      {
        int ny=y;
        int nx=x+dx[i];
        if(foot)
          ny+=dy[i];
        else
          ny-=dy[i];
        if(nx>=0 && nx<h &&
           ny>=0 && ny<w)
          {
        if(maps[nx][ny]==-2)
          {
            ans=step;
            break;
          }
        if(maps[nx][ny]>=0 && !closed[!foot][nx][ny])
          {
            qu.push(make_pair(make_pair(-(step+maps[nx][ny]),!foot),make_pair(nx,ny)));
            //cout<<"next: ";
            //cout<<step<<"+"<<maps[nx][ny]<<" "<<!foot<<" "<<nx<<" "<<ny<<endl;
          }
          }
      }
    if(ans!=-1)
      break;
      }
    cout << ans << endl;
     
  }
  return 0;
}

Measured memory_bytes: 1276
#include <string>
#include <iostream>
using namespace std;
const int mod = 998244353;
int n, dp[200009][3][3]; string s;
int main() {
	cin >> s;
	n = s.size();
	dp[1][0][0] = dp[1][1][1] = dp[1][2][2] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				for (int l = 0; l < 3; ++l) {
					if (j == l) continue;
					dp[i + 1][j][k] += dp[i][l][(k - j + 3) % 3];
					if (dp[i + 1][j][k] >= mod) dp[i + 1][j][k] -= mod;
				}
			}
		}
	}
	bool f = false, f2 = false;
	for (int i = 1; i < n; ++i) {
		if (s[i] != s[i - 1]) f = true;
		if (s[i] == s[i - 1]) f2 = true;
	}
	if (!f) cout << 1 << '\n';
	else if (s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba") {
		cout << 3 << '\n';
	}
	else {
		int v = 0;
		for (int i = 0; i < n; ++i) {
			v = (v + (s[i] - 'a')) % 3;
		}
		int eli = 1;
		for (int i = 1; i < n; ++i) {
			eli = 3LL * eli % mod;
		}
		cout << (eli + mod - ((dp[n][0][v] + dp[n][1][v]) % mod + dp[n][2][v]) % mod + (f2 ? 0 : 1)) % mod << '\n';
	}
	return 0;
}

Measured memory_bytes: 7556
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int main(){
	int r,g,b,n;
	cin>>r>>g>>b>>n;
	int cnt=0;
	for(int i=0;i*r<=n;i++){
		for(int j=0;i*r+j*g<=n;j++){
			int re=n-i*r-j*g;
			if(re%b==0) cnt++;
		}
	}
	cout<<cnt;
}

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

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	std::vector<std::pair<long long, int>> AB(N);
	for (auto& e: AB)
		scanf("%d%d", &e.first, &e.second);
	std::sort(AB.begin(), AB.end());
	long long cost{};
	for (auto& e: AB)
	{
		if (e.second < M)
		{
			cost += e.second * e.first;
			M -= e.second;
		}
		else
		{
			cost += M * e.first;
			break;
		}
	}
	printf("%lld\n", cost);

	return 0;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())

a_b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_b_list.append({'yen':a, 'n_drink':b})
a_b_list.sort(key=lambda x: x['yen'])

n_leftover = m
yen_spent = 0
for i in range(n):
    n_drink = a_b_list[i]['n_drink']
    yen = a_b_list[i]['yen']
    if a_b_list[i]['n_drink'] < n_leftover:
        yen_spent += n_drink * yen
        n_leftover -= n_drink
    else:
        yen_spent += n_leftover * yen
        print(yen_spent)
        exit()

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine().Split('/');
		if(s[0].ToInt() < 2019)
		{
			Console.WriteLine("Heisei");
			return;
		}
		
		if(s[1].ToInt() < 5)
		{
			Console.WriteLine("Heisei");
			return;
		}
		Console.WriteLine("TBD");
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    int all = 0;
    rep(i, N) cin >> vec[i];
    int ans = 1e9;
    FOR(i, -100, 101) {
        int tmp = 0;
        rep(j, N) tmp += (vec[j] - i) * (vec[j] - i);
        ans = min(tmp, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int main() {
  int V, E;
  cin >> V >> E;

  int link[V];
  int available[V];
  REP(i, V) {
    link[i] = 0;
    available[i] = 1;
  }
  vector<int> G[V];
  REP(i, E) {
    int s, t;
    cin >> s >> t;
    G[s].push_back(t);
    link[t]++;
  }

  // priority_queue<pair<int, int> , vector<pair<int, int> >, greater<pair<int, int> > > Q; // (link, vertex id)
  // REP(i, V) {
  //   Q.push(make_pair(link[i], i));
  // }

  REP(_, V) {
    int minv = -1;
    int minlink = 1 << 21;
    REP(i, V) {
      if (link[i] < minlink && available[i]) {
        minlink = link[i];
        minv = i;
      }
    }

    assert(minlink == 0);
    assert(minv != -1);
    cout << minv << endl;
    available[minv] = 0;

    for (vector<int>::iterator it = G[minv].begin(); it != G[minv].end(); it++) {
      link[*it]--;
    }
  }

  return 0;
}

Measured memory_bytes: 3848
n, k = map(int, input().split())
snak = [False] * n
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        snak[a[j] - 1] = True
fcnt = 0
for i in range(n):
    if not snak[i]:
        fcnt += 1
print(fcnt)

Measured memory_bytes: 9184
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)


Measured memory_bytes: 66044
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
vector< ll > divisor(ll n) {  //約数の列挙
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main(){
    ll n;
    std::cin >> n;
    std::vector<ll> d=divisor(n);
    ll ans=INF64;
    rep(i,d.size()){
        ans=min(ans,d[i]+n/d[i]-2);
    }
    std::cout << ans << std::endl;
}

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

using namespace std;

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

    for (int i = 0; i < k; i++) {
        if (a >= b) {
            b *= 2;
        } else {
            c *= 2;
        }
    }

    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int h;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    cin >> h;
    if (h >= K) { ans++; }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct en{
	pair<double, double> pos;
	double r;
};
int main() {
	int n;
	cin >> n;
	while (n--){
		en e1,e2;
		cin >> e1.pos.first >> e1.pos.second >> e1.r >> e2.pos.first >> e2.pos.second >> e2.r;
		double dis = hypot(e1.pos.first - e2.pos.first, e1.pos.second - e2.pos.second);
		if (e1.r>e2.r&&dis + e2.r<e1.r)cout << 2 << endl;
		else if (e1.r<e2.r&&dis+e1.r<e2.r)cout << -2 << endl;
		else if (e1.r + e2.r>=dis)cout << 1 << endl;
		else cout << 0 << endl;
	}
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	int result = n;
	int m; cin >> m;
	for (int i = 1; i < n; ++i) {
		int p; cin >> p;
		if (p > m) result--;
		m = min(m, p);
	}
	cout << result;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


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

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

    vector<ll> d(n);
    rep(i, n) d[i] = abs(X[i] - x);
    ll ans = d[0];
    rep(i, n -1) ans= gcd(ans, d[i+1]);
    put(ans)

    return 0;
}

Measured memory_bytes: 4792
import java.util.*;

/**
 * SortingThreeNumbers
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];

        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);

        System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}


Measured memory_bytes: 26244