akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vi vector<long long>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
ll mod=1000000007;
ll large=1e18;
ll neg=-1e18;
ll N=500000;
ll mod1=998244353;
struct pii
{
   ll x;
   ll y;
};
struct edge
{
   ll from;
   ll to;
   ll w;
   ll id;
};
ll find(ll a,ll p[])
{
   //cout<<"find "<<a<<endl;
   if(a==p[a])
   return a;
   else return p[a]=find(p[a],p);

}
void join(ll a,ll b,ll p[],ll sz[])
{
   a=find(a,p);
   b=find(b,p);
   if(a!=b)
   {
      if(sz[a]<sz[b])
      swap(a,b);
      sz[a]+=sz[b];
      p[b]=a;
   }
}
ll power(ll a,ll b,ll mod)
{
   ll res=1;
   while(b>0)
   {
      if(b&1)
      res=(res*a)%mod;
      b=b/2;
      a=(a*a)%mod;
   }
   return res;
}
ll inverse(ll x, ll p)
{
   return power(x,p-2,p);
}
ll hash1(ll x,ll y)
{
   return x+y+x*y;
}
/*ll f[200000]={0};

void ini()
{
   f[0]=1;
   for(ll i=1;i<=200000;i++)
   f[i]=(i*f[i-1])%mod;
}*/
void build(ll tree[],ll v,ll l,ll r,ll dp[])
{
   if(l==r)
      tree[v]=dp[l];
   else
   {
      ll m=(l+r)/2;
      build(tree,2*v,l,m,dp);
      build(tree,2*v+1,m+1,r,dp);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}
ll query(ll tree[],ll v,ll l,ll r,ll tl,ll tr)
{
   if(l==tl && tr==r)
   {
    //  cout<<"max of "<<tl<<" "<<tr<<" "<<tree[v]<<endl;
      return tree[v];
   }
   else
   {
      ll m=(l+r)/2;
      if(tr<=m)
      {
         ll z1= query(tree,2*v,l,m,tl,tr);
     //    cout<<"max of "<<tl<<" "<<tr<<" "<<z1<<endl;
         return z1;
      }
      else if(tl>m)
      {
         ll z2= query(tree,2*v+1,m+1,r,tl,tr);
      //   cout<<"max of "<<tl<<" "<<tr<<" "<<z2<<endl;
         return z2;
      }
      else 
      {
         ll z=query(tree,2*v,l,m,tl,m);
         ll z1=query(tree,2*v+1,m+1,r,m+1,tr);
       //  cout<<"max of "<<tl<<" "<<tr<<" "<<max(z1,z)<<endl;
         return max(z1,z);
      }
      
      
   }
}
void update(ll tree[],ll v,ll l,ll r,ll pos,ll element)
{
   if(l==r && l==pos)
   tree[v]=element;
   else
   {
      ll m=(l+r)/2;
      if(pos<=m)
      update(tree,2*v,l,m,pos,element);
      else
      update(tree,2*v+1,m+1,r,pos,element);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}

/*ll ncr(ll n,ll r)
{
   ll res=1;
   ll k=f[n];
   ll v=inverse(f[n-r],mod);
   ll u=inverse(f[r],mod);
   ll x=(u*v)%mod;
   k=(k*x)%mod;
   return k;
}*/
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll x[5];
   for(ll i=0;i<5;i++)
   cin>>x[i];
   for(ll i=0;i<5;i++)
   {
      if(x[i]==0)
      {
         cout<<i+1<<endl;
         break;
      }
   }
   return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 100005, MAX_M = 200010;
// code

int a[MAXN], n;
vector<int> g[MAXN];

int dfs(int v, int p){
    int val = 0;
    int mx = 0;
    for (auto u:g[v]){
        if (u == p)
            continue;
        int t = dfs(u, v);
        val += t;
        mx = max(mx, t);
    }
  	int x = g[v].size() == 1 ? 1 : 2;
  	//cout << v << ' ' << x*a[v] - val << endl;
  	if (mx > a[v]){
  	    cout << "NO\n";
      	exit(0);
  	}
  	if (x*a[v] - val < 0 || x*a[v] - val > a[v]){
    	cout << "NO\n";
      	exit(0);
    }
    return x*a[v] - val;
}

void Solve() {
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = 1, a, b; i < n; i++){
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    cout << (dfs(1, 1) == 0 ? "YES\n":"NO\n");
}

signed main(){
    FAST_IO;
    int TC = 1; 
	//cin >> TC;
    while(TC--) Solve();
    return 0;
}


Measured memory_bytes: 16124
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <memory>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using llint =  int;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

// for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend) for(int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable, numberOFbegin, numberOFend) for(int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable, numberOFend) for(int LoopVariable = 0; (LoopVariable) < (numberOFend); LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max() - 5;
constexpr int inf = numeric_limits<int>::max() - 5;
constexpr long long int mod = 1000000007;

int main() {

    string s;
    cin >> s;
    string t = "C";
    t += s;
    t += "C";

    llint n = s.size();
    vector<vector<llint>> dp(n + 2, vector<llint>(19));
    REP(i, n + 2) {
        dp[i][0] = i;
        dp[i][1] = i + (t[i] == 'R' ? 1 : t[i] == 'L' ? -1 : 0);
    }
    FOR(i, 2, 19) {
        REP(j, n + 2) {
            dp[j][i] = dp[dp[j][i-1]][i-1];
        }
    }
    vector<llint> result(n+2, 0);
    FOR(i, 1, n + 1) {
        if(0 <= dp[i][18]-1  && dp[i][18]-1  < n ) {
            result[dp[i][18] - 1]++;
        }
    }
    REP(i, n - 1) {
        cout << result[i] << " ";
    }
    cout << result[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 12800
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
  int n;
  cin>>n;
  vector<double>s(n+1);
  rep(i,n+1){
    int m;
    cin>>m>>m;
    double sum=0;
    while(m--){
      double a,b;
      cin>>a>>b;
      sum+=b;
      s[i]+=a*b;
    }
    s[i]/=sum;
  }
  bool h=false;
  rep(i,n)if(s[i]>s[n]+1e-10)h=true;
  if(h)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 1232
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		try {
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
			String line;
			while ((line = stdReader.readLine()) != null){
				int x = Integer.parseInt(line);
				System.out.println(x*x*x);
			}
		} catch (Exception e) {
			e.getStackTrace();
			System.exit(0);
		}
	}
}

Measured memory_bytes: 24140
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    P p[100005];
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        p[i] = P(r, l);
    }
    sort(p, p + n);
    int u = 0;
    for(int i = 0; i < n; i++) u = max(u, p[i].second);
    int d = max(0, p[0].first - u + 1);
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, p[i].first - p[i].second + 1 + d);
    }
    int l1[100005];
    l1[0] = 0;
    for(int i = 1; i <= n; i++) l1[i] = max(l1[i - 1], p[i - 1].second);
    int l2[100005];
    l2[n] = 0;
    for(int i = n - 1; i >= 0; i--) l2[i] = max(l2[i + 1], p[i].second);
    for(int i = 1; i < n; i++){
        ans = max(ans, max(0, p[0].first - l1[i] + 1) + max(0, p[i].first - l2[i] + 1));
    }
    cout << ans << endl;
}


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = [ i-1 for i in a]

ans = 0
pre = -2
for x in a:
    ans += b[x]

    if x == (pre + 1):
       ans += c[pre]

    pre = x

print(ans)

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


int sumDigit(string n)
{
	int s = 0;
	for (int i = 0; i < n.size(); i++)
		s += n[i] - 48;
	return s;
}

int main()
{
	string x;	
	while (cin >> x && x != "0")
		cout << sumDigit(x) << endl;
}



Measured memory_bytes: 3164
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

class Point{
public:
    double x, y;
    int original_index;

    Point(double x = 0, double y = 0): x(x), y(y){}

    bool operator < (const Point &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }
    Point operator - (Point p) {
        return Point(x - p.x, y - p.y);
    }

    double cross(Point p){
        return x*p.y - y*p.x;
    }
    bool ccw(Point p){
        if(this->cross(p) <= 0){
            return true;
        }else{
            return false;
        }
    }
    double dot(Point p){
        return x*p.x + y*p.y;
    }
    double norm(){
        return sqrt(x*x + y*y);
    }
    double angle(Point p){
        return acos(this->dot(p) / (this -> norm() * p.norm()));
    }

};

typedef Point Vector;

Point p[100];
int N;
vector<Point> u, l;
vector<Point> convex;
double ans[100];


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        double x, y;
        cin >> x >> y;
        p[i].x = x;
        p[i].y = y;
        p[i].original_index = i;
    }

    if(N == 2){
        cout << 0.5 << endl << 0.5 << endl;
        return 0;
    }

    sort(p, p+N);

    u.push_back(p[0]);
    u.push_back(p[1]);
    l.push_back(p[N-1]);
    l.push_back(p[N-2]);

    for(int i = 2; i < N; i++){
        for(int n = u.size(); n >= 2 && !(u[n-1] - u[n-2]).ccw(p[i] - u[n-2]); n--){
            u.pop_back();
        }
        u.push_back(p[i]);
    }
    for(int i = N - 3; i >= 0; i--){
        for(int n = l.size(); n >= 2 && !(l[n-1] - l[n-2]).ccw(p[i] - l[n-2]); n--){
            l.pop_back();
        }
        l.push_back(p[i]);
    }

    
    for(int i = 0; i < u.size(); i++){
        convex.push_back(u[i]);
    }
    
    for(int i = 1; i < l.size()-1; i++){
        convex.push_back(l[i]);
    }

    for(int i = 0; i < convex.size(); i++){
        Point now = convex[i];
        Point before = convex[(i-1+convex.size()) % convex.size()];
        Point after = convex[(i+1) % convex.size()];
        Vector bn = now - before;
        Vector orth1 = Vector(bn.y, -bn.x);
        Vector na = after - now;
        Vector orth2 = Vector(na.y, -na.x);
        ans[now.original_index] = orth1.angle(orth2) / (2*M_PI);
    }
    for(int i = 0; i < N; i++){
        printf("%.9lf\n", ans[i]);
    }
        
    
}

Measured memory_bytes: 640
function main(){
	var n = scan();
	var m = scan();
	var a = Array(m);
	rep(m, function(i){
		a[i] = scan();
	});
	var b = Array(m);
	rep(m, function(i){
		b[i] = Array(n);
		rep(n, function(j){
			b[i][j] = scan();
		});
	});
	var x = Array(n);
	rep(n, function(i){
		x[i] = 0;
	});
	rep(m, function(i){
		rep(n, function(j){
			if(b[i][j] == a[i]){
				++x[j];
			}
			else{
				++x[a[i] - 1];
			}
		});
	});
	rep(n, function(i){
		print(x[i]);
	});
}

function rep(n, func){
	for(var i = 0; i < n; ++i){
		func(i);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';
var input_index = 0;

function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}

function print(val){
	console.log(val);
}

process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.split(/\s+/);
	main();
});

Measured memory_bytes: 18604
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;
int euclid(int a,int b){
    int temp;
    if(a<b){temp=a; a=b; b=temp;}
    if(b<1)return -1;
    if(a%b==0)return b;
    return euclid(b,a%b);
}
int main(void){
   int N;
   cin>>N;
   long A[N];
   for(int i=0;i<N;i++){
       cin>>A[i];
   }
   long ans=euclid(A[0],A[1]);
   for(int i=2;i<N;i++){
       ans=euclid(ans,A[i]);
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[100005],b[100005],s[100005],bit[200005];

ll k;

void Upd(int v){
    while(v<=2*n+1){
        bit[v]++;
        v+=v&-v;
    }
}

int Qry(int v){
    int ans=0;
    while(v){
        ans+=bit[v];
        v-=v&-v;
    }
    return ans;
}

ll f(int v){
    ll ans=0;
    for(int i=1;i<=2*n+1;i++){
        bit[i]=0;
    }
    Upd(n+1);
    for(int i=1;i<=n;i++){
        if(a[i]<=v) s[i]=1;
        else s[i]=-1;
        s[i]+=s[i-1];
        ans+=Qry(s[i]+n);
        Upd(s[i]+n+1);
    }
    return ans;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i]; b[i]=a[i];
    }
    k=(ll)n*(n+1)/2ll;
    sort(b+1,b+n+1);
    int l=1,r=n;
    while(l!=r){
        int mid=(l+r)/2;
        ll cnt=f(b[mid]);
        if(cnt<k/2+1) l=mid+1;
        else r=mid;
    }
    cout << b[l];
}


Measured memory_bytes: 2176
a = input()

if a == 'A' or a == 'B' or a == 'C' or a == 'D' or a == 'E' or a == 'F' or a == 'G' or a == 'H' or a == 'I' or a == 'J' or a == 'K' or a == 'L' or a == 'M' or a == 'N' or a == 'O' or a == 'P' or a == 'Q' or a == 'R' or a == 'S' or a == 'T' or a == 'U' or a == 'V' or a == 'W' or a == 'X' or a == 'Y' or a == 'Z':
  print('A')
else:
  print('a')

Measured memory_bytes: 9064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    ArrayList<Integer> X = new ArrayList<>();
    for (int i = 0; i < M; i++) {
      X.add(scn.nextInt());
    }

    if (N >= M) {
      System.out.println(0);
    } else {

      Collections.sort(X);
      PriorityQueue<Integer> diffX = new PriorityQueue<>(new Comparator<Integer>() {
        public int compare(Integer n1, Integer n2) {
          return (n1 - n2 > 0) ? -1 : 1;
        }
      });

      for (int i = 0; i < M - 1; i++) {
        diffX.add(X.get(i + 1) - X.get(i));
      }
      int ans = X.get(X.size() - 1) - X.get(0);
      for (int i = 0; i < N - 1; i++) {
        ans -= diffX.poll();
      }

      System.out.println(ans);

    }
  }

}


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

const int MN = 1e6 + 12;

int k;
bitset<MN> bs;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cin >> k;
  int cur = 0;
  bs.reset();
  int res = 0;
  while (true) {
    res++;
    cur = (cur * 10 + 7) % k;
    if (cur == 0) {
      cout << res << '\n';
      return 0;
    } else if (bs[cur]) {
      cout << -1 << '\n';
      return 0;
    } else {
      bs[cur] = true;
    }
  }
  return 0;
}



Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
void good(){
  cout << "YES" << endl;
  exit(0);
}
int main(){
  string s;
  cin >> s;
  string m = "keyence";
  if(s == m) good();
  for(int i = 0; i < s.size(); i++){
    for(int j = i; j < s.size(); j++){
      string nv;
      for(int k = 0; k < i; k++) nv.push_back(s[k]);
      for(int k = j + 1; k < s.size(); k++) nv.push_back(s[k]);
      if(nv == m) good();
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long answer = b/n-a/n;
        if(a%n == 0){
            answer++;
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;

constexpr ll X = -1e13;

int main() {
    int n;
    while(cin >> n, n) {
        vector<ll> v(n);
        ll lower = -1e10, upper=1e10;
        for(int i=0; i<n; ++i) {
            string str;
            cin >> str;
            if(str == "x") {
                v[i] = X;
            } else {
                v[i] = stoi(str);
            }
        }

        bool none = false;
        for(int i=0; i<v.size()-1; ++i) {
            if(i % 2 == 0) { // odd small
                if(v[i] == X) {
                    if(v[i+1] == X) {
                        none = true;
                        break;
                    }
                    upper = min(upper, v[i+1] - 1);
                } else {
                    if(v[i+1] == X) {
                        lower = max(lower, v[i]+1);
                    } else if(v[i] >= v[i+1]) {
                        none = true;
                        break;
                    }
                }
            } else {
                if(v[i] == X) {
                    if(v[i+1] == X) {
                        none = true;
                        break;
                    }
                    lower = max(lower, v[i+1] + 1);
                } else {
                    if(v[i+1] == X) {
                        upper = min(upper, v[i]-1);
                    } else if(v[i] <= v[i+1]) {
                        none = true;
                        break;
                    }
                }
            }
        }
        
        if(none || lower > upper) {
            cout << "none" << endl;
        } else if(lower == upper) {
            cout << lower << endl;
        } else {
            cout << "ambiguous" << endl;
        }
    }
}


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

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for (int i=1; i<=n; i++)
	   cin>>a[i];
	for (int i=1; i<=n-k; i++)
	{
		if (a[i]<a[i+k])
		  cout<<"Yes"<<endl;
		else
		  cout<<"No"<<endl;
	 }
	return 0;
 }

Measured memory_bytes: 4400
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e18;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

//ベルマンフォード法
int V,E; //Vは頂点数、Eは辺数
struct edge {int from, to, cost;};
edge es[2010]; //辺
int d[1010]; //最短距離

void shortest_path(int s){
    rep(i,V) d[i]=INF;
    d[s]=0;
    rep(j,V-1){
        bool update = false;
        rep(i,E){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    cin >> V >> E;
    rep(i,E) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        es[i]=(edge){a,b,-c};
    }
    shortest_path(0);
    bool negative[2010];
    rep(i,V){
        negative[i]=false;
    }
    rep(i,V) {
        rep(j,E) {
            if(d[es[j].from]==INF) continue;
            if(d[es[j].to]>d[es[j].from]+es[j].cost) {
                d[es[j].to]=d[es[j].from]+es[j].cost;
                negative[es[j].to]=true;
            }
            if(negative[es[j].from]==true) {
                negative[es[j].to] = true;
            }
        }
    }
    if(negative[V-1]) cout << "inf" << endl;
    else {
        cout << -d[V-1] << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
int h[100000];
bool bo[100000];
signed main() {
	int a, b, ans = 0;
	cin >> a >> b;
	f(i, a)cin >> h[i];
	f(i, b) {
		int c, d;
		cin >> c >> d;
		c--, d--;
		if (h[c] <= h[d])bo[c] = true;
		if (h[d] <= h[c])bo[d] = true;
	}
	f(i, a) {
		if (!bo[i])ans++;
	}
	cout << ans << endl;
}


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

int main()
{
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	ll a = 0,b = 0,c = 0;
	string ch = "a";
	while(1)
	{
		if(ch == "a")
		{
			if(s1.size()>a)
			{
				ch = s1[a];
				a++;
			}
			else
			{
				cout<<"A"<<endl;
				return 0;
			}
		}
				if(ch == "b")
		{
			if(s2.size()>b)
			{
				ch = s2[b];
				b++;
			}
			else
			{
				cout<<"B"<<endl;
				return 0;
			}
		}
				if(ch == "c")
		{
			if(s3.size()>c)
			{
				ch = s3[c];
				c++;
			}
			else
			{
				cout<<"C"<<endl;
				return 0;
			}
		}
	}
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<char, int> P;
typedef set<ll> st;
typedef vector<st> sv;
typedef vector<char> cv;

#define INF 1e16

string form;

bool is_op(char c){ return c=='+'||c=='-'||c=='*'||c=='/'; }

ll calc(ll a,ll b,char c){
  if(c=='+') return a+b;
  else if(c=='-') return a-b;
  else if(c=='*') return a*b;
  else if(c=='/'&&b!=0) return a/b;
  else return -INF;
}

st merge(sv ns,cv op){
  if(op.size()==0)return ns[0];
  st res;
  rep(i,op.size()){
    sv tmp=ns;
    cv nop=op;
    st add;
    each(o1,tmp[i])each(o2,tmp[i+1]){
      ll cal=calc(o1,o2,nop[i]);
      if(cal==-INF)continue;
      add.insert(cal);
    }
    tmp[i]=add;
    tmp.erase(tmp.begin()+i+1);
    nop.erase(nop.begin()+i);
    st e=merge(tmp,nop);
    each(o,e){
      res.insert(o);
    }
  }
  return res;
}

st num(int l,int r){
  st res;
  res.insert(stoll(form.substr(l,r-l)));
  return res;
}

st expr(int l,int r){
  int level=0,nl=l;
  sv tmp;
  cv op;
  repl(i,l,r){
    if(form[i]=='(')level++;
    else if(form[i]==')')level--;
    else if(level==0&&(is_op(form[i]))){
      tmp.pb(expr(nl,i));
      op.pb(form[i]);
      nl=i+1;
    }
  }
  if(op.size()==0&&form[l]=='(')return expr(l+1,r-1);
  else if(op.size()==0)return num(l,r);
  else{
    tmp.pb(expr(nl,r));
    st res=merge(tmp,op);
    return res;
  }
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>form;
    if(form=="#")break;
    int n=form.length();
    st res=expr(0,n);
    cout<<res.size()<<endl;
  }
	return 0;
}

Measured memory_bytes: 3284
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    if ans % T[i] != 0:
        ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
    #print(ans)
print(int(ans))

Measured memory_bytes: 5076
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int main(int argc, char* argv[]){
  long int a,b,c;
  scanf("%ld %ld %ld",&a,&b,&c);
  if (a>c) {
    printf("NO" );
    return 0;
  }
  if (a+b>=c) {
    printf("YES");
  }else{
    printf("NO" );
  }
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;
ll h, w;
ll solve(ll cm, int i, map<ll, vector<ll> >& abm, vector<bool>& ckd, vector<ll>& clst){
    if(ckd[i]) return 0;
    clst[i] = cm;
    ckd[i] = true;
    for(auto it = abm[i].begin(); it != abm[i].end(); ++it){
        solve(cm, *it, abm, ckd, clst);
    }
    return 0;
}

int main(){
    cin >> n >> m;
    map<ll, vector<ll> > abm;
    for (int i=0; i<m; ++i){
        ll a, b;
        cin >> a >> b;
        abm[a-1].push_back(b-1);
        abm[b-1].push_back(a-1);
    }
    vector<bool> ckd(n,false);
    vector<ll> clst(n);
    for(int i=0; i<n; ++i)clst[i] = i;
    for(int i=0; i<n; ++i){
        solve(i,i, abm, ckd, clst);
    }
    map<ll, ll> resm;
    for(auto c : clst){
        resm[c] += 1;
    }
    auto res = max_element(resm.begin(), resm.end(), [](auto a, auto b){return a.second < b.second;});
    cout << res->second << endl;
    return 0;
}

Measured memory_bytes: 45016
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 1000000000 + 7;
                int arr[MAX];
            //Global Variables


                int manhattanDis(int  x , int y , int x1 , int y1)
                {
                    return abs(x - x1) + abs(y - y1);
                }
                int main()
                {
                    string a , b;
                    cin>>a>>b;

                    int lena = a.length();
                    int lenb = b.length();
                    if(lena > lenb)printf("GREATER\n");
                    else if(lenb > lena)printf("LESS\n");
                    else
                    {
                        for(int i = 0 ; i < lena ; i++)
                        {
                            if(a[i] > b[i])
                            {
                                printf("GREATER\n");
                                return 0;
                            }
                            else if(b[i] > a[i])
                            {
                                printf("LESS\n");
                                return 0;
                            }
                        }
                        printf("EQUAL\n");
                    }
                }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int line[6];
    for(int i=0;i<6;++i){
        cin>>line[i];
    }
    sort(line,line+4);
    sort(line+4,line+6);
    cout<<line[1]+line[2]+line[3]+line[5]<<endl;
    return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll n, m;
  cin >> n >> m;
  map<ll, ll> s;
  rep(i, m){
    ll a, b;
    cin >> a >> b;
    a--;b--;
    s[a]++;
    s[b]++;
  }
  rep(i, n){
    cout << s[i] << endl;
  }
  
  return 0;
}


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

int main(){
  int N,i,cnt=0;
  cin >> N;
  vector<int> v(N);
  vector<int> p(N);

  for(i=0;i<N;i++){
    cin >>v.at(i);
    p.at(i) = v.at(i);
  }
  sort(p.begin(),p.end());
  for(i=0;i<N;i++){
    if(!(v.at(i)==p.at(i)))
    cnt++;
  }
  if(cnt<=2)
  cout << "YES" << endl;
  else
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n;cin>>n;
    long long ans=1e18;
    for(long long i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        long long j=n/i;
        ans=min(ans,i+j-2);
    }
    cout<<ans<<endl;
}

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

dp = [0]

for i in range(1, n+1):
    dp.append(100000)
    power = 1
    while (i - power >= 0):
        dp[i] = min(dp[i], 1 + dp[i - power])
        power *= 6

    power = 9
    while (i - power >= 0):
        dp[i] = min(dp[i], 1 + dp[i - power])
        power *= 9

print(dp[n])
    


Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main() {FIN
    
    int n, m, i, j, s, e;
    cin >> n >> m;
    vi cs(m);
    for (i = 0; i < n; i++) {
        s = 0;
        for (j = 0; j < m; j++) {
            cin >> e;
            s += e;
            cs[j] += e;
            cout << e << " ";
        }
        cout << s << "\n";
    }
    s = 0;
    for (i = 0; i < m; i++) {
        cout << cs[i] << " ";
        s += cs[i];
    }
    cout << s <<  "\n";
    return 0;
}


Measured memory_bytes: 3204
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  int a, b, c; cin >> a >> b >> c;
  if (a > c && c > b) print("Yes");
  else if (a < c && c < b) print("Yes");
  else print("No");


  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int a, b, c, d;
int main(void){
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int INF = 1e18;

#define L first
#define R second

signed main(){
	vector<int> hoge, con;
	vector<pair<int,int>> in;
	
	
	int N, M, maximum = 0;
	
	cin>>N>>M;
	
	in.assign(N, {});
	
	hoge.push_back(0);
	hoge.push_back(INF);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].L>>in[i].R;
		hoge.push_back(in[i].L);
		hoge.push_back(in[i].R);
	}
	
	
	sort(hoge.begin(), hoge.end());
	
	hoge.erase(unique(hoge.begin(), hoge.end()), hoge.end());
	
	con.assign(hoge.size(),0);
	
	for(int i = 0; i < N; i++){
		int l = lower_bound(hoge.begin(), hoge.end(), in[i].L) - hoge.begin();
		int r = lower_bound(hoge.begin(), hoge.end(), in[i].R) - hoge.begin();
		
		con[l]++;
		con[r+1]--;
	}
	
	for(int i = 1; i < con.size(); i++){
		con[i] += con[i-1];
		maximum = max(maximum, con[i-1]);
	}
	
	if(maximum%2){
		int minimum = 0;
		for(int i = 0; i < N; i++){
			int r = lower_bound(hoge.begin(), hoge.end(), in[i].R) - hoge.begin();
			if(con[r] == maximum){
				minimum = max(minimum, hoge[r]);
			}
		}
		
		cout<<(maximum-1)*M + minimum<<endl;
	} else {
		int maxi = INF;
		for(int i = 0; i < N; i++){
			int l = lower_bound(hoge.begin(), hoge.end(), in[i].L) - hoge.begin();
			if(con[l] == maximum){
				maxi = min(maxi, hoge[l]);
			}
		}
		
		cout<<(maximum-1)*M + M - maxi<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 12256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>


int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld %ld", &n, &k);

    long exist_zero = 0;
    std::vector<long> a;
    std::vector<long> b;
    long i, j;
    for(i=0; i<n; i++) {
        long tmp;
        scanf("%ld", &tmp);
        if(tmp<0) {
            a.push_back(tmp);
        }
        if(tmp>0) {
            b.push_back(tmp);
        }
        if(tmp==0) {
            exist_zero =1;
        }
    }
    if(exist_zero) {
        k--;
    }
    if(k==0) {
        printf("0\n");
        return 0;
    }

    long ans = 1e+9;
    for(i=0; i<b.size(); i++) {
        long val = b[i];
        long tmp = k-1-i;
        if(tmp>0) {
            if((long)a.size()<tmp) {
                continue;
            }
            val = val * 2 - a[(long)a.size()-tmp];
        }
        if(ans>val) {
            ans = val;
        }
    }

    for(i=0; i<a.size(); i++) {
        long val = -a[(long)a.size()-i-1];
        long tmp = k-1-i;
        if(tmp>0) {
            if((long)b.size() < tmp) {
                continue;
            }
            val = val * 2 + b[tmp-1];
        }
        if(ans>val) {
            ans = val;
        }
    }

    printf("%d\n", ans);

    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n, a, b;
	cin >> n >> a >> b;
	int ans = min(n * a, b);
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

typedef struct{
    
    long int a;
    long int b;
    
}DRINK;

int compare(const void *a, const void *b)
{
   DRINK aNum = *(DRINK*)a;
   DRINK bNum = *(DRINK*)b;

    int tmp1=aNum.a;
    int tmp2=bNum.a;

    return tmp1-tmp2;
}

int main(void)
{
    long int n, m, i;
    scanf("%ld%ld", &n, &m);
    DRINK shop[10*10*10*10*10];
    long int ans=0, cnt=0;
    
    for(i=0;i<n;i++){
        scanf("%ld%ld", &shop[i].a, &shop[i].b);
      }
   qsort(shop, n, sizeof(DRINK), compare);
   i=0;
   while(1){
       ans=ans+shop[i].a*shop[i].b;
       cnt=cnt+shop[i].b;
       if(cnt==m) break;
       else if(cnt>m){
           ans=ans-(cnt-m)*shop[i].a;
           break;
       }
       else i++;
   }

   printf("%ld\n", ans);

   return 0;
}


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

const int maxn = int(1e5)+5;

int freq[maxn], freq1[maxn];

int main(void)
{
	string S, T;
	cin >> S >> T;
	for(int i = 1;i <= int(S.size());i++) freq[i] = freq[i-1]+int(S[i-1] == 'A')+1;
	for(int i = 1;i <= int(T.size());i++) freq1[i] = freq1[i-1]+int(T[i-1] == 'A')+1;
	int q, a, b, c, d;
	scanf("%d", &q);
	while(q--)
	{
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--, c--;
		if((freq[b]-freq[a])%3 == (freq1[d]-freq1[c])%3) printf("YES\n");
		else printf("NO\n");
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> b[i];
  int ans = b[0] + b[n - 2];
  for (int i = 1; i < n - 1; ++i) ans += min(b[i - 1], b[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
d,n=map(int,input().split())

if d==0 and n!=100:
  print(int(n))
elif d==0 and n==100:
  print(int(101))
  
elif d!=0 and n!=100:
  k=100**d
  print(int(k*n))
else:
  k=100**d
  print(int(k*101))

Measured memory_bytes: 3060
s = list(str(input()))
s = list(map(int, s))

c0 = 0
c1 = 0
for i in range(len(s)):
    if s[i] == 0:
        c0 += 1
    if s[i] == 1:
        c1 += 1

print(2 * min(c0, c1))


Measured memory_bytes: 4776
def edu_dp_a_frog1():
    n = int(input())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp [1] = abs(h[1]-h[0])
    for i in range(2, n):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    print(dp[n-1])
edu_dp_a_frog1()

Measured memory_bytes: 20576
#!/usr/bin/ruby

n, an = STDIN.readlines.map{|m| m.chomp}
a = an.split(/\s+/).map{|m| m.to_i}
num_odd = a.inject(1){|sum, i| sum *= (i % 2 == 0 ? 2 : 1)}
puts 3 ** n.to_i - num_odd


Measured memory_bytes: 1916
#include<iostream>
#include<cmath>
#include<iomanip>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
   int n,sum=0;
   cin >> n;
   int mx = -1;
for(int i=0;i<n;i++){
   int temp;
cin >> temp;
sum += temp;
mx = max(temp,mx);
}
sum -= mx;
if(mx < sum)cout << "Yes" << endl;
else cout << "No" << endl; 
   return 0;
}


Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <algorithm>
# define mod 1000000007
using namespace std;

long long a[10010000];
long long h, n;

int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    h += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    h -= a[i];
    ans = (ans + ((h) % mod * a[i]) % mod) % mod;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 3296
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> count(n,0);
    vector<vector<ll>> edge(n);
    vector<ll> dp(n,0);
    queue<ll> Q;
    ll ans=0;
    while(m--){
        ll x,y;
        cin>>x>>y;
        x--; y--;
        count[y]++;
        edge[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        if(count[i]==0){Q.push(i);}
    }
    while(!Q.empty()){
        ll w=Q.front(); Q.pop();
        for(auto &i:edge[w]){
            dp[i]=max(dp[i],dp[w]+1);
            ans=max(ans,dp[i]);
            count[i]--;
            if(count[i]==0){Q.push(i);}
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


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



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

   while(true){
       c -= b;
       if(c <= 0){
           cout << "Yes" << endl;
           return 0;
       }
       a -= d;
       if(a <= 0){
           cout << "No" << endl;
           return 0;
       }
   }
   return 0;
}


Measured memory_bytes: 3624
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (mut x, y, z) = get!(i32, i32, i32);
    let mut c = 0;
    x -= z;
    loop {
        x -= y + z;
        if x < 0 { break; }
        c += 1;
    }
    println!("{}", c);
}

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

for i in range(2**3, 2**4):
    b = bin(i)
    cnt = N//10**3
    for j in range(3):
        if b[j+3] == "1":
            cnt += (N%10**(3-j))//10**(2-j)
        else:
            cnt -= (N%10**(3-j))//10**(2-j)
    if cnt == 7:
        B = b
        break
        
ans = ["0"]*9
ans[0] = str(N//10**3)
ans[2] = str((N%10**3)//10**2)
ans[4] = str((N%10**2)//10)
ans[6] = str(N%10)
for i in range(3):
    if B[i+3] == "1":
        ans[2*i+1] = "+"
    else:
        ans[2*i+1] = "-"
        
ans[7] = "="
ans[8] = "7"
print("".join(ans))

Measured memory_bytes: 38384